-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(examples): use pkg_npm to replace root workspace linking in …
…examples/angular_view_engine
- Loading branch information
1 parent
e12b3af
commit 080b460
Showing
15 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,9 @@ ng_module( | |
"@npm//rxjs", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "todos_esm", | ||
srcs = [":todos"], | ||
output_group = "es6_sources", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/typescript/test/ts_library_esm_with_jest/.babelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "current", | ||
}, | ||
}, | ||
], | ||
] | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/typescript/test/ts_library_esm_with_jest/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") | ||
load("//packages/typescript:index.bzl", "ts_library") | ||
load(":ts_jest_test.bzl", "ts_jest_test") | ||
|
||
ts_library( | ||
name = "lib", | ||
srcs = [ | ||
"lib.ts", | ||
], | ||
# NB: hacky hidden configuration setting so that es6_sources does not include tsickle | ||
# .externs.js outputs | ||
runtime = "nodejs", | ||
deps = [ | ||
"@npm//@types/node", | ||
], | ||
) | ||
|
||
# Shenanigans for Windows which doesn't have runfiles symlinks | ||
# We need the jest config to be in the output tree where the specs are | ||
copy_to_bin( | ||
name = "jest_config", | ||
srcs = [ | ||
"jest.config.js", | ||
], | ||
) | ||
|
||
# Same goes for babelrc. We can't add it to the jest_config copy_to_bin | ||
# since must be a file that is passed to jest in the --config arg. | ||
copy_to_bin( | ||
name = "babel_rc", | ||
srcs = [ | ||
".babelrc", | ||
], | ||
) | ||
|
||
ts_jest_test( | ||
name = "test", | ||
srcs = [ | ||
"lib.test.ts", | ||
], | ||
data = [ | ||
":babel_rc", | ||
], | ||
jest_config = ":jest_config", | ||
deps = [ | ||
":lib", | ||
"@npm//@babel/preset-env", | ||
"@npm//babel-jest", | ||
], | ||
) |
6 changes: 6 additions & 0 deletions
6
packages/typescript/test/ts_library_esm_with_jest/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
transform: {'^.+\\.mjs?$': ['babel-jest', {configFile: __dirname + '/.babelrc'}]}, | ||
testMatch: ['**/?(*.)(spec|test).?(m)js?(x)'], | ||
moduleFileExtensions: ['js', 'mjs'], | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/typescript/test/ts_library_esm_with_jest/lib.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {doStuff} from './lib'; | ||
|
||
describe('doStuff', () => { | ||
it('should do some stuff', () => { | ||
expect(doStuff('boom')).toContain('boom'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function doStuff(a: string): string { | ||
return a | ||
} |
41 changes: 41 additions & 0 deletions
41
packages/typescript/test/ts_library_esm_with_jest/ts_jest_test.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Simple macro around jest_test""" | ||
|
||
load("@npm//jest-cli:index.bzl", _jest_test = "jest_test") | ||
load("//packages/typescript:index.bzl", "ts_library") | ||
|
||
def ts_jest_test(name, srcs, jest_config, deps = [], data = [], **kwargs): | ||
"""A macro around the autogenerated jest_test rule that takes typescript sources | ||
Uses ts_library prodmode esm output""" | ||
|
||
ts_library( | ||
name = "%s_ts" % name, | ||
srcs = srcs, | ||
data = data, | ||
deps = deps + ["@npm//@types/jest"], | ||
# NB: hacky hidden configuration setting so that es6_sources does not include tsickle | ||
# .externs.js outputs | ||
runtime = "nodejs", | ||
# Prevent requesting the .d.ts output as that will also produce lib.test.js | ||
# Without sandbox (e.g. windows) that will be loaded instead of lib.test.mjs | ||
tags = ["manual"], | ||
) | ||
native.filegroup( | ||
name = "%s_esm" % name, | ||
srcs = [":%s_ts" % name], | ||
output_group = "es6_sources", | ||
) | ||
|
||
args = [ | ||
"--no-cache", | ||
"--no-watchman", | ||
"--ci", | ||
] | ||
args.extend(["--config", "$$(rlocation $(rootpath %s))" % jest_config]) | ||
|
||
_jest_test( | ||
name = name, | ||
data = [jest_config, ":%s_esm" % name] + deps + data, | ||
templated_args = args, | ||
**kwargs | ||
) |