From af5959160b3e8ac46edfb60d8d1170289bfdf12a Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 25 Nov 2020 13:18:05 -0800 Subject: [PATCH 1/2] chore: move karma_web_test to concatjs BREAKING CHANGE: `packages/karma:package.bzl` is gone, in your WORKSPACE replace ``` load("//packages/karma:package.bzl", "npm_bazel_karma_dependencies") npm_bazel_karma_dependencies() ``` with the equivalent ``` http_archive( name = "io_bazel_rules_webtesting", sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"], ) ``` Then in BUILD files replace `load("@npm//@bazel/karma:index.bzl", "karma_web_test_suite")` with `load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite")` finally drop npm dependencies on `@bazel/karma` and depend on `@bazel/concatjs` instead --- WORKSPACE | 8 - commitlint.config.js | 1 - docs/BUILD.bazel | 1 - docs/Karma.html | 483 ------------------ docs/Karma.md | 235 --------- examples/BUILD.bazel | 5 +- examples/angular/WORKSPACE | 10 +- examples/angular/package.json | 1 - .../angular/src/app/hello-world/BUILD.bazel | 4 +- examples/angular/yarn.lock | 7 - examples/angular_view_engine/WORKSPACE | 10 +- examples/angular_view_engine/package.json | 1 - .../src/app/hello-world/BUILD.bazel | 4 +- examples/angular_view_engine/yarn.lock | 7 - examples/protocol_buffers/BUILD.bazel | 5 +- examples/protocol_buffers/WORKSPACE | 8 +- examples/protocol_buffers/package.json | 1 - examples/protocol_buffers/yarn.lock | 7 - examples/web_testing/BUILD.bazel | 6 +- examples/web_testing/WORKSPACE | 8 +- examples/web_testing/package.json | 2 +- examples/web_testing/yarn.lock | 7 - .../bazel_integration_test.bzl | 2 - package.bzl | 7 + packages/concatjs/BUILD.bazel | 29 ++ packages/concatjs/_README.md | 46 +- packages/concatjs/index.bzl | 7 + packages/{karma => concatjs}/index.ts | 1 + packages/concatjs/package.json | 11 + packages/concatjs/web_test/BUILD.bazel | 56 ++ .../web_test/concatjs_web_test.bzl} | 42 +- .../web_test}/karma.conf.js | 12 +- .../web_test}/test/karma/BUILD.bazel | 4 +- .../web_test}/test/karma/amd-modules.spec.js | 2 +- .../web_test}/test/karma/custom_chrome.json | 0 .../web_test}/test/karma/decrement.js | 2 +- .../web_test}/test/karma/decrement.spec.js | 6 +- .../web_test}/test/karma/init-test.js | 2 +- .../web_test}/test/karma/karma.conf.js.golden | 0 .../web_test}/test/karma/requirejs-config.js | 2 +- .../test/karma/test-initialized.spec.js | 2 +- .../web_test}/test/karma/tsconfig.json | 0 .../test/karma/unnamed-amd-module.js | 0 .../test/karma_typescript/BUILD.bazel | 4 +- .../test/karma_typescript/decrement.spec.ts | 0 .../test/karma_typescript/decrement.ts | 0 .../web_test}/test/karma_typescript/foobar.js | 0 .../test/karma_typescript/foobar.spec.ts | 0 .../test/karma_typescript/hello_world.spec.js | 2 +- .../test/karma_typescript/hello_world.ts | 0 .../test/karma_typescript/rxjs_shims.js | 0 .../test/karma_typescript/user_files.spec.js | 18 +- .../web_test}/test/stack_trace/BUILD.bazel | 6 +- .../test/stack_trace/failing.spec.ts | 0 .../test/stack_trace/test_folder/BUILD.bazel | 0 .../test/stack_trace/test_folder/hello.ts | 0 .../test/stack_trace/test_folder/test.spec.ts | 0 .../test/stack_trace/test_sourcemap.sh | 26 + packages/index.bzl | 2 +- packages/karma/BUILD.bazel | 129 ----- packages/karma/docs_test.js | 6 - packages/karma/index.bzl | 27 - packages/karma/install.md | 49 -- packages/karma/package.bzl | 38 -- packages/karma/package.json | 32 -- .../karma/test/stack_trace/test_sourcemap.sh | 26 - packages/karma/tsconfig.json | 9 - packages/labs/grpc_web/README.md | 2 +- packages/labs/protobufjs/ts_proto_library.bzl | 10 +- packages/labs/test/grpc_web/BUILD.bazel | 6 +- packages/protractor/protractor.conf.js | 4 +- packages/protractor/protractor_web_test.bzl | 6 +- 72 files changed, 282 insertions(+), 1174 deletions(-) delete mode 100755 docs/Karma.html delete mode 100755 docs/Karma.md rename packages/{karma => concatjs}/index.ts (99%) create mode 100644 packages/concatjs/web_test/BUILD.bazel rename packages/{karma/karma_web_test.bzl => concatjs/web_test/concatjs_web_test.bzl} (95%) rename packages/{karma => concatjs/web_test}/karma.conf.js (97%) rename packages/{karma => concatjs/web_test}/test/karma/BUILD.bazel (95%) rename packages/{karma => concatjs/web_test}/test/karma/amd-modules.spec.js (91%) rename packages/{karma => concatjs/web_test}/test/karma/custom_chrome.json (100%) rename packages/{karma => concatjs/web_test}/test/karma/decrement.js (80%) rename packages/{karma => concatjs/web_test}/test/karma/decrement.spec.js (70%) rename packages/{karma => concatjs/web_test}/test/karma/init-test.js (70%) rename packages/{karma => concatjs/web_test}/test/karma/karma.conf.js.golden (100%) rename packages/{karma => concatjs/web_test}/test/karma/requirejs-config.js (69%) rename packages/{karma => concatjs/web_test}/test/karma/test-initialized.spec.js (81%) rename packages/{karma => concatjs/web_test}/test/karma/tsconfig.json (100%) rename packages/{karma => concatjs/web_test}/test/karma/unnamed-amd-module.js (100%) rename packages/{karma => concatjs/web_test}/test/karma_typescript/BUILD.bazel (95%) rename packages/{karma => concatjs/web_test}/test/karma_typescript/decrement.spec.ts (100%) rename packages/{karma => concatjs/web_test}/test/karma_typescript/decrement.ts (100%) rename packages/{karma => concatjs/web_test}/test/karma_typescript/foobar.js (100%) rename packages/{karma => concatjs/web_test}/test/karma_typescript/foobar.spec.ts (100%) rename packages/{karma => concatjs/web_test}/test/karma_typescript/hello_world.spec.js (84%) rename packages/{karma => concatjs/web_test}/test/karma_typescript/hello_world.ts (100%) rename packages/{karma => concatjs/web_test}/test/karma_typescript/rxjs_shims.js (100%) rename packages/{karma => concatjs/web_test}/test/karma_typescript/user_files.spec.js (58%) rename packages/{karma => concatjs/web_test}/test/stack_trace/BUILD.bazel (90%) rename packages/{karma => concatjs/web_test}/test/stack_trace/failing.spec.ts (100%) rename packages/{karma => concatjs/web_test}/test/stack_trace/test_folder/BUILD.bazel (100%) rename packages/{karma => concatjs/web_test}/test/stack_trace/test_folder/hello.ts (100%) rename packages/{karma => concatjs/web_test}/test/stack_trace/test_folder/test.spec.ts (100%) create mode 100755 packages/concatjs/web_test/test/stack_trace/test_sourcemap.sh delete mode 100644 packages/karma/BUILD.bazel delete mode 100644 packages/karma/docs_test.js delete mode 100644 packages/karma/index.bzl delete mode 100644 packages/karma/install.md delete mode 100644 packages/karma/package.bzl delete mode 100644 packages/karma/package.json delete mode 100755 packages/karma/test/stack_trace/test_sourcemap.sh delete mode 100644 packages/karma/tsconfig.json diff --git a/WORKSPACE b/WORKSPACE index 7384bd3b09..d5a91f6441 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -140,14 +140,6 @@ cypress_repository( fail_on_error = False, ) -# -# Install @bazel/karma dependencies -# - -load("//packages/karma:package.bzl", "npm_bazel_karma_dependencies") - -npm_bazel_karma_dependencies() - # Setup the rules_webtesting toolchain load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") diff --git a/commitlint.config.js b/commitlint.config.js index 517ec8b5e9..24a295b246 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -13,7 +13,6 @@ module.exports = { 'cypress', 'examples', 'jasmine', - 'karma', 'labs', 'protractor', 'rollup', diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index bbc1d01f8c..ccb04183bb 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -76,7 +76,6 @@ rules_nodejs_docs( "Concatjs": "//packages/concatjs:README.md", "Cypress": "//packages/cypress:README.md", "Jasmine": "//packages/jasmine:README.md", - "Karma": "//packages/karma:README.md", "Labs": "//packages/labs:README.md", "Protractor": "//packages/protractor:README.md", "Rollup": "//packages/rollup:README.md", diff --git a/docs/Karma.html b/docs/Karma.html deleted file mode 100755 index 1849756d44..0000000000 --- a/docs/Karma.html +++ /dev/null @@ -1,483 +0,0 @@ - - - - - - - - - - rules_nodejs - Karma - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
- - - -
- - -
-
- -

Karma rules for Bazel

- -

The Karma rules run karma tests with Bazel.

- -

Installation

- -

Add the @bazel/karma npm package to your devDependencies in package.json.

- -

Now add this to your WORKSPACE to install the Karma dependencies:

- -
# Fetch transitive Bazel dependencies of @bazel/karma
-load("@npm//@bazel/karma:package.bzl", "npm_bazel_karma_dependencies")
-npm_bazel_karma_dependencies()
-
- -

This installs the io_bazel_rules_webtesting repository, if you haven’t installed it earlier.

- -

Finally, configure the rules_webtesting:

- -
# Set up web testing, choose browsers we can test on
-load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")
-
-web_test_repositories()
-
-load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories")
-
-browser_repositories(
-    chromium = True,
-    firefox = True,
-)
-
- -

Installing with self-managed dependencies

- -

If you didn’t use the yarn_install or npm_install rule to create an npm workspace, you’ll have to declare a rule in your root BUILD.bazel file to execute karma:

- -
# Create a karma rule to use in ts_web_test_suite karma
-# attribute when using self-managed dependencies
-nodejs_binary(
-    name = "karma/karma",
-    entry_point = "//:node_modules/karma/bin/karma",
-    # Point bazel to your node_modules to find the entry point
-    node_modules = ["//:node_modules"],
-)
-
- -

karma_web_test

- -

USAGE

- -
-karma_web_test(srcs, deps, data, configuration_env_vars, bootstrap, runtime_deps, static_files,
-               config_file, tags, peer_deps, kwargs)
-
- -

Runs unit tests in a browser with Karma.

- -

When executed under bazel test, this uses a headless browser for speed. -This is also because bazel test allows multiple targets to be tested together, -and we don’t want to open a Chrome window on your machine for each one. Also, -under bazel test the test will execute and immediately terminate.

- -

Running under ibazel test gives you a “watch mode” for your tests. The rule is -optimized for this case - the test runner server will stay running and just -re-serve the up-to-date JavaScript source bundle.

- -

To debug a single test target, run it with bazel run instead. This will open a -browser window on your computer. Also you can use any other browser by opening -the URL printed when the test starts up. The test will remain running until you -cancel the bazel run command.

- -

This rule will use your system Chrome by default. In the default case, your -environment must specify CHROME_BIN so that the rule will know which Chrome binary to run. -Other browsers and customLaunchers may be set using the a base Karma configuration -specified in the config_file attribute.

- -

By default we open a headless Chrome. To use a real Chrome browser window, you can pass ---define DISPLAY=true to Bazel, along with configuration_env_vars = ["DISPLAY"] on -karma_web_test.

- -

PARAMETERS

- -

srcs

- -

A list of JavaScript test files

- -

Defaults to []

- -

deps

- -

Other targets which produce JavaScript such as ts_library

- -

Defaults to []

- -

data

- -

Runtime dependencies

- -

Defaults to []

- -

configuration_env_vars

- -

Pass these configuration environment variables to the resulting binary. -Chooses a subset of the configuration environment variables (taken from ctx.var), which also -includes anything specified via the –define flag. -Note, this can lead to different outputs produced by this rule.

- -

Defaults to []

- -

bootstrap

- -

JavaScript files to include before the module loader (require.js). -For example, you can include Reflect,js for TypeScript decorator metadata reflection, -or UMD bundles for third-party libraries.

- -

Defaults to []

- -

runtime_deps

- -

Dependencies which should be loaded after the module loader but before the srcs and deps. -These should be a list of targets which produce JavaScript such as ts_library. -The files will be loaded in the same order they are declared by that rule.

- -

Defaults to []

- -

static_files

- -

Arbitrary files which are available to be served on request. -Files are served at: -/base/<WORKSPACE_NAME>/<path-to-file>, e.g. -/base/npm_bazel_typescript/examples/testing/static_script.js

- -

Defaults to []

- -

config_file

- -

User supplied Karma configuration file. Bazel will override -certain attributes of this configuration file. Attributes that are -overridden will be outputted to the test log.

- -

Defaults to None

- -

tags

- -

Standard Bazel tags, this macro adds tags for ibazel support

- -

Defaults to []

- -

peer_deps

- -

list of peer npm deps required by karma_web_test

- -

Defaults to ["@npm//jasmine-core", "@npm//karma", "@npm//karma-chrome-launcher", "@npm//karma-firefox-launcher", "@npm//karma-jasmine", "@npm//karma-requirejs", "@npm//karma-sourcemap-loader", "@npm//requirejs", "@npm//tmp"]

- -

kwargs

- -

Passed through to karma_web_test

- -

karma_web_test_suite

- -

USAGE

- -
-karma_web_test_suite(name, browsers, web_test_data, wrapped_test_tags, kwargs)
-
- -

Defines a test_suite of web_test targets that wrap a karma_web_test target.

- -

This macro accepts all parameters in karma_web_test and adds additional parameters -for the suite. See karma_web_test docs for all karma_web_test.

- -

The wrapping macro is web_test_suite which comes from rules_websting: -https://github.com/bazelbuild/rules_webtesting/blob/master/web/web.bzl.

- -

PARAMETERS

- -

name

- -

The base name of the test

- -

browsers

- -

A sequence of labels specifying the browsers to use.

- -

Defaults to None

- -

web_test_data

- -

Data dependencies for the wrapper web_test targets.

- -

Defaults to []

- -

wrapped_test_tags

- -

A list of test tag strings to use for the wrapped -karma_web_test target.

- -

Defaults to ["manual", "noci"]

- -

kwargs

- -

Arguments for the wrapped karma_web_test target.

- - -
-
- - -
-
- - - - - - - - - - - - - - - - - diff --git a/docs/Karma.md b/docs/Karma.md deleted file mode 100755 index 0e0c0229ec..0000000000 --- a/docs/Karma.md +++ /dev/null @@ -1,235 +0,0 @@ ---- -title: Karma -layout: default -toc: true -nav: rule ---- - -# Karma rules for Bazel - -The Karma rules run karma tests with Bazel. - - -## Installation - -Add the `@bazel/karma` npm package to your `devDependencies` in `package.json`. - -Now add this to your `WORKSPACE` to install the Karma dependencies: - -```python -# Fetch transitive Bazel dependencies of @bazel/karma -load("@npm//@bazel/karma:package.bzl", "npm_bazel_karma_dependencies") -npm_bazel_karma_dependencies() -``` - -This installs the `io_bazel_rules_webtesting` repository, if you haven't installed it earlier. - -Finally, configure the rules_webtesting: - -```python -# Set up web testing, choose browsers we can test on -load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") - -web_test_repositories() - -load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories") - -browser_repositories( - chromium = True, - firefox = True, -) -``` - - -## Installing with self-managed dependencies - -If you didn't use the `yarn_install` or `npm_install` rule to create an `npm` workspace, you'll have to declare a rule in your root `BUILD.bazel` file to execute karma: - -```python -# Create a karma rule to use in ts_web_test_suite karma -# attribute when using self-managed dependencies -nodejs_binary( - name = "karma/karma", - entry_point = "//:node_modules/karma/bin/karma", - # Point bazel to your node_modules to find the entry point - node_modules = ["//:node_modules"], -) -``` - - - -## karma_web_test - -**USAGE** - -
-karma_web_test(srcs, deps, data, configuration_env_vars, bootstrap, runtime_deps, static_files,
-               config_file, tags, peer_deps, kwargs)
-
- -Runs unit tests in a browser with Karma. - -When executed under `bazel test`, this uses a headless browser for speed. -This is also because `bazel test` allows multiple targets to be tested together, -and we don't want to open a Chrome window on your machine for each one. Also, -under `bazel test` the test will execute and immediately terminate. - -Running under `ibazel test` gives you a "watch mode" for your tests. The rule is -optimized for this case - the test runner server will stay running and just -re-serve the up-to-date JavaScript source bundle. - -To debug a single test target, run it with `bazel run` instead. This will open a -browser window on your computer. Also you can use any other browser by opening -the URL printed when the test starts up. The test will remain running until you -cancel the `bazel run` command. - -This rule will use your system Chrome by default. In the default case, your -environment must specify CHROME_BIN so that the rule will know which Chrome binary to run. -Other `browsers` and `customLaunchers` may be set using the a base Karma configuration -specified in the `config_file` attribute. - -By default we open a headless Chrome. To use a real Chrome browser window, you can pass -`--define DISPLAY=true` to Bazel, along with `configuration_env_vars = ["DISPLAY"]` on -`karma_web_test`. - - -**PARAMETERS** - - -

srcs

- -A list of JavaScript test files - -Defaults to `[]` - -

deps

- -Other targets which produce JavaScript such as `ts_library` - -Defaults to `[]` - -

data

- -Runtime dependencies - -Defaults to `[]` - -

configuration_env_vars

- -Pass these configuration environment variables to the resulting binary. -Chooses a subset of the configuration environment variables (taken from ctx.var), which also -includes anything specified via the --define flag. -Note, this can lead to different outputs produced by this rule. - -Defaults to `[]` - -

bootstrap

- -JavaScript files to include *before* the module loader (require.js). -For example, you can include Reflect,js for TypeScript decorator metadata reflection, -or UMD bundles for third-party libraries. - -Defaults to `[]` - -

runtime_deps

- -Dependencies which should be loaded after the module loader but before the srcs and deps. -These should be a list of targets which produce JavaScript such as `ts_library`. -The files will be loaded in the same order they are declared by that rule. - -Defaults to `[]` - -

static_files

- -Arbitrary files which are available to be served on request. -Files are served at: -`/base/<WORKSPACE_NAME>/<path-to-file>`, e.g. -`/base/npm_bazel_typescript/examples/testing/static_script.js` - -Defaults to `[]` - -

config_file

- -User supplied Karma configuration file. Bazel will override -certain attributes of this configuration file. Attributes that are -overridden will be outputted to the test log. - -Defaults to `None` - -

tags

- -Standard Bazel tags, this macro adds tags for ibazel support - -Defaults to `[]` - -

peer_deps

- -list of peer npm deps required by karma_web_test - -Defaults to `["@npm//jasmine-core", "@npm//karma", "@npm//karma-chrome-launcher", "@npm//karma-firefox-launcher", "@npm//karma-jasmine", "@npm//karma-requirejs", "@npm//karma-sourcemap-loader", "@npm//requirejs", "@npm//tmp"]` - -

kwargs

- -Passed through to `karma_web_test` - - - - - -## karma_web_test_suite - -**USAGE** - -
-karma_web_test_suite(name, browsers, web_test_data, wrapped_test_tags, kwargs)
-
- -Defines a test_suite of web_test targets that wrap a karma_web_test target. - -This macro accepts all parameters in karma_web_test and adds additional parameters -for the suite. See karma_web_test docs for all karma_web_test. - -The wrapping macro is `web_test_suite` which comes from rules_websting: -https://github.com/bazelbuild/rules_webtesting/blob/master/web/web.bzl. - - -**PARAMETERS** - - -

name

- -The base name of the test - - - -

browsers

- -A sequence of labels specifying the browsers to use. - -Defaults to `None` - -

web_test_data

- -Data dependencies for the wrapper web_test targets. - -Defaults to `[]` - -

wrapped_test_tags

- -A list of test tag strings to use for the wrapped -karma_web_test target. - -Defaults to `["manual", "noci"]` - -

kwargs

- -Arguments for the wrapped karma_web_test target. - - - - diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 162e917550..ca13a6630e 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -20,7 +20,6 @@ example_integration_test( npm_packages = { "//packages/angular:npm_package": "@bazel/angular", "//packages/concatjs:npm_package": "@bazel/concatjs", - "//packages/karma:npm_package": "@bazel/karma", "//packages/protractor:npm_package": "@bazel/protractor", "//packages/rollup:npm_package": "@bazel/rollup", "//packages/terser:npm_package": "@bazel/terser", @@ -46,7 +45,6 @@ example_integration_test( timeout = "long", npm_packages = { "//packages/concatjs:npm_package": "@bazel/concatjs", - "//packages/karma:npm_package": "@bazel/karma", "//packages/protractor:npm_package": "@bazel/protractor", "//packages/rollup:npm_package": "@bazel/rollup", "//packages/terser:npm_package": "@bazel/terser", @@ -142,7 +140,7 @@ example_integration_test( example_integration_test( name = "examples_web_testing", npm_packages = { - "//packages/karma:npm_package": "@bazel/karma", + "//packages/concatjs:npm_package": "@bazel/concatjs", "//packages/typescript:npm_package": "@bazel/typescript", }, ) @@ -190,7 +188,6 @@ example_integration_test( timeout = "long", npm_packages = { "//packages/concatjs:npm_package": "@bazel/concatjs", - "//packages/karma:npm_package": "@bazel/karma", "//packages/labs:npm_package": "@bazel/labs", "//packages/protractor:npm_package": "@bazel/protractor", "//packages/rollup:npm_package": "@bazel/rollup", diff --git a/examples/angular/WORKSPACE b/examples/angular/WORKSPACE index 7d1d7cbd78..64ad073972 100644 --- a/examples/angular/WORKSPACE +++ b/examples/angular/WORKSPACE @@ -59,10 +59,12 @@ load("@npm//@bazel/protractor:package.bzl", "npm_bazel_protractor_dependencies") npm_bazel_protractor_dependencies() -# Load @bazel/karma dependencies -load("@npm//@bazel/karma:package.bzl", "npm_bazel_karma_dependencies") - -npm_bazel_karma_dependencies() +# Load concatjs_web_test dependencies +http_archive( + name = "io_bazel_rules_webtesting", + sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", + urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"], +) # Setup the rules_webtesting toolchain load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") diff --git a/examples/angular/package.json b/examples/angular/package.json index 54239c1a2e..d80bc14018 100644 --- a/examples/angular/package.json +++ b/examples/angular/package.json @@ -42,7 +42,6 @@ "@bazel/buildifier": "^3.5.0", "@bazel/concatjs": "^2.2.2", "@bazel/ibazel": "^0.13.2", - "@bazel/karma": "^2.2.2", "@bazel/protractor": "^2.2.2", "@bazel/rollup": "^2.2.2", "@bazel/terser": "^2.2.2", diff --git a/examples/angular/src/app/hello-world/BUILD.bazel b/examples/angular/src/app/hello-world/BUILD.bazel index d25c978c1d..488f10d4a4 100644 --- a/examples/angular/src/app/hello-world/BUILD.bazel +++ b/examples/angular/src/app/hello-world/BUILD.bazel @@ -1,5 +1,5 @@ load("@io_bazel_rules_sass//:defs.bzl", "multi_sass_binary") -load("@npm//@bazel/karma:index.bzl", "karma_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite") load("@npm//@bazel/typescript:index.bzl", "ts_library") load("//tools:angular_ts_library.bzl", "ng_ts_library") @@ -49,7 +49,7 @@ ts_library( ], ) -karma_web_test_suite( +concatjs_web_test_suite( name = "test", srcs = [ # We are manaully adding the bazel generated named-UMD date-fns bundle here as diff --git a/examples/angular/yarn.lock b/examples/angular/yarn.lock index 9a525c80c2..9326e25dd1 100644 --- a/examples/angular/yarn.lock +++ b/examples/angular/yarn.lock @@ -883,13 +883,6 @@ resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.13.2.tgz#eb914c41c66af4606db786457a7b130634355e8f" integrity sha512-q5fGwjTY76MLNcYpF2zEu/y1Clu4DjdjhvJM9+yDKc3+3mBlbX+uiMJYiCz5b0oSYdJTlw1QSRptTYA7CID8EQ== -"@bazel/karma@^2.2.2": - version "2.2.2" - resolved "https://registry.yarnpkg.com/@bazel/karma/-/karma-2.2.2.tgz#89470c42c527973bb59a02527b55ef9225dcbfc0" - integrity sha512-V5y2N5d6RXde/4TQ8UcNg3IBdLx1tob6drYlHB7nYF3soShucTOfvEyENCLzn4LVeFgTrR8gdob5b3TzvYUCCw== - dependencies: - tmp "0.1.0" - "@bazel/protractor@^2.2.2": version "2.2.2" resolved "https://registry.yarnpkg.com/@bazel/protractor/-/protractor-2.2.2.tgz#0660837a193994ee349e15cb022de76f3262af5e" diff --git a/examples/angular_view_engine/WORKSPACE b/examples/angular_view_engine/WORKSPACE index 14e5c3675f..1f7383c25d 100644 --- a/examples/angular_view_engine/WORKSPACE +++ b/examples/angular_view_engine/WORKSPACE @@ -53,10 +53,12 @@ load("@npm//@bazel/protractor:package.bzl", "npm_bazel_protractor_dependencies") npm_bazel_protractor_dependencies() -# Load @bazel/karma dependencies -load("@npm//@bazel/karma:package.bzl", "npm_bazel_karma_dependencies") - -npm_bazel_karma_dependencies() +# Load karma dependencies +http_archive( + name = "io_bazel_rules_webtesting", + sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", + urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"], +) # Setup the rules_webtesting toolchain load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") diff --git a/examples/angular_view_engine/package.json b/examples/angular_view_engine/package.json index f1f8019abc..8aa8d9c76b 100644 --- a/examples/angular_view_engine/package.json +++ b/examples/angular_view_engine/package.json @@ -37,7 +37,6 @@ "@bazel/buildifier": "^3.5.0", "@bazel/ibazel": "^0.13.2", "@bazel/concatjs": "^2.2.2", - "@bazel/karma": "^2.2.2", "@bazel/protractor": "^2.2.2", "@bazel/rollup": "^2.2.2", "@bazel/terser": "^2.2.2", diff --git a/examples/angular_view_engine/src/app/hello-world/BUILD.bazel b/examples/angular_view_engine/src/app/hello-world/BUILD.bazel index 20e106eed2..8f5ebee668 100644 --- a/examples/angular_view_engine/src/app/hello-world/BUILD.bazel +++ b/examples/angular_view_engine/src/app/hello-world/BUILD.bazel @@ -1,5 +1,5 @@ load("@io_bazel_rules_sass//:defs.bzl", "sass_binary") -load("@npm//@bazel/karma:index.bzl", "karma_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite") load("@npm//@bazel/typescript:index.bzl", "ts_library") load("@npm_angular_bazel//:index.bzl", "ng_module") @@ -59,7 +59,7 @@ ts_library( ], ) -karma_web_test_suite( +concatjs_web_test_suite( name = "test", srcs = [ # We are manaully adding the bazel generated named-UMD date-fns bundle here as diff --git a/examples/angular_view_engine/yarn.lock b/examples/angular_view_engine/yarn.lock index b2e1e23a8e..d1e015dd44 100644 --- a/examples/angular_view_engine/yarn.lock +++ b/examples/angular_view_engine/yarn.lock @@ -833,13 +833,6 @@ resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.13.2.tgz#eb914c41c66af4606db786457a7b130634355e8f" integrity sha512-q5fGwjTY76MLNcYpF2zEu/y1Clu4DjdjhvJM9+yDKc3+3mBlbX+uiMJYiCz5b0oSYdJTlw1QSRptTYA7CID8EQ== -"@bazel/karma@^2.2.2": - version "2.2.2" - resolved "https://registry.yarnpkg.com/@bazel/karma/-/karma-2.2.2.tgz#89470c42c527973bb59a02527b55ef9225dcbfc0" - integrity sha512-V5y2N5d6RXde/4TQ8UcNg3IBdLx1tob6drYlHB7nYF3soShucTOfvEyENCLzn4LVeFgTrR8gdob5b3TzvYUCCw== - dependencies: - tmp "0.1.0" - "@bazel/protractor@^2.2.2": version "2.2.2" resolved "https://registry.yarnpkg.com/@bazel/protractor/-/protractor-2.2.2.tgz#0660837a193994ee349e15cb022de76f3262af5e" diff --git a/examples/protocol_buffers/BUILD.bazel b/examples/protocol_buffers/BUILD.bazel index 6f7181dcc8..c0740a2360 100644 --- a/examples/protocol_buffers/BUILD.bazel +++ b/examples/protocol_buffers/BUILD.bazel @@ -1,5 +1,4 @@ -load("@npm//@bazel/concatjs:index.bzl", "concatjs_devserver") -load("@npm//@bazel/karma:index.bzl", "karma_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "concatjs_devserver", "concatjs_web_test_suite") load("@npm//@bazel/labs:index.bzl", "ts_proto_library") load("@npm//@bazel/protractor:index.bzl", "protractor_web_test_suite") load("@npm//@bazel/rollup:index.bzl", "rollup_bundle") @@ -54,7 +53,7 @@ ts_library( ], ) -karma_web_test_suite( +concatjs_web_test_suite( name = "test", srcs = [ "@npm//@bazel/labs/grpc_web:bootstrap_scripts", diff --git a/examples/protocol_buffers/WORKSPACE b/examples/protocol_buffers/WORKSPACE index 960cb6ebfb..2b723bdbc6 100644 --- a/examples/protocol_buffers/WORKSPACE +++ b/examples/protocol_buffers/WORKSPACE @@ -53,9 +53,11 @@ load("@npm//@bazel/protractor:package.bzl", "npm_bazel_protractor_dependencies") npm_bazel_protractor_dependencies() -load("@npm//@bazel/karma:package.bzl", "npm_bazel_karma_dependencies") - -npm_bazel_karma_dependencies() +http_archive( + name = "io_bazel_rules_webtesting", + sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", + urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"], +) load("@npm//@bazel/labs:package.bzl", "npm_bazel_labs_dependencies") diff --git a/examples/protocol_buffers/package.json b/examples/protocol_buffers/package.json index 9cf5fd9f96..c0d8a947c0 100644 --- a/examples/protocol_buffers/package.json +++ b/examples/protocol_buffers/package.json @@ -1,7 +1,6 @@ { "devDependencies": { "@bazel/concatjs": "^2.2.2", - "@bazel/karma": "^2.2.2", "@bazel/labs": "^2.2.2", "@bazel/protractor": "^2.2.2", "@bazel/rollup": "^2.2.2", diff --git a/examples/protocol_buffers/yarn.lock b/examples/protocol_buffers/yarn.lock index 4f0f973f1d..a74420201a 100644 --- a/examples/protocol_buffers/yarn.lock +++ b/examples/protocol_buffers/yarn.lock @@ -2,13 +2,6 @@ # yarn lockfile v1 -"@bazel/karma@^2.2.2": - version "2.2.2" - resolved "https://registry.yarnpkg.com/@bazel/karma/-/karma-2.2.2.tgz#89470c42c527973bb59a02527b55ef9225dcbfc0" - integrity sha512-V5y2N5d6RXde/4TQ8UcNg3IBdLx1tob6drYlHB7nYF3soShucTOfvEyENCLzn4LVeFgTrR8gdob5b3TzvYUCCw== - dependencies: - tmp "0.1.0" - "@bazel/labs@^2.2.2": version "2.2.2" resolved "https://registry.yarnpkg.com/@bazel/labs/-/labs-2.2.2.tgz#0f57547d845bf3539c629b912ce74fc1391a7e20" diff --git a/examples/web_testing/BUILD.bazel b/examples/web_testing/BUILD.bazel index 187ecf7a76..e43ea95d75 100644 --- a/examples/web_testing/BUILD.bazel +++ b/examples/web_testing/BUILD.bazel @@ -1,4 +1,4 @@ -load("@npm//@bazel/karma:index.bzl", "karma_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite") load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_library") ts_library( @@ -35,7 +35,7 @@ ts_library( ], ) -karma_web_test_suite( +concatjs_web_test_suite( name = "config_test", browsers = [ "@io_bazel_rules_webtesting//browsers:chromium-local", @@ -55,7 +55,7 @@ karma_web_test_suite( ], ) -karma_web_test_suite( +concatjs_web_test_suite( name = "no_config_test", browsers = [ "@io_bazel_rules_webtesting//browsers:chromium-local", diff --git a/examples/web_testing/WORKSPACE b/examples/web_testing/WORKSPACE index 3a78b3799f..a20337f6ed 100644 --- a/examples/web_testing/WORKSPACE +++ b/examples/web_testing/WORKSPACE @@ -33,9 +33,11 @@ yarn_install( yarn_lock = "//:yarn.lock", ) -load("@npm//@bazel/karma:package.bzl", "npm_bazel_karma_dependencies") - -npm_bazel_karma_dependencies() +http_archive( + name = "io_bazel_rules_webtesting", + sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", + urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"], +) load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") diff --git a/examples/web_testing/package.json b/examples/web_testing/package.json index 4a82962cb7..83e00e7678 100644 --- a/examples/web_testing/package.json +++ b/examples/web_testing/package.json @@ -1,6 +1,6 @@ { "devDependencies": { - "@bazel/karma": "^2.2.2", + "@bazel/concatjs": "^2.2.2", "@bazel/typescript": "^2.2.2", "@types/jasmine": "2.8.2", "@types/node": "11.11.1", diff --git a/examples/web_testing/yarn.lock b/examples/web_testing/yarn.lock index 30104c5da1..0f3c46b485 100644 --- a/examples/web_testing/yarn.lock +++ b/examples/web_testing/yarn.lock @@ -2,13 +2,6 @@ # yarn lockfile v1 -"@bazel/karma@^2.2.2": - version "2.2.2" - resolved "https://registry.yarnpkg.com/@bazel/karma/-/karma-2.2.2.tgz#89470c42c527973bb59a02527b55ef9225dcbfc0" - integrity sha512-V5y2N5d6RXde/4TQ8UcNg3IBdLx1tob6drYlHB7nYF3soShucTOfvEyENCLzn4LVeFgTrR8gdob5b3TzvYUCCw== - dependencies: - tmp "0.1.0" - "@bazel/typescript@^2.2.2": version "2.2.2" resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-2.2.2.tgz#c7cd49cb630ca3720c04c94046ba8ca4c0d5b0aa" diff --git a/internal/bazel_integration_test/bazel_integration_test.bzl b/internal/bazel_integration_test/bazel_integration_test.bzl index 00be6b63b1..61d6b9877f 100644 --- a/internal/bazel_integration_test/bazel_integration_test.bzl +++ b/internal/bazel_integration_test/bazel_integration_test.bzl @@ -170,7 +170,6 @@ replaced in all integration tests. For example, ``` check_npm_packages = [ "@bazel/jasmine", - "@bazel/karma", "@bazel/labs", "@bazel/protractor", "@bazel/typescript", @@ -190,7 +189,6 @@ For example, ``` npm_packages = { "//packages/jasmine:npm_package": "@bazel/jasmine", - "//packages/karma:npm_package": "@bazel/karma", "//packages/typescript:npm_package": "@bazel/typescript", } ```""", diff --git a/package.bzl b/package.bzl index f573191a8a..3ca9f39cc3 100644 --- a/package.bzl +++ b/package.bzl @@ -118,6 +118,13 @@ def rules_nodejs_dev_dependencies(): sha256 = "aeca78988341a2ee1ba097641056d168320ecc51372ef7ff8e64b139516a4937", ) + _maybe( + http_archive, + name = "io_bazel_rules_webtesting", + sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", + urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"], + ) + def _maybe(repo_rule, name, **kwargs): if name not in native.existing_rules(): repo_rule(name = name, **kwargs) diff --git a/packages/concatjs/BUILD.bazel b/packages/concatjs/BUILD.bazel index e3c55d1af7..91babea3f6 100644 --- a/packages/concatjs/BUILD.bazel +++ b/packages/concatjs/BUILD.bazel @@ -13,10 +13,33 @@ # limitations under the License. load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") +load("@build_bazel_rules_nodejs//packages/typescript:index.bzl", "ts_project") load("@build_bazel_rules_nodejs//tools/stardoc:index.bzl", "stardoc") load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file") +ts_project( + name = "bazel_concatjs_lib", + srcs = glob(["*.ts"]), + tsconfig = { + "compilerOptions": { + "declaration": True, + "module": "umd", + "moduleResolution": "node", + "types": ["node"], + }, + }, + deps = ["@npm//@types/node"], +) + +js_library( + name = "bazel_concatjs", + package_name = "@bazel/concatjs", + srcs = ["bazel_concatjs_lib"], + visibility = ["//packages/concatjs:__subpackages__"], +) + bzl_library( name = "bzl", srcs = glob(["*.bzl"]) + [ @@ -68,16 +91,22 @@ pkg_npm( "package.json", "//packages/concatjs/devserver:package_contents", "//packages/concatjs/third_party/npm/requirejs:package_contents", + "//packages/concatjs/web_test:package_contents", ], build_file_content = "", nested_packages = [ "@build_bazel_rules_typescript//:npm_bazel_typescript_package", ], + substitutions = { + "#@external ": "", + "//packages/concatjs/web_test:karma_bin": "@npm//karma/bin:karma", + }, vendor_external = [ "build_bazel_rules_typescript", ], deps = [ ":npm_version_check", + ":bazel_concatjs_lib", ] + select({ # FIXME: fix stardoc on Windows "@bazel_tools//src/conditions:windows": [], diff --git a/packages/concatjs/_README.md b/packages/concatjs/_README.md index 9152a8cdc7..b52362a188 100644 --- a/packages/concatjs/_README.md +++ b/packages/concatjs/_README.md @@ -19,7 +19,7 @@ Most packages do not ship with this format, so in order to use concatjs tooling, This is at the core of how Google does JavaScript development. So Bazel rules that originated in Google's codebase have affordances for concatjs. For example `ts_library` produces named AMD modules in its "devmode" output, and -`karma_web_test` expects to bundle inputs using concatjs. +`concatjs_web_test` expects to bundle inputs using concatjs. ## Serving JS in development mode under Bazel @@ -75,3 +75,47 @@ server so the browser refreshes the application automatically when each build finishes. [ibazel]: https://github.com/bazelbuild/bazel-watcher + +## Testing with Karma + +The `concatjs_web_test` rule runs karma tests with Bazel. + +It depends on rules_webtesting, so you need to add this to your `WORKSPACE` +if you use the web testing rules in `@bazel/concatjs`: + +```python +# Fetch transitive Bazel dependencies of concatjs_web_test +http_archive( + name = "io_bazel_rules_webtesting", + sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", + urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"], +) + +# Set up web testing, choose browsers we can test on +load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") + +web_test_repositories() + +load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories") + +browser_repositories( + chromium = True, + firefox = True, +) +``` + +## Installing with self-managed dependencies + +If you didn't use the `yarn_install` or `npm_install` rule to create an `npm` workspace, you'll have to declare a rule in your root `BUILD.bazel` file to execute karma: + +```python +# Create a karma rule to use in concatjs_web_test_suite karma +# attribute when using self-managed dependencies +nodejs_binary( + name = "karma/karma", + entry_point = "//:node_modules/karma/bin/karma", + # Point bazel to your node_modules to find the entry point + node_modules = ["//:node_modules"], +) +``` + diff --git a/packages/concatjs/index.bzl b/packages/concatjs/index.bzl index cd8845ff5a..1de0f9807d 100644 --- a/packages/concatjs/index.bzl +++ b/packages/concatjs/index.bzl @@ -18,5 +18,12 @@ Users should not load files under "/internal" """ load("//packages/concatjs/devserver:concatjs_devserver.bzl", _concatjs_devserver = "concatjs_devserver_macro") +load( + "//packages/concatjs/web_test:concatjs_web_test.bzl", + _concatjs_web_test = "concatjs_web_test", + _concatjs_web_test_suite = "concatjs_web_test_suite", +) +concatjs_web_test = _concatjs_web_test +concatjs_web_test_suite = _concatjs_web_test_suite concatjs_devserver = _concatjs_devserver diff --git a/packages/karma/index.ts b/packages/concatjs/index.ts similarity index 99% rename from packages/karma/index.ts rename to packages/concatjs/index.ts index 31308ab358..7f87a6ca16 100644 --- a/packages/karma/index.ts +++ b/packages/concatjs/index.ts @@ -1,3 +1,4 @@ +/// /* * Concat all JS files before serving. */ diff --git a/packages/concatjs/package.json b/packages/concatjs/package.json index ee806c6b8f..62e71b0df1 100644 --- a/packages/concatjs/package.json +++ b/packages/concatjs/package.json @@ -14,11 +14,22 @@ "keywords": [ "bazel" ], + "main": "./index.js", + "typings": "./index.d.ts", "dependencies": { "protobufjs": "6.8.8", "source-map-support": "0.5.9", "tsutils": "2.27.2" }, + "peerDependencies": { + "jasmine-core": ">=2.0.0", + "karma": ">=4.0.0", + "karma-chrome-launcher": ">=2.0.0", + "karma-firefox-launcher": ">=1.0.0", + "karma-jasmine": ">=2.0.0", + "karma-requirejs": ">=1.0.0", + "karma-sourcemap-loader": ">=0.3.0" + }, "scripts": { "postinstall": "node npm_version_check.js" } diff --git a/packages/concatjs/web_test/BUILD.bazel b/packages/concatjs/web_test/BUILD.bazel new file mode 100644 index 0000000000..4b141795e6 --- /dev/null +++ b/packages/concatjs/web_test/BUILD.bazel @@ -0,0 +1,56 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") + +package(default_visibility = ["//visibility:public"]) + +exports_files(["karma.conf.js"]) + +nodejs_binary( + name = "karma_bin", + data = [ + "//packages/concatjs:bazel_concatjs", + "@npm//jasmine-core", + "@npm//karma", + "@npm//karma-chrome-launcher", + "@npm//karma-firefox-launcher", + "@npm//karma-jasmine", + "@npm//karma-requirejs", + "@npm//karma-sourcemap-loader", + "@npm//requirejs", + ], + entry_point = "@npm//:node_modules/karma/bin/karma", +) + +bzl_library( + name = "bzl", + testonly = True, + srcs = glob(["*.bzl"]), + deps = [ + "@build_bazel_rules_nodejs//:bzl", + "@build_bazel_rules_nodejs//internal/js_library:bzl", + "@io_bazel_rules_webtesting//web", + ], +) + +filegroup( + name = "package_contents", + srcs = [ + "BUILD.bazel", + "concatjs_web_test.bzl", + "karma.conf.js", + ], +) diff --git a/packages/karma/karma_web_test.bzl b/packages/concatjs/web_test/concatjs_web_test.bzl similarity index 95% rename from packages/karma/karma_web_test.bzl rename to packages/concatjs/web_test/concatjs_web_test.bzl index 3c2faf10e4..cc4b7db21f 100644 --- a/packages/karma/karma_web_test.bzl +++ b/packages/concatjs/web_test/concatjs_web_test.bzl @@ -20,7 +20,7 @@ load("@io_bazel_rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_ KARMA_PEER_DEPS = [ # NB: uncommented during pkg_npm - #@external "@npm//@bazel/karma", + #@external "@npm//@bazel/concatjs", "@npm//jasmine-core", "@npm//karma", "@npm//karma-chrome-launcher", @@ -31,7 +31,7 @@ KARMA_PEER_DEPS = [ "@npm//requirejs", ] -KARMA_WEB_TEST_ATTRS = { +CONCATJS_WEB_TEST_ATTRS = { "bootstrap": attr.label_list( doc = """JavaScript files to include *before* the module loader (require.js). For example, you can include Reflect,js for TypeScript decorator metadata reflection, @@ -63,7 +63,7 @@ KARMA_WEB_TEST_ATTRS = { "karma": attr.label( doc = "karma binary label", # NB: replaced during pkg_npm with "@npm//karma/bin:karma" - default = "//packages/karma:karma_bin", + default = "//packages/concatjs/web_test:karma_bin", executable = True, cfg = "target", allow_files = True, @@ -87,7 +87,7 @@ KARMA_WEB_TEST_ATTRS = { allow_files = True, ), "_conf_tmpl": attr.label( - default = "//packages/karma:karma.conf.js", + default = "//packages/concatjs/web_test:karma.conf.js", allow_single_file = True, ), } @@ -207,7 +207,7 @@ def _write_karma_config(ctx, files, amd_names_shim): return configuration -def _karma_web_test_impl(ctx): +def _concatjs_web_test_impl(ctx): files_depsets = [depset(ctx.files.srcs)] for dep in ctx.attr.deps + ctx.attr.runtime_deps: if JSNamedModuleInfo in dep: @@ -316,17 +316,17 @@ ${{COMMAND}} executable = ctx.outputs.executable, )] -_karma_web_test = rule( - implementation = _karma_web_test_impl, +_concatjs_web_test = rule( + implementation = _concatjs_web_test_impl, test = True, executable = True, - attrs = KARMA_WEB_TEST_ATTRS, + attrs = CONCATJS_WEB_TEST_ATTRS, outputs = { "configuration": "%{name}.conf.js", }, ) -def karma_web_test( +def concatjs_web_test( srcs = [], deps = [], data = [], @@ -361,7 +361,7 @@ def karma_web_test( By default we open a headless Chrome. To use a real Chrome browser window, you can pass `--define DISPLAY=true` to Bazel, along with `configuration_env_vars = ["DISPLAY"]` on - `karma_web_test`. + `concatjs_web_test`. Args: srcs: A list of JavaScript test files @@ -385,11 +385,11 @@ def karma_web_test( certain attributes of this configuration file. Attributes that are overridden will be outputted to the test log. tags: Standard Bazel tags, this macro adds tags for ibazel support - peer_deps: list of peer npm deps required by karma_web_test - **kwargs: Passed through to `karma_web_test` + peer_deps: list of peer npm deps required by concatjs_web_test + **kwargs: Passed through to `concatjs_web_test` """ - _karma_web_test( + _concatjs_web_test( srcs = srcs, deps = deps + peer_deps, data = data, @@ -405,16 +405,16 @@ def karma_web_test( **kwargs ) -def karma_web_test_suite( +def concatjs_web_test_suite( name, browsers = None, web_test_data = [], wrapped_test_tags = list(DEFAULT_WRAPPED_TEST_TAGS), **kwargs): - """Defines a test_suite of web_test targets that wrap a karma_web_test target. + """Defines a test_suite of web_test targets that wrap a concatjs_web_test target. - This macro accepts all parameters in karma_web_test and adds additional parameters - for the suite. See karma_web_test docs for all karma_web_test. + This macro accepts all parameters in concatjs_web_test and adds additional parameters + for the suite. See concatjs_web_test docs for all concatjs_web_test. The wrapping macro is `web_test_suite` which comes from rules_websting: https://github.com/bazelbuild/rules_webtesting/blob/master/web/web.bzl. @@ -424,8 +424,8 @@ def karma_web_test_suite( browsers: A sequence of labels specifying the browsers to use. web_test_data: Data dependencies for the wrapper web_test targets. wrapped_test_tags: A list of test tag strings to use for the wrapped - karma_web_test target. - **kwargs: Arguments for the wrapped karma_web_test target. + concatjs_web_test target. + **kwargs: Arguments for the wrapped concatjs_web_test target. """ # Common attributes @@ -452,9 +452,9 @@ def karma_web_test_suite( if not "native" in tags: tags = tags + ["native"] - # The wrapped `karma_web_test` target + # The wrapped `concatjs_web_test` target wrapped_test_name = name + "_wrapped_test" - karma_web_test( + concatjs_web_test( name = wrapped_test_name, args = args, flaky = flaky, diff --git a/packages/karma/karma.conf.js b/packages/concatjs/web_test/karma.conf.js similarity index 97% rename from packages/karma/karma.conf.js rename to packages/concatjs/web_test/karma.conf.js index de39889783..df9057a977 100644 --- a/packages/karma/karma.conf.js +++ b/packages/concatjs/web_test/karma.conf.js @@ -137,14 +137,14 @@ try { } /** - * Configuration settings for karma under Bazel common to karma_web_test - * and karma_web_test_suite. + * Configuration settings for karma under Bazel common to concatjs_web_test + * and concatjs_web_test_suite. */ function configureBazelConfig(config, conf) { // list of karma plugins mergeConfigArray(conf, 'plugins', [ // Loads 'concat_js' - require('@bazel/karma'), + require('@bazel/concatjs'), // Load plugins that are peer deps. These packages are used in this config file. require('karma-chrome-launcher'), require('karma-firefox-launcher'), @@ -279,7 +279,7 @@ try { } /** - * Configure karma under karma_web_test_suite. + * Configure karma under concatjs_web_test_suite. * `browsers` and `customLaunchers` are setup by Bazel. */ function configureTsWebTestSuiteConfig(conf) { @@ -287,7 +287,7 @@ try { // of the browsers attribute passed to karms_web_test_suite // We setup the karma configuration based on the values in this object if (!process.env['WEB_TEST_METADATA']) { - // This is a karma_web_test rule since there is no WEB_TEST_METADATA + // This is a concatjs_web_test rule since there is no WEB_TEST_METADATA return; } @@ -369,7 +369,7 @@ try { function configureTsWebTestConfig(conf) { if (process.env['WEB_TEST_METADATA']) { - // This is a karma_web_test_suite rule since there is a WEB_TEST_METADATA + // This is a concatjs_web_test_suite rule since there is a WEB_TEST_METADATA return; } diff --git a/packages/karma/test/karma/BUILD.bazel b/packages/concatjs/web_test/test/karma/BUILD.bazel similarity index 95% rename from packages/karma/test/karma/BUILD.bazel rename to packages/concatjs/web_test/test/karma/BUILD.bazel index aee67d3354..e3d4379e0a 100644 --- a/packages/karma/test/karma/BUILD.bazel +++ b/packages/concatjs/web_test/test/karma/BUILD.bazel @@ -14,9 +14,9 @@ load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test") load("@io_bazel_rules_webtesting//web:web.bzl", "custom_browser") -load("//packages/karma:index.bzl", "karma_web_test_suite") +load("//packages/concatjs:index.bzl", "concatjs_web_test_suite") -karma_web_test_suite( +concatjs_web_test_suite( name = "testing", srcs = glob( ["*.js"], diff --git a/packages/karma/test/karma/amd-modules.spec.js b/packages/concatjs/web_test/test/karma/amd-modules.spec.js similarity index 91% rename from packages/karma/test/karma/amd-modules.spec.js rename to packages/concatjs/web_test/test/karma/amd-modules.spec.js index e1f5135c1f..d971f9262f 100644 --- a/packages/karma/test/karma/amd-modules.spec.js +++ b/packages/concatjs/web_test/test/karma/amd-modules.spec.js @@ -1,5 +1,5 @@ define( - 'build_bazel_rules_nodejs/packages/karma/test/karma/amd-modules.spec', ['require'], require => { + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma/amd-modules.spec', ['require'], require => { describe('AMD module loading', () => { describe('unnamed amd modules', () => { it('should not warn if module is configured as static file', doneFn => { diff --git a/packages/karma/test/karma/custom_chrome.json b/packages/concatjs/web_test/test/karma/custom_chrome.json similarity index 100% rename from packages/karma/test/karma/custom_chrome.json rename to packages/concatjs/web_test/test/karma/custom_chrome.json diff --git a/packages/karma/test/karma/decrement.js b/packages/concatjs/web_test/test/karma/decrement.js similarity index 80% rename from packages/karma/test/karma/decrement.js rename to packages/concatjs/web_test/test/karma/decrement.js index fcbf2a221f..9b72703995 100644 --- a/packages/karma/test/karma/decrement.js +++ b/packages/concatjs/web_test/test/karma/decrement.js @@ -4,7 +4,7 @@ if (typeof module === 'object' && typeof module.exports === 'object') { if (v !== undefined) module.exports = v; } else if (typeof define === 'function' && define.amd) { define( - 'build_bazel_rules_nodejs/packages/karma/test/karma/decrement', ['require', 'exports'], + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma/decrement', ['require', 'exports'], factory); } })(function(require, exports) { diff --git a/packages/karma/test/karma/decrement.spec.js b/packages/concatjs/web_test/test/karma/decrement.spec.js similarity index 70% rename from packages/karma/test/karma/decrement.spec.js rename to packages/concatjs/web_test/test/karma/decrement.spec.js index ef29e320a6..afddf4927d 100644 --- a/packages/karma/test/karma/decrement.spec.js +++ b/packages/concatjs/web_test/test/karma/decrement.spec.js @@ -4,14 +4,14 @@ if (typeof module === 'object' && typeof module.exports === 'object') { if (v !== undefined) module.exports = v; } else if (typeof define === 'function' && define.amd) { define( - 'build_bazel_rules_nodejs/packages/karma/test/karma/decrement.spec', - ['require', 'exports', 'build_bazel_rules_nodejs/packages/karma/test/karma/decrement'], + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma/decrement.spec', + ['require', 'exports', 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma/decrement'], factory); } })(function(require, exports) { 'use strict'; Object.defineProperty(exports, '__esModule', {value: true}); -var decrement_1 = require('build_bazel_rules_nodejs/packages/karma/test/karma/decrement'); +var decrement_1 = require('build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma/decrement'); describe('decrementing', function() { it('should do that', function() { expect(decrement_1.decrement(1)).toBe(0); diff --git a/packages/karma/test/karma/init-test.js b/packages/concatjs/web_test/test/karma/init-test.js similarity index 70% rename from packages/karma/test/karma/init-test.js rename to packages/concatjs/web_test/test/karma/init-test.js index 7f8a73b357..bb6b2531f4 100644 --- a/packages/karma/test/karma/init-test.js +++ b/packages/concatjs/web_test/test/karma/init-test.js @@ -3,6 +3,6 @@ * to ensure that the Karma bazel rules properly include the file in the ConcatJS bundle. */ -define('build_bazel_rules_nodejs/packages/karma/test/karma/init-test', [], () => { +define('build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma/init-test', [], () => { window['__testInitialized'] = true; }); diff --git a/packages/karma/test/karma/karma.conf.js.golden b/packages/concatjs/web_test/test/karma/karma.conf.js.golden similarity index 100% rename from packages/karma/test/karma/karma.conf.js.golden rename to packages/concatjs/web_test/test/karma/karma.conf.js.golden diff --git a/packages/karma/test/karma/requirejs-config.js b/packages/concatjs/web_test/test/karma/requirejs-config.js similarity index 69% rename from packages/karma/test/karma/requirejs-config.js rename to packages/concatjs/web_test/test/karma/requirejs-config.js index 94824e99d4..e83fa1b864 100644 --- a/packages/karma/test/karma/requirejs-config.js +++ b/packages/concatjs/web_test/test/karma/requirejs-config.js @@ -2,7 +2,7 @@ require.config({ paths: { // Configure some fake AMD module that exists and should not cause a loading // error message from the "karma-requirejs" plugin which is enabled by default. - 'unnamed-module': '/base/build_bazel_rules_nodejs/packages/karma/test/karma/unnamed-amd-module', + 'unnamed-module': '/base/build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma/unnamed-amd-module', 'unnamed-module-invalid-file': '/some-invalid-file-path', } }); diff --git a/packages/karma/test/karma/test-initialized.spec.js b/packages/concatjs/web_test/test/karma/test-initialized.spec.js similarity index 81% rename from packages/karma/test/karma/test-initialized.spec.js rename to packages/concatjs/web_test/test/karma/test-initialized.spec.js index 987fbcee94..8b22e5c66a 100644 --- a/packages/karma/test/karma/test-initialized.spec.js +++ b/packages/concatjs/web_test/test/karma/test-initialized.spec.js @@ -1,4 +1,4 @@ -define('build_bazel_rules_nodejs/packages/karma/test/karma/test-initialized.spec', [], () => { +define('build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma/test-initialized.spec', [], () => { // Test that ensures that the "init-test.js" file has been included in the // ConcatJS module and was actually executed by the browser. The "init-test.js" // file is included in "static_files" and in the "deps" but should not be treated diff --git a/packages/karma/test/karma/tsconfig.json b/packages/concatjs/web_test/test/karma/tsconfig.json similarity index 100% rename from packages/karma/test/karma/tsconfig.json rename to packages/concatjs/web_test/test/karma/tsconfig.json diff --git a/packages/karma/test/karma/unnamed-amd-module.js b/packages/concatjs/web_test/test/karma/unnamed-amd-module.js similarity index 100% rename from packages/karma/test/karma/unnamed-amd-module.js rename to packages/concatjs/web_test/test/karma/unnamed-amd-module.js diff --git a/packages/karma/test/karma_typescript/BUILD.bazel b/packages/concatjs/web_test/test/karma_typescript/BUILD.bazel similarity index 95% rename from packages/karma/test/karma_typescript/BUILD.bazel rename to packages/concatjs/web_test/test/karma_typescript/BUILD.bazel index d9a2694b02..67e49d62e4 100644 --- a/packages/karma/test/karma_typescript/BUILD.bazel +++ b/packages/concatjs/web_test/test/karma_typescript/BUILD.bazel @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("//packages/concatjs:index.bzl", "concatjs_web_test_suite") load("//packages/jasmine:index.bzl", "jasmine_node_test") -load("//packages/karma:index.bzl", "karma_web_test_suite") load("//packages/typescript:index.bzl", "ts_library") ts_library( @@ -42,7 +42,7 @@ ts_library( ], ) -karma_web_test_suite( +concatjs_web_test_suite( name = "testing", srcs = [ # JS files only in srcs - eval'ed but not require'd diff --git a/packages/karma/test/karma_typescript/decrement.spec.ts b/packages/concatjs/web_test/test/karma_typescript/decrement.spec.ts similarity index 100% rename from packages/karma/test/karma_typescript/decrement.spec.ts rename to packages/concatjs/web_test/test/karma_typescript/decrement.spec.ts diff --git a/packages/karma/test/karma_typescript/decrement.ts b/packages/concatjs/web_test/test/karma_typescript/decrement.ts similarity index 100% rename from packages/karma/test/karma_typescript/decrement.ts rename to packages/concatjs/web_test/test/karma_typescript/decrement.ts diff --git a/packages/karma/test/karma_typescript/foobar.js b/packages/concatjs/web_test/test/karma_typescript/foobar.js similarity index 100% rename from packages/karma/test/karma_typescript/foobar.js rename to packages/concatjs/web_test/test/karma_typescript/foobar.js diff --git a/packages/karma/test/karma_typescript/foobar.spec.ts b/packages/concatjs/web_test/test/karma_typescript/foobar.spec.ts similarity index 100% rename from packages/karma/test/karma_typescript/foobar.spec.ts rename to packages/concatjs/web_test/test/karma_typescript/foobar.spec.ts diff --git a/packages/karma/test/karma_typescript/hello_world.spec.js b/packages/concatjs/web_test/test/karma_typescript/hello_world.spec.js similarity index 84% rename from packages/karma/test/karma_typescript/hello_world.spec.js rename to packages/concatjs/web_test/test/karma_typescript/hello_world.spec.js index 026744c1b0..198d5ed295 100644 --- a/packages/karma/test/karma_typescript/hello_world.spec.js +++ b/packages/concatjs/web_test/test/karma_typescript/hello_world.spec.js @@ -5,7 +5,7 @@ } else if (typeof define === "function" && define.amd) { define( - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/hello_world.spec', + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/hello_world.spec', ['require', 'exports'], factory); } })(function (require, exports) { diff --git a/packages/karma/test/karma_typescript/hello_world.ts b/packages/concatjs/web_test/test/karma_typescript/hello_world.ts similarity index 100% rename from packages/karma/test/karma_typescript/hello_world.ts rename to packages/concatjs/web_test/test/karma_typescript/hello_world.ts diff --git a/packages/karma/test/karma_typescript/rxjs_shims.js b/packages/concatjs/web_test/test/karma_typescript/rxjs_shims.js similarity index 100% rename from packages/karma/test/karma_typescript/rxjs_shims.js rename to packages/concatjs/web_test/test/karma_typescript/rxjs_shims.js diff --git a/packages/karma/test/karma_typescript/user_files.spec.js b/packages/concatjs/web_test/test/karma_typescript/user_files.spec.js similarity index 58% rename from packages/karma/test/karma_typescript/user_files.spec.js rename to packages/concatjs/web_test/test/karma_typescript/user_files.spec.js index a37a77e2ba..2cf0ef40eb 100644 --- a/packages/karma/test/karma_typescript/user_files.spec.js +++ b/packages/concatjs/web_test/test/karma_typescript/user_files.spec.js @@ -6,7 +6,7 @@ describe('karma_web_test_suite', () => { beforeAll(() => { config = fs.readFileSync( require.resolve( - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/testing_wrapped_test.conf.js'), + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/testing_wrapped_test.conf.js'), 'utf-8'); }); @@ -20,7 +20,7 @@ describe('karma_web_test_suite', () => { expect(files).toEqual([ 'npm/node_modules/requirejs/require.js', 'npm/node_modules/karma-requirejs/lib/adapter.js', - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/_testing_wrapped_test.amd_names_shim.js', + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/_testing_wrapped_test.amd_names_shim.js', ]); }); @@ -34,14 +34,14 @@ describe('karma_web_test_suite', () => { // These are files that Karma should load, they are not necessarily // topologically sorted. expect(files).toEqual([ - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/foobar.js', - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/hello_world.spec.js', - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/decrement.spec.js', - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/foobar.spec.js', - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/decrement.js', + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/foobar.js', + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/hello_world.spec.js', + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/decrement.spec.js', + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/foobar.spec.js', + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/decrement.js', 'npm/node_modules/rxjs/bundles/rxjs.umd.js', - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/rxjs_shims.js', - 'build_bazel_rules_nodejs/packages/karma/test/karma_typescript/hello_world.js', + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/rxjs_shims.js', + 'build_bazel_rules_nodejs/packages/concatjs/web_test/test/karma_typescript/hello_world.js', ]); }); }); diff --git a/packages/karma/test/stack_trace/BUILD.bazel b/packages/concatjs/web_test/test/stack_trace/BUILD.bazel similarity index 90% rename from packages/karma/test/stack_trace/BUILD.bazel rename to packages/concatjs/web_test/test/stack_trace/BUILD.bazel index 41d54a639d..df806404ad 100644 --- a/packages/karma/test/stack_trace/BUILD.bazel +++ b/packages/concatjs/web_test/test/stack_trace/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//packages/karma:index.bzl", "karma_web_test_suite") +load("//packages/concatjs:index.bzl", "concatjs_web_test_suite") load("//packages/typescript:index.bzl", "ts_library") ts_library( @@ -27,7 +27,7 @@ ts_library( # This is a test with failing test. This test is not directly run by CI. # The sh_test below invokes this test and checks the source mapped lines in the # stack trace. -karma_web_test_suite( +concatjs_web_test_suite( name = "karma_test", browsers = [ "@io_bazel_rules_webtesting//browsers:chromium-local", @@ -39,7 +39,7 @@ karma_web_test_suite( ], deps = [ ":test_lib", - "//packages/karma/test/stack_trace/test_folder:test_lib", + "//packages/concatjs/web_test/test/stack_trace/test_folder:test_lib", ], ) diff --git a/packages/karma/test/stack_trace/failing.spec.ts b/packages/concatjs/web_test/test/stack_trace/failing.spec.ts similarity index 100% rename from packages/karma/test/stack_trace/failing.spec.ts rename to packages/concatjs/web_test/test/stack_trace/failing.spec.ts diff --git a/packages/karma/test/stack_trace/test_folder/BUILD.bazel b/packages/concatjs/web_test/test/stack_trace/test_folder/BUILD.bazel similarity index 100% rename from packages/karma/test/stack_trace/test_folder/BUILD.bazel rename to packages/concatjs/web_test/test/stack_trace/test_folder/BUILD.bazel diff --git a/packages/karma/test/stack_trace/test_folder/hello.ts b/packages/concatjs/web_test/test/stack_trace/test_folder/hello.ts similarity index 100% rename from packages/karma/test/stack_trace/test_folder/hello.ts rename to packages/concatjs/web_test/test/stack_trace/test_folder/hello.ts diff --git a/packages/karma/test/stack_trace/test_folder/test.spec.ts b/packages/concatjs/web_test/test/stack_trace/test_folder/test.spec.ts similarity index 100% rename from packages/karma/test/stack_trace/test_folder/test.spec.ts rename to packages/concatjs/web_test/test/stack_trace/test_folder/test.spec.ts diff --git a/packages/concatjs/web_test/test/stack_trace/test_sourcemap.sh b/packages/concatjs/web_test/test/stack_trace/test_sourcemap.sh new file mode 100755 index 0000000000..bd725b215b --- /dev/null +++ b/packages/concatjs/web_test/test/stack_trace/test_sourcemap.sh @@ -0,0 +1,26 @@ +# Execute first test. +OUTPUT=$(${RUNFILES_DIR}/build_bazel_rules_nodejs/packages/concatjs/web_test/test/stack_trace/karma_test_chromium-local.sh) + +# Test whether the package relative TS path is printed in stack trace. +echo ${OUTPUT} | grep -q "(packages/concatjs/web_test/test/stack_trace/failing.spec.ts:7:17" +if [[ "$?" != "0" ]]; then + echo "Did not find '(packages/concatjs/web_test/test/stack_trace/failing.spec.ts:7:17' in Karma stack trace" + echo $OUTPUT + exit 1 +fi + +# Test whether the package relative path inside a subdirectory is printed. +echo ${OUTPUT} | grep -q "(packages/concatjs/web_test/test/stack_trace/test_folder/test.spec.ts:5:23" +if [[ "$?" != "0" ]]; then + echo "Did not find '(packages/concatjs/web_test/test/stack_trace/test_folder/test.spec.ts:5:23' in Karma stack trace" + exit 1 +fi + +# Test whether stack trace with multiple stack frames mapped get printed. +echo ${OUTPUT} | grep -q "(packages/concatjs/web_test/test/stack_trace/test_folder/hello.ts:6:8" +if [[ "$?" != "0" ]]; then + echo "Did not find '(packages/concatjs/web_test/test/stack_trace/test_folder/hello.ts:6:8' in Karma stack trace" + exit 1 +fi + +exit 0 diff --git a/packages/index.bzl b/packages/index.bzl index 8e19d3eb46..985a1db464 100644 --- a/packages/index.bzl +++ b/packages/index.bzl @@ -17,9 +17,9 @@ NPM_PACKAGES = ["@bazel/%s" % pkg for pkg in [ "angular", + "concatjs", "create", "jasmine", - "karma", "labs", "protractor", "rollup", diff --git a/packages/karma/BUILD.bazel b/packages/karma/BUILD.bazel deleted file mode 100644 index e47e07a08f..0000000000 --- a/packages/karma/BUILD.bazel +++ /dev/null @@ -1,129 +0,0 @@ -# Copyright 2019 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary", "nodejs_test") -load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "pkg_npm") -load("@build_bazel_rules_nodejs//packages/typescript:index.bzl", "ts_library") -load("@build_bazel_rules_nodejs//tools/stardoc:index.bzl", "stardoc") -load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file") - -package(default_visibility = ["//visibility:public"]) - -exports_files(["karma.conf.js"]) - -ts_library( - name = "bazel_karma_lib", - srcs = glob(["*.ts"]), - module_name = "@bazel/karma", - tsconfig = ":tsconfig.json", - deps = [ - "@npm//@types/node", - ], -) - -nodejs_binary( - name = "karma_bin", - data = [ - ":bazel_karma_lib", - "@npm//jasmine-core", - "@npm//karma", - "@npm//karma-chrome-launcher", - "@npm//karma-firefox-launcher", - "@npm//karma-jasmine", - "@npm//karma-requirejs", - "@npm//karma-sourcemap-loader", - "@npm//requirejs", - ], - entry_point = "@npm//:node_modules/karma/bin/karma", -) - -bzl_library( - name = "bzl", - testonly = True, - srcs = glob(["*.bzl"]), - deps = [ - "@build_bazel_rules_nodejs//:bzl", - "@build_bazel_rules_nodejs//internal/js_library:bzl", - "@io_bazel_rules_webtesting//web", - ], -) - -stardoc( - name = "docs", - testonly = True, - out = "index.md", - input = "index.bzl", - tags = ["fix-windows"], - deps = [":bzl"], -) - -nodejs_test( - name = "test", - data = [ - "docs_test.js", - "index.md", - ], - entry_point = ":docs_test.js", - tags = [ - "fix-windows", - ], -) - -# Ugly genrule depending on local linux environment to build the README out of skylark doc generation. -# Only referenced when we do a release. -# TODO: This ought to be possible with stardoc alone. Need to coordinate with Chris Parsons. -genrule( - name = "generate_README", - srcs = [ - "index.md", - "install.md", - ], - outs = ["README.md"], - cmd = """cat $(execpath install.md) $(execpath index.md) | sed 's/^##/\\\n##/' > $@""", - tags = ["fix-windows"], - visibility = ["//docs:__pkg__"], -) - -copy_file( - name = "npm_version_check", - src = "//internal:npm_version_check.js", - out = ":npm_version_check.js", -) - -pkg_npm( - name = "npm_package", - srcs = [ - "index.bzl", - "karma.conf.js", - "karma_web_test.bzl", - "package.bzl", - "package.json", - ], - build_file_content = """exports_files(["karma.conf.js"])""", - substitutions = { - "#@external ": "", - "//packages/karma:karma_bin": "@npm//karma/bin:karma", - }, - deps = [ - "//packages/karma:bazel_karma_lib", - ":npm_version_check", - ] + select({ - # FIXME: fix stardoc on Windows; //packages/karma:index.md generation fails with: - # ERROR: D:/b/62unjjin/external/npm_bazel_karma/BUILD.bazel:65:1: Couldn't build file - # external/npm_bazel_karma/docs.raw: Generating proto for Starlark doc for docs failed (Exit 1) - "@bazel_tools//src/conditions:windows": [], - "//conditions:default": [":generate_README"], - }), -) diff --git a/packages/karma/docs_test.js b/packages/karma/docs_test.js deleted file mode 100644 index 9cab0e0868..0000000000 --- a/packages/karma/docs_test.js +++ /dev/null @@ -1,6 +0,0 @@ -const actual = require('fs').readFileSync( - process.env['TEST_SRCDIR'] + '/build_bazel_rules_nodejs/packages/karma/index.md', - {encoding: 'utf-8'}); -if (actual.indexOf('') >= 0) { - throw new Error('Found in index.md'); -} diff --git a/packages/karma/index.bzl b/packages/karma/index.bzl deleted file mode 100644 index 5193249d65..0000000000 --- a/packages/karma/index.bzl +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Public API surface is re-exported here. -""" - -load( - ":karma_web_test.bzl", - _karma_web_test = "karma_web_test", - _karma_web_test_suite = "karma_web_test_suite", -) - -karma_web_test = _karma_web_test -karma_web_test_suite = _karma_web_test_suite -# DO NOT ADD MORE rules here unless they appear in the generated docsite. -# Run yarn stardoc to re-generate the docsite. diff --git a/packages/karma/install.md b/packages/karma/install.md deleted file mode 100644 index e8766d658c..0000000000 --- a/packages/karma/install.md +++ /dev/null @@ -1,49 +0,0 @@ -# Karma rules for Bazel - -The Karma rules run karma tests with Bazel. - -## Installation - -Add the `@bazel/karma` npm package to your `devDependencies` in `package.json`. - -Now add this to your `WORKSPACE` to install the Karma dependencies: - -```python -# Fetch transitive Bazel dependencies of @bazel/karma -load("@npm//@bazel/karma:package.bzl", "npm_bazel_karma_dependencies") -npm_bazel_karma_dependencies() -``` - -This installs the `io_bazel_rules_webtesting` repository, if you haven't installed it earlier. - -Finally, configure the rules_webtesting: - -```python -# Set up web testing, choose browsers we can test on -load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") - -web_test_repositories() - -load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories") - -browser_repositories( - chromium = True, - firefox = True, -) -``` - -## Installing with self-managed dependencies - -If you didn't use the `yarn_install` or `npm_install` rule to create an `npm` workspace, you'll have to declare a rule in your root `BUILD.bazel` file to execute karma: - -```python -# Create a karma rule to use in ts_web_test_suite karma -# attribute when using self-managed dependencies -nodejs_binary( - name = "karma/karma", - entry_point = "//:node_modules/karma/bin/karma", - # Point bazel to your node_modules to find the entry point - node_modules = ["//:node_modules"], -) -``` - diff --git a/packages/karma/package.bzl b/packages/karma/package.bzl deleted file mode 100644 index 78bd2debe0..0000000000 --- a/packages/karma/package.bzl +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Package file which defines @bazel/karma dependencies -""" - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -def npm_bazel_karma_dependencies(): - """ - Fetch our transitive dependencies. - - If the user wants to get a different version of these, they can just fetch it - from their WORKSPACE before calling this function, or not call this function at all. - """ - - # karma rules depend on the web testing rules to provision browsers. - _maybe( - http_archive, - name = "io_bazel_rules_webtesting", - sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", - urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.3/rules_webtesting.tar.gz"], - ) - -def _maybe(repo_rule, name, **kwargs): - if name not in native.existing_rules(): - repo_rule(name = name, **kwargs) diff --git a/packages/karma/package.json b/packages/karma/package.json deleted file mode 100644 index e7892640c7..0000000000 --- a/packages/karma/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@bazel/karma", - "description": "Karma rules for Bazel", - "license": "Apache-2.0", - "version": "0.0.0-PLACEHOLDER", - "repository": { - "type": "git", - "url": "https://github.com/bazelbuild/rules_nodejs.git", - "directory": "packages/karma" - }, - "bugs": { - "url": "https://github.com/bazelbuild/rules_nodejs/issues" - }, - "keywords": [ - "karma", - "bazel" - ], - "main": "./index.js", - "typings": "./index.d.ts", - "peerDependencies": { - "jasmine-core": ">=2.0.0", - "karma": ">=4.0.0", - "karma-chrome-launcher": ">=2.0.0", - "karma-firefox-launcher": ">=1.0.0", - "karma-jasmine": ">=2.0.0", - "karma-requirejs": ">=1.0.0", - "karma-sourcemap-loader": ">=0.3.0" - }, - "scripts": { - "postinstall": "node npm_version_check.js" - } -} diff --git a/packages/karma/test/stack_trace/test_sourcemap.sh b/packages/karma/test/stack_trace/test_sourcemap.sh deleted file mode 100755 index c29be13ea5..0000000000 --- a/packages/karma/test/stack_trace/test_sourcemap.sh +++ /dev/null @@ -1,26 +0,0 @@ -# Execute first test. -OUTPUT=$(${RUNFILES_DIR}/build_bazel_rules_nodejs/packages/karma/test/stack_trace/karma_test_chromium-local.sh) - -# Test whether the package relative TS path is printed in stack trace. -echo ${OUTPUT} | grep -q "(packages/karma/test/stack_trace/failing.spec.ts:7:17" -if [[ "$?" != "0" ]]; then - echo "Did not find '(packages/karma/test/stack_trace/failing.spec.ts:7:17' in Karma stack trace" - echo $OUTPUT - exit 1 -fi - -# Test whether the package relative path inside a subdirectory is printed. -echo ${OUTPUT} | grep -q "(packages/karma/test/stack_trace/test_folder/test.spec.ts:5:23" -if [[ "$?" != "0" ]]; then - echo "Did not find '(packages/karma/test/stack_trace/test_folder/test.spec.ts:5:23' in Karma stack trace" - exit 1 -fi - -# Test whether stack trace with multiple stack frames mapped get printed. -echo ${OUTPUT} | grep -q "(packages/karma/test/stack_trace/test_folder/hello.ts:6:8" -if [[ "$?" != "0" ]]; then - echo "Did not find '(packages/karma/test/stack_trace/test_folder/hello.ts:6:8' in Karma stack trace" - exit 1 -fi - -exit 0 diff --git a/packages/karma/tsconfig.json b/packages/karma/tsconfig.json deleted file mode 100644 index bce2c5c476..0000000000 --- a/packages/karma/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - // Explicitly set types settings so typescript doesn't auto-discover types. - // If all types are discovered then all types need to be included as deps - // or typescript may error out with TS2688: Cannot find type definition file for 'foo'. - "types": ["node"] - } -} - diff --git a/packages/labs/grpc_web/README.md b/packages/labs/grpc_web/README.md index 0c8f4fd3a7..5adb9e520a 100644 --- a/packages/labs/grpc_web/README.md +++ b/packages/labs/grpc_web/README.md @@ -48,7 +48,7 @@ You can now use the `test_ts_proto` target as a `dep` in other `ts_library` targ - `google-protobuf` - `grpc-web` -UMD versions of these runtime dependencies are provided by `//packages/labs/grpc_web:bootstrap_scripts` (for use within `concatjs_devserver` and `karma_web_test_suite`) +UMD versions of these runtime dependencies are provided by `//packages/labs/grpc_web:bootstrap_scripts` (for use within `concatjs_devserver` and `concatjs_web_test_suite`) See `//examples/protocol_buffers/BUILD.bazel` for an example. diff --git a/packages/labs/protobufjs/ts_proto_library.bzl b/packages/labs/protobufjs/ts_proto_library.bzl index d69b6ebce0..3dcc9aee81 100644 --- a/packages/labs/protobufjs/ts_proto_library.bzl +++ b/packages/labs/protobufjs/ts_proto_library.bzl @@ -201,17 +201,17 @@ result will be `car.d.ts`. This means our TypeScript code can just name the rule differently from the output file. The JavaScript produced by protobuf.js has a runtime dependency on a support library. -Under devmode (e.g. `concatjs_devserver`, `karma_web_test_suite`) you'll need to include these scripts +Under devmode (e.g. `concatjs_devserver`, `concatjs_web_test_suite`) you'll need to include these scripts in the `bootstrap` phase (before Require.js loads). You can use the label `@npm//@bazel/labs/protobufjs:bootstrap_scripts` to reference these scripts -in the `bootstrap` attribute of `karma_web_test_suite` or `concatjs_devserver`. +in the `bootstrap` attribute of `concatjs_web_test_suite` or `concatjs_devserver`. -To complete the example above, you could write a `karma_web_test_suite`: +To complete the example above, you could write a `concatjs_web_test_suite`: ```python -load("@npm//@bazel/karma:index.bzl", "karma_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite") -karma_web_test_suite( +concatjs_web_test_suite( name = "test", deps = ["test_lib"], bootstrap = ["@npm//@bazel/labs/protobufjs:bootstrap_scripts"], diff --git a/packages/labs/test/grpc_web/BUILD.bazel b/packages/labs/test/grpc_web/BUILD.bazel index 58e66bcf84..09ade8bdc2 100644 --- a/packages/labs/test/grpc_web/BUILD.bazel +++ b/packages/labs/test/grpc_web/BUILD.bazel @@ -1,5 +1,5 @@ +load("//packages/concatjs:index.bzl", "concatjs_web_test_suite") load("//packages/jasmine:index.bzl", "jasmine_node_test") -load("//packages/karma:index.bzl", "karma_web_test_suite") load("//packages/rollup:index.bzl", "rollup_bundle") load("//packages/typescript:index.bzl", "ts_library") @@ -38,7 +38,7 @@ ts_library( ], ) -karma_web_test_suite( +concatjs_web_test_suite( name = "proto_with_deps_test_suite", srcs = [ "//packages/labs/grpc_web:bootstrap_scripts", @@ -64,7 +64,7 @@ ts_library( ], ) -karma_web_test_suite( +concatjs_web_test_suite( name = "pizza_service_proto_test_suite", srcs = [ "//packages/labs/grpc_web:bootstrap_scripts", diff --git a/packages/protractor/protractor.conf.js b/packages/protractor/protractor.conf.js index 6726f5610c..53f3472e37 100644 --- a/packages/protractor/protractor.conf.js +++ b/packages/protractor/protractor.conf.js @@ -100,7 +100,7 @@ if (onPreparePath) { } // Override the user's base protractor configuration as appropriate based on the -// karma_web_test_suite & rules_webtesting WEB_TEST_METADATA attributes +// concatjs_web_test_suite & rules_webtesting WEB_TEST_METADATA attributes setConf(conf, 'framework', 'jasmine2', 'is set to jasmine2'); const specs = @@ -109,7 +109,7 @@ const specs = setConf(conf, 'specs', specs, 'are determined by the srcs and deps attribute'); // WEB_TEST_METADATA is configured in rules_webtesting based on value -// of the browsers attribute passed to karma_web_test_suite +// of the browsers attribute passed to concatjs_web_test_suite // We setup the protractor configuration based on the values in this object if (process.env['WEB_TEST_METADATA']) { const webTestMetadata = require(process.env['WEB_TEST_METADATA']); diff --git a/packages/protractor/protractor_web_test.bzl b/packages/protractor/protractor_web_test.bzl index 7639822a1f..f7b7dcc149 100644 --- a/packages/protractor/protractor_web_test.bzl +++ b/packages/protractor/protractor_web_test.bzl @@ -299,8 +299,8 @@ def protractor_web_test_suite( browsers: A sequence of labels specifying the browsers to use. web_test_data: Data dependencies for the wrapper web_test targets. wrapped_test_tags: A list of test tag strings to use for the wrapped - karma_web_test target. - **kwargs: Arguments for the wrapped karma_web_test target. + concatjs_web_test target. + **kwargs: Arguments for the wrapped concatjs_web_test target. """ # Common attributes @@ -327,7 +327,7 @@ def protractor_web_test_suite( if not "native" in tags: tags = tags + ["native"] - # The wrapped `karma_web_test` target + # The wrapped `concatjs_web_test` target wrapped_test_name = name + "_wrapped_test" protractor_web_test( name = wrapped_test_name, From c1b19b7ae0aa577609ed736a05af22f4c9ccd9f2 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 1 Dec 2020 15:31:10 -0800 Subject: [PATCH 2/2] concatjs_web back to karma_web --- examples/angular/WORKSPACE | 2 +- .../angular/src/app/hello-world/BUILD.bazel | 4 +-- .../src/app/hello-world/BUILD.bazel | 4 +-- examples/protocol_buffers/BUILD.bazel | 4 +-- examples/web_testing/BUILD.bazel | 6 ++-- packages/concatjs/BUILD.bazel | 3 ++ packages/concatjs/_README.md | 8 ++--- packages/concatjs/index.bzl | 10 +++--- packages/concatjs/index.docs.bzl | 7 ++++ packages/concatjs/web_test/BUILD.bazel | 2 +- packages/concatjs/web_test/karma.conf.js | 10 +++--- ...ncatjs_web_test.bzl => karma_web_test.bzl} | 36 +++++++++---------- .../concatjs/web_test/test/karma/BUILD.bazel | 4 +-- .../test/karma_typescript/BUILD.bazel | 4 +-- .../web_test/test/stack_trace/BUILD.bazel | 4 +-- packages/labs/grpc_web/README.md | 2 +- packages/labs/protobufjs/ts_proto_library.bzl | 10 +++--- packages/labs/test/grpc_web/BUILD.bazel | 6 ++-- packages/protractor/protractor.conf.js | 4 +-- packages/protractor/protractor_web_test.bzl | 6 ++-- 20 files changed, 73 insertions(+), 63 deletions(-) rename packages/concatjs/web_test/{concatjs_web_test.bzl => karma_web_test.bzl} (95%) diff --git a/examples/angular/WORKSPACE b/examples/angular/WORKSPACE index 64ad073972..b743247c61 100644 --- a/examples/angular/WORKSPACE +++ b/examples/angular/WORKSPACE @@ -59,7 +59,7 @@ load("@npm//@bazel/protractor:package.bzl", "npm_bazel_protractor_dependencies") npm_bazel_protractor_dependencies() -# Load concatjs_web_test dependencies +# Load karma_web_test dependencies http_archive( name = "io_bazel_rules_webtesting", sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", diff --git a/examples/angular/src/app/hello-world/BUILD.bazel b/examples/angular/src/app/hello-world/BUILD.bazel index 488f10d4a4..c5ae983a2d 100644 --- a/examples/angular/src/app/hello-world/BUILD.bazel +++ b/examples/angular/src/app/hello-world/BUILD.bazel @@ -1,5 +1,5 @@ load("@io_bazel_rules_sass//:defs.bzl", "multi_sass_binary") -load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite") load("@npm//@bazel/typescript:index.bzl", "ts_library") load("//tools:angular_ts_library.bzl", "ng_ts_library") @@ -49,7 +49,7 @@ ts_library( ], ) -concatjs_web_test_suite( +karma_web_test_suite( name = "test", srcs = [ # We are manaully adding the bazel generated named-UMD date-fns bundle here as diff --git a/examples/angular_view_engine/src/app/hello-world/BUILD.bazel b/examples/angular_view_engine/src/app/hello-world/BUILD.bazel index 8f5ebee668..929788153b 100644 --- a/examples/angular_view_engine/src/app/hello-world/BUILD.bazel +++ b/examples/angular_view_engine/src/app/hello-world/BUILD.bazel @@ -1,5 +1,5 @@ load("@io_bazel_rules_sass//:defs.bzl", "sass_binary") -load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite") load("@npm//@bazel/typescript:index.bzl", "ts_library") load("@npm_angular_bazel//:index.bzl", "ng_module") @@ -59,7 +59,7 @@ ts_library( ], ) -concatjs_web_test_suite( +karma_web_test_suite( name = "test", srcs = [ # We are manaully adding the bazel generated named-UMD date-fns bundle here as diff --git a/examples/protocol_buffers/BUILD.bazel b/examples/protocol_buffers/BUILD.bazel index c0740a2360..523438131b 100644 --- a/examples/protocol_buffers/BUILD.bazel +++ b/examples/protocol_buffers/BUILD.bazel @@ -1,4 +1,4 @@ -load("@npm//@bazel/concatjs:index.bzl", "concatjs_devserver", "concatjs_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "concatjs_devserver", "karma_web_test_suite") load("@npm//@bazel/labs:index.bzl", "ts_proto_library") load("@npm//@bazel/protractor:index.bzl", "protractor_web_test_suite") load("@npm//@bazel/rollup:index.bzl", "rollup_bundle") @@ -53,7 +53,7 @@ ts_library( ], ) -concatjs_web_test_suite( +karma_web_test_suite( name = "test", srcs = [ "@npm//@bazel/labs/grpc_web:bootstrap_scripts", diff --git a/examples/web_testing/BUILD.bazel b/examples/web_testing/BUILD.bazel index e43ea95d75..6ba4372374 100644 --- a/examples/web_testing/BUILD.bazel +++ b/examples/web_testing/BUILD.bazel @@ -1,4 +1,4 @@ -load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite") load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_library") ts_library( @@ -35,7 +35,7 @@ ts_library( ], ) -concatjs_web_test_suite( +karma_web_test_suite( name = "config_test", browsers = [ "@io_bazel_rules_webtesting//browsers:chromium-local", @@ -55,7 +55,7 @@ concatjs_web_test_suite( ], ) -concatjs_web_test_suite( +karma_web_test_suite( name = "no_config_test", browsers = [ "@io_bazel_rules_webtesting//browsers:chromium-local", diff --git a/packages/concatjs/BUILD.bazel b/packages/concatjs/BUILD.bazel index 91babea3f6..2b487d2899 100644 --- a/packages/concatjs/BUILD.bazel +++ b/packages/concatjs/BUILD.bazel @@ -42,6 +42,7 @@ js_library( bzl_library( name = "bzl", + testonly = True, srcs = glob(["*.bzl"]) + [ # Work-around since we don't have and don't wnat a bzl_library in the generated # @nodejs//:BUILD.bazel file @@ -49,6 +50,7 @@ bzl_library( ], deps = [ "//packages/concatjs/devserver:bzl", + "//packages/concatjs/web_test:bzl", "@build_bazel_rules_nodejs//:bzl", "@build_bazel_rules_nodejs//internal/common:bzl", "@build_bazel_rules_nodejs//internal/node:bzl", @@ -57,6 +59,7 @@ bzl_library( stardoc( name = "docs", + testonly = True, out = "index.md", input = "index.docs.bzl", tags = ["fix-windows"], diff --git a/packages/concatjs/_README.md b/packages/concatjs/_README.md index b52362a188..f9b922abec 100644 --- a/packages/concatjs/_README.md +++ b/packages/concatjs/_README.md @@ -19,7 +19,7 @@ Most packages do not ship with this format, so in order to use concatjs tooling, This is at the core of how Google does JavaScript development. So Bazel rules that originated in Google's codebase have affordances for concatjs. For example `ts_library` produces named AMD modules in its "devmode" output, and -`concatjs_web_test` expects to bundle inputs using concatjs. +`karma_web_test` expects to bundle inputs using concatjs. ## Serving JS in development mode under Bazel @@ -78,13 +78,13 @@ finishes. ## Testing with Karma -The `concatjs_web_test` rule runs karma tests with Bazel. +The `karma_web_test` rule runs karma tests with Bazel. It depends on rules_webtesting, so you need to add this to your `WORKSPACE` if you use the web testing rules in `@bazel/concatjs`: ```python -# Fetch transitive Bazel dependencies of concatjs_web_test +# Fetch transitive Bazel dependencies of karma_web_test http_archive( name = "io_bazel_rules_webtesting", sha256 = "9bb461d5ef08e850025480bab185fd269242d4e533bca75bfb748001ceb343c3", @@ -109,7 +109,7 @@ browser_repositories( If you didn't use the `yarn_install` or `npm_install` rule to create an `npm` workspace, you'll have to declare a rule in your root `BUILD.bazel` file to execute karma: ```python -# Create a karma rule to use in concatjs_web_test_suite karma +# Create a karma rule to use in karma_web_test_suite karma # attribute when using self-managed dependencies nodejs_binary( name = "karma/karma", diff --git a/packages/concatjs/index.bzl b/packages/concatjs/index.bzl index 1de0f9807d..220c2d2285 100644 --- a/packages/concatjs/index.bzl +++ b/packages/concatjs/index.bzl @@ -19,11 +19,11 @@ Users should not load files under "/internal" load("//packages/concatjs/devserver:concatjs_devserver.bzl", _concatjs_devserver = "concatjs_devserver_macro") load( - "//packages/concatjs/web_test:concatjs_web_test.bzl", - _concatjs_web_test = "concatjs_web_test", - _concatjs_web_test_suite = "concatjs_web_test_suite", + "//packages/concatjs/web_test:karma_web_test.bzl", + _karma_web_test = "karma_web_test", + _karma_web_test_suite = "karma_web_test_suite", ) -concatjs_web_test = _concatjs_web_test -concatjs_web_test_suite = _concatjs_web_test_suite +karma_web_test = _karma_web_test +karma_web_test_suite = _karma_web_test_suite concatjs_devserver = _concatjs_devserver diff --git a/packages/concatjs/index.docs.bzl b/packages/concatjs/index.docs.bzl index 4d716a3d27..6436a241bd 100644 --- a/packages/concatjs/index.docs.bzl +++ b/packages/concatjs/index.docs.bzl @@ -19,7 +19,14 @@ So this is a copy of index.bzl with macro indirection removed. """ load("//packages/concatjs/devserver:concatjs_devserver.bzl", _concatjs_devserver = "concatjs_devserver") +load( + "//packages/concatjs/web_test:karma_web_test.bzl", + _karma_web_test = "karma_web_test", + _karma_web_test_suite = "karma_web_test_suite", +) +karma_web_test = _karma_web_test +karma_web_test_suite = _karma_web_test_suite concatjs_devserver = _concatjs_devserver # DO NOT ADD MORE rules here unless they appear in the generated docsite. # Run yarn stardoc to re-generate the docsite. diff --git a/packages/concatjs/web_test/BUILD.bazel b/packages/concatjs/web_test/BUILD.bazel index 4b141795e6..d8f077c32c 100644 --- a/packages/concatjs/web_test/BUILD.bazel +++ b/packages/concatjs/web_test/BUILD.bazel @@ -50,7 +50,7 @@ filegroup( name = "package_contents", srcs = [ "BUILD.bazel", - "concatjs_web_test.bzl", "karma.conf.js", + "karma_web_test.bzl", ], ) diff --git a/packages/concatjs/web_test/karma.conf.js b/packages/concatjs/web_test/karma.conf.js index df9057a977..d06d731401 100644 --- a/packages/concatjs/web_test/karma.conf.js +++ b/packages/concatjs/web_test/karma.conf.js @@ -137,8 +137,8 @@ try { } /** - * Configuration settings for karma under Bazel common to concatjs_web_test - * and concatjs_web_test_suite. + * Configuration settings for karma under Bazel common to karma_web_test + * and karma_web_test_suite. */ function configureBazelConfig(config, conf) { // list of karma plugins @@ -279,7 +279,7 @@ try { } /** - * Configure karma under concatjs_web_test_suite. + * Configure karma under karma_web_test_suite. * `browsers` and `customLaunchers` are setup by Bazel. */ function configureTsWebTestSuiteConfig(conf) { @@ -287,7 +287,7 @@ try { // of the browsers attribute passed to karms_web_test_suite // We setup the karma configuration based on the values in this object if (!process.env['WEB_TEST_METADATA']) { - // This is a concatjs_web_test rule since there is no WEB_TEST_METADATA + // This is a karma_web_test rule since there is no WEB_TEST_METADATA return; } @@ -369,7 +369,7 @@ try { function configureTsWebTestConfig(conf) { if (process.env['WEB_TEST_METADATA']) { - // This is a concatjs_web_test_suite rule since there is a WEB_TEST_METADATA + // This is a karma_web_test_suite rule since there is a WEB_TEST_METADATA return; } diff --git a/packages/concatjs/web_test/concatjs_web_test.bzl b/packages/concatjs/web_test/karma_web_test.bzl similarity index 95% rename from packages/concatjs/web_test/concatjs_web_test.bzl rename to packages/concatjs/web_test/karma_web_test.bzl index cc4b7db21f..afb39c177a 100644 --- a/packages/concatjs/web_test/concatjs_web_test.bzl +++ b/packages/concatjs/web_test/karma_web_test.bzl @@ -31,7 +31,7 @@ KARMA_PEER_DEPS = [ "@npm//requirejs", ] -CONCATJS_WEB_TEST_ATTRS = { +KARMA_WEB_TEST_ATTRS = { "bootstrap": attr.label_list( doc = """JavaScript files to include *before* the module loader (require.js). For example, you can include Reflect,js for TypeScript decorator metadata reflection, @@ -207,7 +207,7 @@ def _write_karma_config(ctx, files, amd_names_shim): return configuration -def _concatjs_web_test_impl(ctx): +def _karma_web_test_impl(ctx): files_depsets = [depset(ctx.files.srcs)] for dep in ctx.attr.deps + ctx.attr.runtime_deps: if JSNamedModuleInfo in dep: @@ -316,17 +316,17 @@ ${{COMMAND}} executable = ctx.outputs.executable, )] -_concatjs_web_test = rule( - implementation = _concatjs_web_test_impl, +_karma_web_test = rule( + implementation = _karma_web_test_impl, test = True, executable = True, - attrs = CONCATJS_WEB_TEST_ATTRS, + attrs = KARMA_WEB_TEST_ATTRS, outputs = { "configuration": "%{name}.conf.js", }, ) -def concatjs_web_test( +def karma_web_test( srcs = [], deps = [], data = [], @@ -361,7 +361,7 @@ def concatjs_web_test( By default we open a headless Chrome. To use a real Chrome browser window, you can pass `--define DISPLAY=true` to Bazel, along with `configuration_env_vars = ["DISPLAY"]` on - `concatjs_web_test`. + `karma_web_test`. Args: srcs: A list of JavaScript test files @@ -385,11 +385,11 @@ def concatjs_web_test( certain attributes of this configuration file. Attributes that are overridden will be outputted to the test log. tags: Standard Bazel tags, this macro adds tags for ibazel support - peer_deps: list of peer npm deps required by concatjs_web_test - **kwargs: Passed through to `concatjs_web_test` + peer_deps: list of peer npm deps required by karma_web_test + **kwargs: Passed through to `karma_web_test` """ - _concatjs_web_test( + _karma_web_test( srcs = srcs, deps = deps + peer_deps, data = data, @@ -405,16 +405,16 @@ def concatjs_web_test( **kwargs ) -def concatjs_web_test_suite( +def karma_web_test_suite( name, browsers = None, web_test_data = [], wrapped_test_tags = list(DEFAULT_WRAPPED_TEST_TAGS), **kwargs): - """Defines a test_suite of web_test targets that wrap a concatjs_web_test target. + """Defines a test_suite of web_test targets that wrap a karma_web_test target. - This macro accepts all parameters in concatjs_web_test and adds additional parameters - for the suite. See concatjs_web_test docs for all concatjs_web_test. + This macro accepts all parameters in karma_web_test and adds additional parameters + for the suite. See karma_web_test docs for all karma_web_test. The wrapping macro is `web_test_suite` which comes from rules_websting: https://github.com/bazelbuild/rules_webtesting/blob/master/web/web.bzl. @@ -424,8 +424,8 @@ def concatjs_web_test_suite( browsers: A sequence of labels specifying the browsers to use. web_test_data: Data dependencies for the wrapper web_test targets. wrapped_test_tags: A list of test tag strings to use for the wrapped - concatjs_web_test target. - **kwargs: Arguments for the wrapped concatjs_web_test target. + karma_web_test target. + **kwargs: Arguments for the wrapped karma_web_test target. """ # Common attributes @@ -452,9 +452,9 @@ def concatjs_web_test_suite( if not "native" in tags: tags = tags + ["native"] - # The wrapped `concatjs_web_test` target + # The wrapped `karma_web_test` target wrapped_test_name = name + "_wrapped_test" - concatjs_web_test( + karma_web_test( name = wrapped_test_name, args = args, flaky = flaky, diff --git a/packages/concatjs/web_test/test/karma/BUILD.bazel b/packages/concatjs/web_test/test/karma/BUILD.bazel index e3d4379e0a..e56ddd472f 100644 --- a/packages/concatjs/web_test/test/karma/BUILD.bazel +++ b/packages/concatjs/web_test/test/karma/BUILD.bazel @@ -14,9 +14,9 @@ load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test") load("@io_bazel_rules_webtesting//web:web.bzl", "custom_browser") -load("//packages/concatjs:index.bzl", "concatjs_web_test_suite") +load("//packages/concatjs:index.bzl", "karma_web_test_suite") -concatjs_web_test_suite( +karma_web_test_suite( name = "testing", srcs = glob( ["*.js"], diff --git a/packages/concatjs/web_test/test/karma_typescript/BUILD.bazel b/packages/concatjs/web_test/test/karma_typescript/BUILD.bazel index 67e49d62e4..60fbe139be 100644 --- a/packages/concatjs/web_test/test/karma_typescript/BUILD.bazel +++ b/packages/concatjs/web_test/test/karma_typescript/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//packages/concatjs:index.bzl", "concatjs_web_test_suite") +load("//packages/concatjs:index.bzl", "karma_web_test_suite") load("//packages/jasmine:index.bzl", "jasmine_node_test") load("//packages/typescript:index.bzl", "ts_library") @@ -42,7 +42,7 @@ ts_library( ], ) -concatjs_web_test_suite( +karma_web_test_suite( name = "testing", srcs = [ # JS files only in srcs - eval'ed but not require'd diff --git a/packages/concatjs/web_test/test/stack_trace/BUILD.bazel b/packages/concatjs/web_test/test/stack_trace/BUILD.bazel index df806404ad..c5a3e0336f 100644 --- a/packages/concatjs/web_test/test/stack_trace/BUILD.bazel +++ b/packages/concatjs/web_test/test/stack_trace/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//packages/concatjs:index.bzl", "concatjs_web_test_suite") +load("//packages/concatjs:index.bzl", "karma_web_test_suite") load("//packages/typescript:index.bzl", "ts_library") ts_library( @@ -27,7 +27,7 @@ ts_library( # This is a test with failing test. This test is not directly run by CI. # The sh_test below invokes this test and checks the source mapped lines in the # stack trace. -concatjs_web_test_suite( +karma_web_test_suite( name = "karma_test", browsers = [ "@io_bazel_rules_webtesting//browsers:chromium-local", diff --git a/packages/labs/grpc_web/README.md b/packages/labs/grpc_web/README.md index 5adb9e520a..0c8f4fd3a7 100644 --- a/packages/labs/grpc_web/README.md +++ b/packages/labs/grpc_web/README.md @@ -48,7 +48,7 @@ You can now use the `test_ts_proto` target as a `dep` in other `ts_library` targ - `google-protobuf` - `grpc-web` -UMD versions of these runtime dependencies are provided by `//packages/labs/grpc_web:bootstrap_scripts` (for use within `concatjs_devserver` and `concatjs_web_test_suite`) +UMD versions of these runtime dependencies are provided by `//packages/labs/grpc_web:bootstrap_scripts` (for use within `concatjs_devserver` and `karma_web_test_suite`) See `//examples/protocol_buffers/BUILD.bazel` for an example. diff --git a/packages/labs/protobufjs/ts_proto_library.bzl b/packages/labs/protobufjs/ts_proto_library.bzl index 3dcc9aee81..36523458e1 100644 --- a/packages/labs/protobufjs/ts_proto_library.bzl +++ b/packages/labs/protobufjs/ts_proto_library.bzl @@ -201,17 +201,17 @@ result will be `car.d.ts`. This means our TypeScript code can just name the rule differently from the output file. The JavaScript produced by protobuf.js has a runtime dependency on a support library. -Under devmode (e.g. `concatjs_devserver`, `concatjs_web_test_suite`) you'll need to include these scripts +Under devmode (e.g. `concatjs_devserver`, `karma_web_test_suite`) you'll need to include these scripts in the `bootstrap` phase (before Require.js loads). You can use the label `@npm//@bazel/labs/protobufjs:bootstrap_scripts` to reference these scripts -in the `bootstrap` attribute of `concatjs_web_test_suite` or `concatjs_devserver`. +in the `bootstrap` attribute of `karma_web_test_suite` or `concatjs_devserver`. -To complete the example above, you could write a `concatjs_web_test_suite`: +To complete the example above, you could write a `karma_web_test_suite`: ```python -load("@npm//@bazel/concatjs:index.bzl", "concatjs_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite") -concatjs_web_test_suite( +karma_web_test_suite( name = "test", deps = ["test_lib"], bootstrap = ["@npm//@bazel/labs/protobufjs:bootstrap_scripts"], diff --git a/packages/labs/test/grpc_web/BUILD.bazel b/packages/labs/test/grpc_web/BUILD.bazel index 09ade8bdc2..d69bde0f8d 100644 --- a/packages/labs/test/grpc_web/BUILD.bazel +++ b/packages/labs/test/grpc_web/BUILD.bazel @@ -1,4 +1,4 @@ -load("//packages/concatjs:index.bzl", "concatjs_web_test_suite") +load("//packages/concatjs:index.bzl", "karma_web_test_suite") load("//packages/jasmine:index.bzl", "jasmine_node_test") load("//packages/rollup:index.bzl", "rollup_bundle") load("//packages/typescript:index.bzl", "ts_library") @@ -38,7 +38,7 @@ ts_library( ], ) -concatjs_web_test_suite( +karma_web_test_suite( name = "proto_with_deps_test_suite", srcs = [ "//packages/labs/grpc_web:bootstrap_scripts", @@ -64,7 +64,7 @@ ts_library( ], ) -concatjs_web_test_suite( +karma_web_test_suite( name = "pizza_service_proto_test_suite", srcs = [ "//packages/labs/grpc_web:bootstrap_scripts", diff --git a/packages/protractor/protractor.conf.js b/packages/protractor/protractor.conf.js index 53f3472e37..6726f5610c 100644 --- a/packages/protractor/protractor.conf.js +++ b/packages/protractor/protractor.conf.js @@ -100,7 +100,7 @@ if (onPreparePath) { } // Override the user's base protractor configuration as appropriate based on the -// concatjs_web_test_suite & rules_webtesting WEB_TEST_METADATA attributes +// karma_web_test_suite & rules_webtesting WEB_TEST_METADATA attributes setConf(conf, 'framework', 'jasmine2', 'is set to jasmine2'); const specs = @@ -109,7 +109,7 @@ const specs = setConf(conf, 'specs', specs, 'are determined by the srcs and deps attribute'); // WEB_TEST_METADATA is configured in rules_webtesting based on value -// of the browsers attribute passed to concatjs_web_test_suite +// of the browsers attribute passed to karma_web_test_suite // We setup the protractor configuration based on the values in this object if (process.env['WEB_TEST_METADATA']) { const webTestMetadata = require(process.env['WEB_TEST_METADATA']); diff --git a/packages/protractor/protractor_web_test.bzl b/packages/protractor/protractor_web_test.bzl index f7b7dcc149..7639822a1f 100644 --- a/packages/protractor/protractor_web_test.bzl +++ b/packages/protractor/protractor_web_test.bzl @@ -299,8 +299,8 @@ def protractor_web_test_suite( browsers: A sequence of labels specifying the browsers to use. web_test_data: Data dependencies for the wrapper web_test targets. wrapped_test_tags: A list of test tag strings to use for the wrapped - concatjs_web_test target. - **kwargs: Arguments for the wrapped concatjs_web_test target. + karma_web_test target. + **kwargs: Arguments for the wrapped karma_web_test target. """ # Common attributes @@ -327,7 +327,7 @@ def protractor_web_test_suite( if not "native" in tags: tags = tags + ["native"] - # The wrapped `concatjs_web_test` target + # The wrapped `karma_web_test` target wrapped_test_name = name + "_wrapped_test" protractor_web_test( name = wrapped_test_name,