Skip to content

Commit

Permalink
feat(cypress): remove browiserify preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Muller authored and Alex Eagle committed Nov 10, 2020
1 parent 9745e66 commit 98ee87d
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 2,957 deletions.
6 changes: 3 additions & 3 deletions docs/Cypress.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/Cypress.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ The Cypress rules run tests under the Cypress e2e testing framework with Bazel.

## Installation

Add `@bazel/cypress`, `cypress` and `@cypress/browserify-preprocessor` npm packages to your `devDependencies` in `package.json`.
Add `@bazel/cypress` and `cypress` npm packages to your `devDependencies` in `package.json`.

```
npm install --save-dev @bazel/cypress cypress @cypress/browserify-preprocessor
npm install --save-dev @bazel/cypress cypress
```
or using yarn
```
yarn add -D @bazel/cypress cypress @cypress/browserify-preprocessor
yarn add -D @bazel/cypress cypress
```

Then, load and invoke `cypress_repository` within your `WORKSPACE` file.
Expand Down
3 changes: 1 addition & 2 deletions examples/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"@bazel/cypress": "^2.2.2",
"@bazel/ibazel": "^0.13.2",
"@bazel/typescript": "^2.2.2",
"@cypress/browserify-preprocessor": "^3.0.0",
"@types/node": "14.0.13",
"cypress": "^4.8.0",
"rxjs": "^6.5.2",
Expand All @@ -18,4 +17,4 @@
"scripts": {
"test": "bazel test //..."
}
}
}
1 change: 0 additions & 1 deletion packages/cypress/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ pkg_npm(
"@build_bazel_rules_nodejs//packages/cypress:internal/plugins/base.js": "TEMPLATED_node_modules_workspace_name//@bazel/cypress:internal/plugins/base.js",
"@build_bazel_rules_nodejs//packages/cypress:internal/plugins/index.template.js": "TEMPLATED_node_modules_workspace_name//@bazel/cypress:internal/plugins/index.template.js",
"@build_bazel_rules_nodejs//packages/cypress:internal/run-cypress.js": "TEMPLATED_node_modules_workspace_name//@bazel/cypress:internal/run-cypress.js",
"\\${cwd}/../cypress_deps/node_modules/@cypress/browserify-preprocessor/index": "@cypress/browserify-preprocessor",
},
deps = [
":npm_version_check",
Expand Down
6 changes: 3 additions & 3 deletions packages/cypress/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ The Cypress rules run tests under the Cypress e2e testing framework with Bazel.

## Installation

Add `@bazel/cypress`, `cypress` and `@cypress/browserify-preprocessor` npm packages to your `devDependencies` in `package.json`.
Add `@bazel/cypress` and `cypress` npm packages to your `devDependencies` in `package.json`.

```
npm install --save-dev @bazel/cypress cypress @cypress/browserify-preprocessor
npm install --save-dev @bazel/cypress cypress
```
or using yarn
```
yarn add -D @bazel/cypress cypress @cypress/browserify-preprocessor
yarn add -D @bazel/cypress cypress
```

Then, load and invoke `cypress_repository` within your `WORKSPACE` file.
Expand Down
10 changes: 10 additions & 0 deletions packages/cypress/internal/cypress_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def _cypress_repository_impl(repository_ctx):
{},
)

repository_ctx.template(
"plugins/base.js",
repository_ctx.path(repository_ctx.attr._base_plugin),
{},
)

repository_ctx.template(
"packages/cypress/internal/cypress_web_test.bzl",
repository_ctx.path(repository_ctx.attr._cypress_web_test),
Expand Down Expand Up @@ -59,6 +65,10 @@ cypress_repository = repository_rule(
default = True,
doc = "If stdout and stderr should be printed to the terminal",
),
"_base_plugin": attr.label(
allow_single_file = True,
default = "//packages/cypress:internal/plugins/base.js",
),
"_cypress_web_test": attr.label(
allow_single_file = True,
default = "//packages/cypress:internal/template.cypress_web_test.bzl",
Expand Down
12 changes: 1 addition & 11 deletions packages/cypress/internal/plugins/index.template.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {join, normalize} = require('path');
const {join} = require('path');

const basePluginShortPath = 'TEMPLATED_pluginsFile';
const integrationFileShortPaths = TEMPLATED_integrationFileShortPaths;
Expand All @@ -7,9 +7,6 @@ const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
const basePlugin = require(runfiles.resolveWorkspaceRelative(basePluginShortPath));
const cwd = process.cwd();

const browserifyFactory = require(normalize(`TEMPLATED_@cypress/browserify-preprocessor`));
const browserify = browserifyFactory(browserifyFactory.defaultOptions);

module.exports = (on, config) => {
// Set env variables needed usually set by for `bazel test` invocations
// (they are not set automatically for `bazel run`).
Expand All @@ -25,13 +22,6 @@ module.exports = (on, config) => {
config.screenshotsFolder = process.env['TEST_UNDECLARED_OUTPUTS_DIR'] || process.env.RUNFILES_DIR;
config.videosFolder = process.env['TEST_UNDECLARED_OUTPUTS_DIR'] || process.env.RUNFILES_DIR;

// Set file preprocessing output path to writable directory.
on('file:preprocessor', (file) => {
file.outputPath =
join(process.env['TEST_TMPDIR'], file.outputPath.split('/bundles/').slice(1).join());
return browserify(file);
});

// Load in the user's cypress plugin
return basePlugin(on, config);
};
9 changes: 1 addition & 8 deletions packages/cypress/internal/template.cypress_web_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def _cypress_plugin_impl(ctx):
output = ctx.outputs.plugin,
template = ctx.file._plugin_template,
substitutions = {
"TEMPLATED_@cypress/browserify-preprocessor": "${cwd}/../cypress_deps/node_modules/@cypress/browserify-preprocessor/index",
"TEMPLATED_integrationFileShortPaths": "[\n {files}\n]".format(files = ",\n ".join(integration_files_short_paths)),
"TEMPLATED_pluginsFile": plugins_file.short_path,
},
Expand Down Expand Up @@ -78,9 +77,7 @@ def cypress_web_test(
name,
config_file,
srcs = [],
plugins_file = Label("@build_bazel_rules_nodejs//packages/cypress:internal/plugins/base.js"),
cypress = Label("TEMPLATED_node_modules_workspace_name//cypress:cypress"),
cypress_browserify_preprocessor = Label("TEMPLATED_node_modules_workspace_name//@cypress/browserify-preprocessor"),
plugins_file = Label("//plugins/base.js"),
data = [],
templated_args = [],
cypress_cache = Label("//:cypress_cache"),
Expand All @@ -104,8 +101,6 @@ def cypress_web_test(
tags = tags,
data = data + [
plugins_file,
cypress,
cypress_browserify_preprocessor,
cypress_cache,
cypress_executable,
"{cypress_plugin}".format(cypress_plugin = cypress_plugin),
Expand All @@ -127,7 +122,6 @@ def cypress_web_test_global_cache(
srcs = [],
plugins_file = Label("@build_bazel_rules_nodejs//packages/cypress:plugins/base.js"),
cypress = Label("TEMPLATED_node_modules_workspace_name//cypress:cypress"),
cypress_browserify_preprocessor = Label("TEMPLATED_node_modules_workspace_name//@cypress/browserify-preprocessor"),
data = [],
templated_args = [],
**kwargs):
Expand All @@ -150,7 +144,6 @@ def cypress_web_test_global_cache(
data = data + [
plugins_file,
cypress,
cypress_browserify_preprocessor,
"{cypress_plugin}".format(cypress_plugin = cypress_plugin),
"{config_file}".format(config_file = config_file),
] + srcs,
Expand Down
5 changes: 2 additions & 3 deletions packages/cypress/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "@bazel/cypress",
"peerDependencies": {
"cypress": ">=4.7.0",
"@cypress/browserify-preprocessor": ">=3.0.0"
"cypress": ">=4.7.0"
},
"description": "Run Cypress e2e testing framework under Bazel",
"license": "Apache-2.0",
Expand All @@ -22,4 +21,4 @@
"scripts": {
"postinstall": "node npm_version_check.js"
}
}
}
3 changes: 1 addition & 2 deletions packages/cypress/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"private": true,
"dependencies": {
"express": "4.17.1",
"cypress": "^4.8.0",
"@cypress/browserify-preprocessor": "^3.0.0",
"cypress": "^5.2.0",
"@types/node": "14.0.14",
"rxjs": "^6.5.2",
"typescript": "3.9.5"
Expand Down
Loading

0 comments on commit 98ee87d

Please sign in to comment.