Skip to content

Commit

Permalink
fix(cypress): add js files from JSModuleInfo to plugin wrapper source…
Browse files Browse the repository at this point in the history
…s if available
  • Loading branch information
mtl-wgtwo authored and alexeagle committed Aug 23, 2021
1 parent eacbcf7 commit 1274c59
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/cypress/internal/cypress_web_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
"E2E testing with Cypress"

load("@build_bazel_rules_nodejs//:providers.bzl", "JSNamedModuleInfo")
load("@build_bazel_rules_nodejs//:providers.bzl", "JSModuleInfo", "JSNamedModuleInfo")
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_test_kwargs")

ATTRS = dict(
Expand Down Expand Up @@ -55,9 +55,10 @@ def _filter_js(files):
def _cypress_plugin_wrapper(ctx):
plugin_file = None

# TODO: switch to JSModuleInfo when it is available
if JSNamedModuleInfo in ctx.attr.plugin_file:
if JSNamedModuleInfo in ctx.attr.plugin_file and len(ctx.attr.plugin_file[JSNamedModuleInfo].direct_sources.to_list()) > 0:
plugin_file = _filter_js(ctx.attr.plugin_file[JSNamedModuleInfo].direct_sources.to_list())[0]
if JSModuleInfo in ctx.attr.plugin_file and len(ctx.attr.plugin_file[JSModuleInfo].direct_sources.to_list()) > 0:
plugin_file = _filter_js(ctx.attr.plugin_file[JSModuleInfo].direct_sources.to_list())[0]
else:
plugin_file = ctx.file.plugin_file

Expand Down
24 changes: 24 additions & 0 deletions packages/cypress/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
load("@build_bazel_rules_nodejs//packages/cypress:index.bzl", "cypress_web_test")
load("@build_bazel_rules_nodejs//packages/typescript:index.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

js_library(
name = "lib_plugin_file",
srcs = ["lib_plugin.js"],
deps = [
"@cypress_deps//:node_modules",
],
)

ts_library(
name = "plugin_file",
Expand Down Expand Up @@ -37,3 +46,18 @@ cypress_web_test(
plugin_file = ":plugin_file",
tags = ["cypress"],
)

cypress_web_test(
name = "lib_test",
srcs = [
"world.spec.js",
":hello_spec",
],
config_file = "cypress.json",
cypress_npm_package = "@cypress_deps//cypress",
data = [
"@cypress_deps//rxjs",
],
plugin_file = ":lib_plugin_file",
tags = ["cypress"],
)
20 changes: 20 additions & 0 deletions packages/cypress/test/lib_plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

const http = require('http');

module.exports = (_on, config) => {
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((_req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end('<html><body>hello-world</body></html>');
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});

config.baseUrl = `http://${hostname}:${port}`;

return config;
};

0 comments on commit 1274c59

Please sign in to comment.