Skip to content

Commit 5485a8a

Browse files
authored
feat(examples): illustrate how to run a mocha test (#1216)
1 parent baa9aa8 commit 5485a8a

9 files changed

Lines changed: 296 additions & 513 deletions

File tree

examples/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ example_integration_test(
9797
example_integration_test(
9898
name = "examples_webapp",
9999
npm_packages = {
100-
"//packages/jasmine:npm_package": "@bazel/jasmine",
101100
"//packages/protractor:npm_package": "@bazel/protractor",
102101
"//packages/rollup:npm_package": "@bazel/rollup",
103102
"//packages/terser:npm_package": "@bazel/terser",

examples/webapp/BUILD.bazel

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@npm//http-server:index.bzl", "http_server")
2-
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
2+
load("@npm//mocha:index.bzl", "mocha_test")
33
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
44
load(":differential_loading.bzl", "differential_loading")
55

@@ -31,14 +31,27 @@ protractor_web_test_suite(
3131
],
3232
)
3333

34-
jasmine_node_test(
34+
mocha_test(
3535
name = "test_sourcemaps",
36-
srcs = ["sourcemaps.spec.js"],
37-
deps = [
36+
# if we were in a subdirectory we'd need
37+
# package_name() + "/*.spec.js"
38+
args = ["*.spec.js"],
39+
data = [
40+
"sourcemaps.spec.js",
3841
":app_chunks",
3942
":app_chunks.min",
4043
":app_chunks_es5",
4144
":app_chunks_es5.min",
4245
"@npm//source-map",
4346
],
47+
tags = [
48+
# Need to set the pwd to avoid mocha needing a runfiles helper
49+
"no-bazelci-windows",
50+
],
51+
)
52+
53+
# Just a dummy test so that we have a test target for //... on certain bazelci platforms with bazel_integration_test
54+
sh_test(
55+
name = "dummy_test",
56+
srcs = ["dummy_test.sh"],
4457
)

examples/webapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"@babel/cli": "^7.6.0",
55
"@babel/core": "^7.6.0",
66
"@babel/preset-env": "^7.6.0",
7-
"@bazel/jasmine": "^0.38.0",
87
"@bazel/protractor": "^0.38.0",
98
"@bazel/rollup": "^0.38.0",
109
"@bazel/terser": "^0.38.0",
1110
"@bazel/typescript": "^0.38.0",
1211
"http-server": "^0.11.1",
12+
"mocha": "^6.2.1",
1313
"rollup": "1.21.4",
1414
"source-map": "^0.7.3",
1515
"terser": "^4.3.1",

examples/webapp/sourcemaps.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Ensure we have working sourcemaps when the app runs in a browser
22

3+
const assert = require('assert');
34
const fs = require('fs');
45
const path = require('path');
56
const sm = require('source-map');
@@ -38,9 +39,9 @@ function asserts(pos) {
3839
// so it actually starts with a bunch of '/../..'
3940
// expect(pos.source).toBe('index.mjs');
4041

41-
expect(pos.source.endsWith('index.mjs')).toBeTruthy();
42-
expect(pos.line).toBe(7); // one-based
43-
expect(pos.column).toBe(20); // zero-based
42+
assert(pos.source.endsWith('index.mjs'));
43+
assert(pos.line == 7); // one-based
44+
assert(pos.column == 20); // zero-based
4445
}
4546

4647
describe('application sourcemaps in the browser', () => {

0 commit comments

Comments
 (0)