Skip to content

Commit dd7e778

Browse files
authored
fix(jasmine): allow cjs specs + add cjs/mjs tests (#3401)
1 parent 5240f37 commit dd7e778

10 files changed

Lines changed: 88 additions & 26 deletions

File tree

‎packages/jasmine/jasmine_node_test.bzl‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ than launching a test in Karma, for example.
2121
load("@rules_nodejs//nodejs:providers.bzl", "JSModuleInfo")
2222
load("//packages/jasmine/private:index.bzl", "bazel_jasmine_runner_test")
2323
load("@build_bazel_rules_nodejs//internal/node:node.bzl", nodejs_test="nodejs_test_macro")
24+
load("@build_bazel_rules_nodejs//internal/common:is_js_file.bzl", "is_javascript_file")
2425

2526
def_js_sources_impl(ctx):
2627
depsets= []
@@ -36,7 +37,7 @@ def _js_sources_impl(ctx):
3637
ctx.actions.write(ctx.outputs.manifest, "".join([
3738
f.short_path+"\n"
3839
forfinsources.to_list()
39-
iff.path.endswith(".js") orf.path.endswith(".mjs")
40+
ifis_javascript_file(f)
4041
]))
4142

4243
return [DefaultInfo(files=sources)]

‎packages/jasmine/test/BUILD.bazel‎

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,54 @@ load("//internal/common:copy_to_bin.bzl", "copy_to_bin")
33
load("//packages/jasmine:index.bzl", "jasmine_node_test")
44
load("//packages/typescript:index.bzl", "ts_project")
55

6-
jasmine_node_test(
7-
name="underscore_spec_test",
8-
srcs= ["foo_spec.js"],
9-
)
6+
_JS_EXTENSIONS= [
7+
"js",
8+
"cjs",
9+
"mjs",
10+
]
11+
12+
[
13+
jasmine_node_test(
14+
name="underscore_spec_%s_test"%ext,
15+
srcs= ["foo_spec.%s"%ext],
16+
)
17+
forextin_JS_EXTENSIONS
18+
]
1019

1120
# Verify that a bootstrap script does not break the test
12-
jasmine_node_test(
13-
name="underscore_spec_bootstrap_test",
14-
srcs= ["foo_spec.js"],
15-
data= ["bootstrap.js"],
16-
templated_args= ["--node_options=--require=$$(rlocation $(location :bootstrap.js))"],
17-
)
18-
19-
jasmine_node_test(
20-
name="underscore_test_test",
21-
srcs= ["foo_test.js"],
22-
)
23-
24-
jasmine_node_test(
25-
name="dot_spec_test",
26-
srcs= ["foo.spec.js"],
27-
)
28-
29-
jasmine_node_test(
30-
name="dot_test_test",
31-
srcs= ["foo.test.js"],
32-
)
21+
[
22+
jasmine_node_test(
23+
name="underscore_spec_%s_bootstrap_test"%ext,
24+
srcs= ["foo_spec.%s"%ext],
25+
data= ["bootstrap.js"],
26+
templated_args= ["--node_options=--require=$$(rlocation $(location :bootstrap.js))"],
27+
)
28+
forextin_JS_EXTENSIONS
29+
]
30+
31+
[
32+
jasmine_node_test(
33+
name="underscore_test_%s_test"%ext,
34+
srcs= ["foo_test.%s"%ext],
35+
)
36+
forextin_JS_EXTENSIONS
37+
]
38+
39+
[
40+
jasmine_node_test(
41+
name="dot_spec_%s_test"%ext,
42+
srcs= ["foo.spec.%s"%ext],
43+
)
44+
forextin_JS_EXTENSIONS
45+
]
46+
47+
[
48+
jasmine_node_test(
49+
name="dot_test_%s_test"%ext,
50+
srcs= ["foo.test.%s"%ext],
51+
)
52+
forextin_JS_EXTENSIONS
53+
]
3354

3455
jasmine_node_test(
3556
name="sharding_test",

‎packages/jasmine/test/foo.spec.cjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('spec in file ending with .spec.cjs',()=>{
2+
it('should run',()=>{
3+
expect(true).toBe(true);
4+
});
5+
});

‎packages/jasmine/test/foo.spec.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('spec in file ending with .spec.mjs',()=>{
2+
it('should run',()=>{
3+
expect(true).toBe(true);
4+
});
5+
});

‎packages/jasmine/test/foo.test.cjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('spec in file ending with .test.cjs',()=>{
2+
it('should run',()=>{
3+
expect(true).toBe(true);
4+
});
5+
});

‎packages/jasmine/test/foo.test.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('spec in file ending with .test.mjs',()=>{
2+
it('should run',()=>{
3+
expect(true).toBe(true);
4+
});
5+
});

‎packages/jasmine/test/foo_spec.cjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('spec in file ending with _spec.cjs',()=>{
2+
it('should run',()=>{
3+
expect(true).toBe(true);
4+
});
5+
});

‎packages/jasmine/test/foo_spec.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('spec in file ending with _spec.mjs',()=>{
2+
it('should run',()=>{
3+
expect(true).toBe(true);
4+
});
5+
});

‎packages/jasmine/test/foo_test.cjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('spec in file ending with _test.cjs',()=>{
2+
it('should run',()=>{
3+
expect(true).toBe(true);
4+
});
5+
});

‎packages/jasmine/test/foo_test.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('spec in file ending with _test.mjs',()=>{
2+
it('should run',()=>{
3+
expect(true).toBe(true);
4+
});
5+
});

0 commit comments

Comments
 (0)