Skip to content

Commit

Permalink
refactor: use Bazel expand_location function instead of our own
Browse files Browse the repository at this point in the history
This allows a mocha_test macro to be neatly written - otherwise it got inputs like wksp_name/./file.js
  • Loading branch information
alexeagle committed Oct 1, 2019
1 parent d572173 commit 1f0c7fe
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 123 deletions.
1 change: 0 additions & 1 deletion examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,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
9 changes: 6 additions & 3 deletions examples/webapp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@npm//http-server:index.bzl", "http_server")
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
load(":differential_loading.bzl", "differential_loading")
load(":mocha.bzl", "mocha_test")

differential_loading(
name = "app",
Expand Down Expand Up @@ -31,9 +31,12 @@ protractor_web_test_suite(
],
)

jasmine_node_test(
mocha_test(
name = "test_sourcemaps",
srcs = ["sourcemaps.spec.js"],
srcs = [
"sourcemaps.spec.js",
],
entry_point = "@npm//:node_modules/mocha/bin/mocha",
deps = [
":app_chunks",
":app_chunks.min",
Expand Down
15 changes: 15 additions & 0 deletions examples/webapp/mocha.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"Example mocha_test macro"

load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

def mocha_test(name, srcs = [], deps = [], **kwargs):
nodejs_test(
name = name,
entry_point = "@npm//:node_modules/mocha/bin/mocha",
data = srcs + deps + [
"@npm//mocha",
],
# We could mix the users args with $(locations) but what if user wants
# to give arg `*.spec.js` - better to stay out of the way.
templated_args = kwargs.pop("args", ["$(locations %s)" % s for s in srcs]),
)
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": "latest",
"@bazel/protractor": "latest",
"@bazel/rollup": "latest",
"@bazel/terser": "latest",
"@bazel/typescript": "latest",
"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 1f0c7fe

Please sign in to comment.