Skip to content

Commit 318bbf3

Browse files
gregmagolanalexeagle
authored andcommitted
feat(karma): npm peer deps & remove @rules_webtesting//browsers/sauce:chrome-win10 support
Also cleanup us arguments and doc string for karma_web_test_suite. BREAKING CHANGES: npm karma deps for karma_web_test and karma_web_suite are now peer deps so that the versions used can be chosen by the user. This PR also removes the built-in `@io_bazel_rules_webtesting//browsers/sauce:chrome-win10` saucelabs support. It is not very useful as it only tests a single browser and it difficult to use. In the angular repo, saucelabs support was implemented with a custom karma config using karma_web_test. This is the recommended approach.
1 parent cc11b20 commit 318bbf3

16 files changed

Lines changed: 130 additions & 344 deletions

File tree

examples/angular/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
"core-js": "2.6.9",
4747
"firebase-tools": "7.1.0",
4848
"history-server": "^1.3.1",
49+
"karma": "~4.1.0",
50+
"karma-chrome-launcher": "2.2.0",
51+
"karma-firefox-launcher": "1.1.0",
52+
"karma-jasmine": "2.0.1",
53+
"karma-requirejs": "1.1.0",
54+
"karma-sourcemap-loader": "0.3.7",
55+
"requirejs": "2.3.6",
4956
"rollup": "^1.21.4",
5057
"rollup-plugin-commonjs": "^10.1.0",
5158
"rollup-plugin-node-resolve": "^5.2.0",

examples/angular_view_engine/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@
4646
"core-js": "2.6.9",
4747
"firebase-tools": "7.1.0",
4848
"history-server": "^1.3.1",
49+
"karma": "~4.1.0",
50+
"karma-chrome-launcher": "2.2.0",
51+
"karma-firefox-launcher": "1.1.0",
52+
"karma-jasmine": "2.0.1",
53+
"karma-requirejs": "1.1.0",
54+
"karma-sourcemap-loader": "0.3.7",
4955
"patch-package": "^6.2.0",
56+
"requirejs": "2.3.6",
5057
"rollup": "^1.21.4",
5158
"rollup-plugin-amd": "^4.0.0",
5259
"rollup-plugin-commonjs": "^10.1.0",

examples/protocol_buffers/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@
1111
"@types/long": "^4.0.0",
1212
"@types/node": "11.11.1",
1313
"http-server": "^0.11.1",
14+
"karma": "~4.1.0",
15+
"karma-chrome-launcher": "2.2.0",
16+
"karma-firefox-launcher": "1.1.0",
17+
"karma-jasmine": "2.0.1",
18+
"karma-requirejs": "1.1.0",
19+
"karma-sourcemap-loader": "0.3.7",
1420
"long": "4.0.0",
1521
"protobufjs": "5.0.3",
22+
"requirejs": "2.3.6",
1623
"rollup": "1.20.3",
1724
"terser": "4.3.1",
1825
"typescript": "^3.3.1"

examples/web_testing/BUILD.bazel

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,6 @@ karma_web_test_suite(
7373
],
7474
)
7575

76-
karma_web_test_suite(
77-
name = "sauce_test",
78-
browsers = [
79-
"@io_bazel_rules_webtesting//browsers/sauce:chrome-win10",
80-
],
81-
tags = [
82-
"exclusive",
83-
"native",
84-
"sauce",
85-
# TODO(alexeagle): enable on CI once we have set the SAUCE env variables
86-
"manual",
87-
],
88-
deps = [
89-
":tests",
90-
],
91-
)
92-
9376
# Just a dummy test so that we have a test target for //... on certain bazelci platforms with bazel_integration_test
9477
sh_test(
9578
name = "dummy_test",

examples/web_testing/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
"@bazel/typescript": "^0.40.0",
55
"@types/jasmine": "2.8.2",
66
"@types/node": "11.11.1",
7+
"karma": "~4.1.0",
8+
"karma-chrome-launcher": "2.2.0",
9+
"karma-firefox-launcher": "1.1.0",
10+
"karma-jasmine": "2.0.1",
711
"karma-json-result-reporter": "1.0.0",
12+
"karma-requirejs": "1.1.0",
13+
"karma-sourcemap-loader": "0.3.7",
14+
"requirejs": "2.3.6",
815
"typescript": "^3.3.1"
916
},
1017
"scripts": {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"karma-firefox-launcher": "1.1.0",
4242
"karma-jasmine": "2.0.1",
4343
"karma-requirejs": "1.1.0",
44-
"karma-sauce-launcher": "2.0.2",
4544
"karma-sourcemap-loader": "0.3.7",
4645
"minimist": "^1.2.0",
4746
"node_resolve_index": "file:./tools/npm_packages/node_resolve_index",

packages/karma/src/BUILD.bazel

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# The generated `@bazel/karma` npm package contains a trimmed BUILD file using INTERNAL fences.
1818
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
1919
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
20-
load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library")
2120
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")
2221

2322
package(default_visibility = ["//visibility:public"])
@@ -43,7 +42,6 @@ nodejs_binary(
4342
"@npm//karma-firefox-launcher",
4443
"@npm//karma-jasmine",
4544
"@npm//karma-requirejs",
46-
"@npm//karma-sauce-launcher",
4745
"@npm//karma-sourcemap-loader",
4846
"@npm//requirejs",
4947
"@npm//tmp",
@@ -71,23 +69,12 @@ filegroup(
7169
"browser_repositories.bzl",
7270
"index.bzl",
7371
"karma.conf.js",
74-
"karma.js",
7572
"karma_web_test.bzl",
7673
"package.bzl",
7774
"package.json",
78-
"plugins.js",
7975
],
8076
)
8177

82-
js_library(
83-
name = "karma_plugins",
84-
srcs = [
85-
"plugins.js",
86-
],
87-
module_name = "@bazel/karma/plugins",
88-
module_root = "plugins.js",
89-
)
90-
9178
# END-INTERNAL
9279
exports_files([
9380
"karma.conf.js",

packages/karma/src/index.from_src.bzl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@ load(
2121
_karma_web_test_suite = "karma_web_test_suite",
2222
)
2323

24-
INTERNAL_KARMA_BIN = "@npm_bazel_karma//:karma_bin"
24+
_KARMA_BIN = "@npm_bazel_karma//:karma_bin"
25+
_KARMA_PEER_DEPS = [
26+
"@npm//jasmine-core",
27+
"@npm//karma",
28+
"@npm//karma-chrome-launcher",
29+
"@npm//karma-firefox-launcher",
30+
"@npm//karma-jasmine",
31+
"@npm//karma-requirejs",
32+
"@npm//karma-sourcemap-loader",
33+
"@npm//requirejs",
34+
"@npm//tmp",
35+
]
2536

26-
def karma_web_test(karma = INTERNAL_KARMA_BIN, **kwargs):
27-
data = kwargs.pop("data", []) + ["@npm_bazel_karma//:karma_plugins"]
28-
_karma_web_test(karma = karma, data = data, **kwargs)
37+
def karma_web_test(karma = _KARMA_BIN, **kwargs):
38+
_karma_web_test(karma = karma, peer_deps = _KARMA_PEER_DEPS, **kwargs)
2939

30-
def karma_web_test_suite(karma = INTERNAL_KARMA_BIN, **kwargs):
31-
data = kwargs.pop("data", []) + ["@npm_bazel_karma//:karma_plugins"]
32-
_karma_web_test_suite(karma = karma, data = data, **kwargs)
40+
def karma_web_test_suite(karma = _KARMA_BIN, **kwargs):
41+
_karma_web_test_suite(karma = karma, peer_deps = _KARMA_PEER_DEPS, **kwargs)

packages/karma/src/karma.conf.js

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,15 @@ try {
142142
function configureBazelConfig(config, conf) {
143143
// list of karma plugins
144144
mergeConfigArray(conf, 'plugins', [
145-
// Loads 'concat_js', 'watcher', 'jasmine', 'requirejs' and 'sourcemap'
146-
// from @bazel/karma. These packages are used in this config file.
147-
...require('@bazel/karma/plugins'),
145+
// Loads 'concat_js'
146+
require('@bazel/karma'),
147+
// Load plugins that are peer deps. These packages are used in this config file.
148+
require('karma-chrome-launcher'),
149+
require('karma-firefox-launcher'),
150+
require('karma-jasmine'),
151+
require('karma-requirejs'),
152+
require('karma-sourcemap-loader'),
148153
// Loads user-installed karma-* packages in the root node_modules.
149-
// If some of the plugins above are also installed in user project, the
150-
// user version would override the default.
151154
'karma-*',
152155
]);
153156

@@ -307,29 +310,7 @@ try {
307310

308311
const webTestMetadata = require(process.env['WEB_TEST_METADATA']);
309312
log_verbose(`WEB_TEST_METADATA: ${JSON.stringify(webTestMetadata, null, 2)}`);
310-
if (webTestMetadata['environment'] === 'sauce') {
311-
// If a sauce labs browser is chosen for the test such as
312-
// "@io_bazel_rules_webtesting//browsers/sauce:chrome-win10"
313-
// than the 'environment' will equal 'sauce'.
314-
// We expect that a SAUCE_USERNAME and SAUCE_ACCESS_KEY is available
315-
// from the environment for this test to run
316-
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
317-
console.error(
318-
'Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.');
319-
process.exit(1);
320-
}
321-
// 'capabilities' will specify the sauce labs configuration to use
322-
const capabilities = webTestMetadata['capabilities'];
323-
conf.customLaunchers = {
324-
'sauce': {
325-
base: 'SauceLabs',
326-
browserName: capabilities['browserName'],
327-
platform: capabilities['platform'],
328-
version: capabilities['version'],
329-
}
330-
};
331-
conf.browsers.push('sauce');
332-
} else if (webTestMetadata['environment'] === 'local') {
313+
if (webTestMetadata['environment'] === 'local') {
333314
// When a local chrome or firefox browser is chosen such as
334315
// "@io_bazel_rules_webtesting//browsers:chromium-local" or
335316
// "@io_bazel_rules_webtesting//browsers:firefox-local"
@@ -376,26 +357,6 @@ try {
376357
if (!conf.browsers.length) {
377358
throw new Error('No browsers configured in web test suite');
378359
}
379-
380-
// Extra configuration is needed for saucelabs
381-
// See: https://github.com/karma-runner/karma-sauce-launcher
382-
if (conf.customLaunchers) {
383-
// set the test name for sauce labs to use
384-
// TEST_BINARY is set by Bazel and contains the name of the test
385-
// target postfixed with the browser name such as
386-
// 'examples/testing/testing_sauce_chrome-win10' for the
387-
// test target examples/testing:testing
388-
if (!conf.sauceLabs) {
389-
conf.sauceLabs = {}
390-
}
391-
conf.sauceLabs.testName = process.env['TEST_BINARY'] || 'karma';
392-
393-
// Try "websocket" for a faster transmission first. Fallback to "polling" if necessary.
394-
overrideConfigValue(conf, 'transports', ['websocket', 'polling']);
395-
396-
// add the saucelabs reporter
397-
mergeConfigArray(conf, 'reporters', ['saucelabs']);
398-
}
399360
}
400361

401362
function configureTsWebTestConfig(conf) {

packages/karma/src/karma.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)