Skip to content

Commit

Permalink
feat(examples): illustrate how to run a mocha test (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored Oct 9, 2019
1 parent baa9aa8 commit 5485a8a
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 513 deletions.
1 change: 0 additions & 1 deletion examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ example_integration_test(
example_integration_test(
name = "examples_webapp",
npm_packages = {
"//packages/jasmine:npm_package": "@bazel/jasmine",
"//packages/protractor:npm_package": "@bazel/protractor",
"//packages/rollup:npm_package": "@bazel/rollup",
"//packages/terser:npm_package": "@bazel/terser",
Expand Down
21 changes: 17 additions & 4 deletions examples/webapp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@npm//http-server:index.bzl", "http_server")
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
load("@npm//mocha:index.bzl", "mocha_test")
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
load(":differential_loading.bzl", "differential_loading")

Expand Down Expand Up @@ -31,14 +31,27 @@ protractor_web_test_suite(
],
)

jasmine_node_test(
mocha_test(
name = "test_sourcemaps",
srcs = ["sourcemaps.spec.js"],
deps = [
# if we were in a subdirectory we'd need
# package_name() + "/*.spec.js"
args = ["*.spec.js"],
data = [
"sourcemaps.spec.js",
":app_chunks",
":app_chunks.min",
":app_chunks_es5",
":app_chunks_es5.min",
"@npm//source-map",
],
tags = [
# Need to set the pwd to avoid mocha needing a runfiles helper
"no-bazelci-windows",
],
)

# Just a dummy test so that we have a test target for //... on certain bazelci platforms with bazel_integration_test
sh_test(
name = "dummy_test",
srcs = ["dummy_test.sh"],
)
2 changes: 1 addition & 1 deletion examples/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"@babel/cli": "^7.6.0",
"@babel/core": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@bazel/jasmine": "^0.38.0",
"@bazel/protractor": "^0.38.0",
"@bazel/rollup": "^0.38.0",
"@bazel/terser": "^0.38.0",
"@bazel/typescript": "^0.38.0",
"http-server": "^0.11.1",
"mocha": "^6.2.1",
"rollup": "1.21.4",
"source-map": "^0.7.3",
"terser": "^4.3.1",
Expand Down
7 changes: 4 additions & 3 deletions examples/webapp/sourcemaps.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Ensure we have working sourcemaps when the app runs in a browser

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const sm = require('source-map');
Expand Down Expand Up @@ -38,9 +39,9 @@ function asserts(pos) {
// so it actually starts with a bunch of '/../..'
// expect(pos.source).toBe('index.mjs');

expect(pos.source.endsWith('index.mjs')).toBeTruthy();
expect(pos.line).toBe(7); // one-based
expect(pos.column).toBe(20); // zero-based
assert(pos.source.endsWith('index.mjs'));
assert(pos.line == 7); // one-based
assert(pos.column == 20); // zero-based
}

describe('application sourcemaps in the browser', () => {
Expand Down
Loading

0 comments on commit 5485a8a

Please sign in to comment.