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..b743247c61 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 karma_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..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/karma:index.bzl", "karma_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") 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..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/karma:index.bzl", "karma_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") 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..523438131b 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", "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") 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..6ba4372374 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", "karma_web_test_suite") load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_library") ts_library( 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..2b487d2899 100644 --- a/packages/concatjs/BUILD.bazel +++ b/packages/concatjs/BUILD.bazel @@ -13,12 +13,36 @@ # 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", + 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 @@ -26,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", @@ -34,6 +59,7 @@ bzl_library( stardoc( name = "docs", + testonly = True, out = "index.md", input = "index.docs.bzl", tags = ["fix-windows"], @@ -68,16 +94,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..f9b922abec 100644 --- a/packages/concatjs/_README.md +++ b/packages/concatjs/_README.md @@ -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 `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 karma_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 karma_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..220c2d2285 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: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 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/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..d8f077c32c --- /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", + "karma.conf.js", + "karma_web_test.bzl", + ], +) diff --git a/packages/karma/karma.conf.js b/packages/concatjs/web_test/karma.conf.js similarity index 99% rename from packages/karma/karma.conf.js rename to packages/concatjs/web_test/karma.conf.js index de39889783..d06d731401 100644 --- a/packages/karma/karma.conf.js +++ b/packages/concatjs/web_test/karma.conf.js @@ -144,7 +144,7 @@ try { // 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'), diff --git a/packages/karma/karma_web_test.bzl b/packages/concatjs/web_test/karma_web_test.bzl similarity index 99% rename from packages/karma/karma_web_test.bzl rename to packages/concatjs/web_test/karma_web_test.bzl index 3c2faf10e4..afb39c177a 100644 --- a/packages/karma/karma_web_test.bzl +++ b/packages/concatjs/web_test/karma_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", @@ -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, ), } diff --git a/packages/karma/test/karma/BUILD.bazel b/packages/concatjs/web_test/test/karma/BUILD.bazel similarity index 96% rename from packages/karma/test/karma/BUILD.bazel rename to packages/concatjs/web_test/test/karma/BUILD.bazel index aee67d3354..e56ddd472f 100644 --- a/packages/karma/test/karma/BUILD.bazel +++ b/packages/concatjs/web_test/test/karma/BUILD.bazel @@ -14,7 +14,7 @@ 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", "karma_web_test_suite") karma_web_test_suite( name = "testing", 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 97% rename from packages/karma/test/karma_typescript/BUILD.bazel rename to packages/concatjs/web_test/test/karma_typescript/BUILD.bazel index d9a2694b02..60fbe139be 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", "karma_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( 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 91% rename from packages/karma/test/stack_trace/BUILD.bazel rename to packages/concatjs/web_test/test/stack_trace/BUILD.bazel index 41d54a639d..c5a3e0336f 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", "karma_web_test_suite") load("//packages/typescript:index.bzl", "ts_library") ts_library( @@ -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/protobufjs/ts_proto_library.bzl b/packages/labs/protobufjs/ts_proto_library.bzl index d69b6ebce0..36523458e1 100644 --- a/packages/labs/protobufjs/ts_proto_library.bzl +++ b/packages/labs/protobufjs/ts_proto_library.bzl @@ -209,7 +209,7 @@ in the `bootstrap` attribute of `karma_web_test_suite` or `concatjs_devserver`. To complete the example above, you could write a `karma_web_test_suite`: ```python -load("@npm//@bazel/karma:index.bzl", "karma_web_test_suite") +load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite") karma_web_test_suite( name = "test", diff --git a/packages/labs/test/grpc_web/BUILD.bazel b/packages/labs/test/grpc_web/BUILD.bazel index 58e66bcf84..d69bde0f8d 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", "karma_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")