Skip to content

Commit

Permalink
fix(jasmine): allow cjs specs + add cjs/mjs tests (#3401)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstuder-gh authored Apr 8, 2022
1 parent 5240f37 commit dd7e778
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 26 deletions.
3 changes: 2 additions & 1 deletion packages/jasmine/jasmine_node_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ than launching a test in Karma, for example.
load("@rules_nodejs//nodejs:providers.bzl", "JSModuleInfo")
load("//packages/jasmine/private:index.bzl", "bazel_jasmine_runner_test")
load("@build_bazel_rules_nodejs//internal/node:node.bzl", nodejs_test = "nodejs_test_macro")
load("@build_bazel_rules_nodejs//internal/common:is_js_file.bzl", "is_javascript_file")

def _js_sources_impl(ctx):
depsets = []
Expand All @@ -36,7 +37,7 @@ def _js_sources_impl(ctx):
ctx.actions.write(ctx.outputs.manifest, "".join([
f.short_path + "\n"
for f in sources.to_list()
if f.path.endswith(".js") or f.path.endswith(".mjs")
if is_javascript_file(f)
]))

return [DefaultInfo(files = sources)]
Expand Down
71 changes: 46 additions & 25 deletions packages/jasmine/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,54 @@ load("//internal/common:copy_to_bin.bzl", "copy_to_bin")
load("//packages/jasmine:index.bzl", "jasmine_node_test")
load("//packages/typescript:index.bzl", "ts_project")

jasmine_node_test(
name = "underscore_spec_test",
srcs = ["foo_spec.js"],
)
_JS_EXTENSIONS = [
"js",
"cjs",
"mjs",
]

[
jasmine_node_test(
name = "underscore_spec_%s_test" % ext,
srcs = ["foo_spec.%s" % ext],
)
for ext in _JS_EXTENSIONS
]

# Verify that a bootstrap script does not break the test
jasmine_node_test(
name = "underscore_spec_bootstrap_test",
srcs = ["foo_spec.js"],
data = ["bootstrap.js"],
templated_args = ["--node_options=--require=$$(rlocation $(location :bootstrap.js))"],
)

jasmine_node_test(
name = "underscore_test_test",
srcs = ["foo_test.js"],
)

jasmine_node_test(
name = "dot_spec_test",
srcs = ["foo.spec.js"],
)

jasmine_node_test(
name = "dot_test_test",
srcs = ["foo.test.js"],
)
[
jasmine_node_test(
name = "underscore_spec_%s_bootstrap_test" % ext,
srcs = ["foo_spec.%s" % ext],
data = ["bootstrap.js"],
templated_args = ["--node_options=--require=$$(rlocation $(location :bootstrap.js))"],
)
for ext in _JS_EXTENSIONS
]

[
jasmine_node_test(
name = "underscore_test_%s_test" % ext,
srcs = ["foo_test.%s" % ext],
)
for ext in _JS_EXTENSIONS
]

[
jasmine_node_test(
name = "dot_spec_%s_test" % ext,
srcs = ["foo.spec.%s" % ext],
)
for ext in _JS_EXTENSIONS
]

[
jasmine_node_test(
name = "dot_test_%s_test" % ext,
srcs = ["foo.test.%s" % ext],
)
for ext in _JS_EXTENSIONS
]

jasmine_node_test(
name = "sharding_test",
Expand Down
5 changes: 5 additions & 0 deletions packages/jasmine/test/foo.spec.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('spec in file ending with .spec.cjs', () => {
it('should run', () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions packages/jasmine/test/foo.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('spec in file ending with .spec.mjs', () => {
it('should run', () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions packages/jasmine/test/foo.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('spec in file ending with .test.cjs', () => {
it('should run', () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions packages/jasmine/test/foo.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('spec in file ending with .test.mjs', () => {
it('should run', () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions packages/jasmine/test/foo_spec.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('spec in file ending with _spec.cjs', () => {
it('should run', () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions packages/jasmine/test/foo_spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('spec in file ending with _spec.mjs', () => {
it('should run', () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions packages/jasmine/test/foo_test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('spec in file ending with _test.cjs', () => {
it('should run', () => {
expect(true).toBe(true);
});
});
5 changes: 5 additions & 0 deletions packages/jasmine/test/foo_test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('spec in file ending with _test.mjs', () => {
it('should run', () => {
expect(true).toBe(true);
});
});

0 comments on commit dd7e778

Please sign in to comment.