-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "js_run_devserver symlinks scoped node_modules to baze… (
#1233) * Revert "Revert "js_run_devserver symlinks scoped node_modules to bazel-out instead of runfiles (unscoped node_modules are already linked to bazel-out) (#1210)" (#1230)" Roll-forward #1210 with fixes. This reverts commit 06ad186. * chore: tag devserver test as no-remote-exec
- Loading branch information
Showing
13 changed files
with
813 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
load("@npm//js/private/test/js_run_devserver:jasmine/package_json.bzl", jasmine_bin = "bin") | ||
load(":js_run_devserver_test.bzl", "js_run_devserver_test") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
# Checks node_modules symlinks that they refer to exec root (instead of runfiles) | ||
# in order to make sure bundlers see exactly one node_modules tree. Checks: | ||
# - https://github.com/aspect-build/rules_js/pull/1043 | ||
# - https://github.com/aspect-build/rules_js/issues/1204 | ||
js_run_devserver_test( | ||
name = "node_modules_symlink_to_execroot_test", | ||
args = ["node_modules_symlink_to_execroot.test.mjs"], | ||
chdir = "js/private/test/js_run_devserver", | ||
data = [ | ||
"node_modules_symlink_to_execroot.test.mjs", | ||
|
||
# Some packages to link back to the exec root for the tests for | ||
# https://github.com/aspect-build/rules_js/issues/1204 (and need jasmine | ||
# anyway for the runner) | ||
":node_modules/@types/node", | ||
":node_modules/jasmine", | ||
], | ||
tags = [ | ||
# devserver is meant to be `bazel run` locally. | ||
# See https://github.com/aspect-build/rules_js/pull/1233 | ||
"no-remote-exec", | ||
], | ||
tool = ":jasmine", | ||
) | ||
|
||
jasmine_bin.jasmine_binary( | ||
name = "jasmine", | ||
) |
41 changes: 41 additions & 0 deletions
41
js/private/test/js_run_devserver/js_run_devserver_test.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"Implementation of the js_run_devserver_test rule (the 'test' version of js_run_devserver)" | ||
|
||
load("//js/private:js_run_devserver.bzl", "js_run_devserver", "js_run_devserver_lib") | ||
|
||
# 'test' version of the _js_run_devserver` rule | ||
_js_run_devserver_test = rule( | ||
attrs = js_run_devserver_lib.attrs, | ||
implementation = js_run_devserver_lib.implementation, | ||
toolchains = js_run_devserver_lib.toolchains, | ||
test = True, | ||
) | ||
|
||
def js_run_devserver_test( | ||
name, | ||
tags = [], | ||
**kwargs): | ||
""" | ||
'Test' version of the `js_run_devserver` macro. | ||
Provides the test rule to the macro, along with the 'no-sandbox' tag in | ||
order to properly simulate the js_run_devserver environment of 'bazel run'. | ||
Args: | ||
name: A unique name for this target. | ||
tags: Additional Bazel tags to supply to the rule. | ||
**kwargs: All other args for `js_run_devserver`. | ||
See https://docs.aspect.build/rules/aspect_rules_js/docs/js_run_devserver | ||
""" | ||
js_run_devserver( | ||
name, | ||
# Override the rule to execute | ||
rule_to_execute = _js_run_devserver_test, | ||
# 'no-sandbox' needed to simulate 'bazel run' command - normally tests | ||
# are sandboxed, but sandboxing doesn't exhibit the issue in | ||
# https://github.com/aspect-build/rules_js/issues/1204 | ||
tags = tags + ["no-sandbox"], | ||
**kwargs | ||
) |
30 changes: 30 additions & 0 deletions
30
js/private/test/js_run_devserver/node_modules_symlink_to_execroot.test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import fs from 'fs' | ||
|
||
describe('node_modules symlinks >', () => { | ||
const execRootDir = process.env.JS_BINARY__EXECROOT | ||
const runfilesDir = process.env.JS_BINARY__RUNFILES | ||
|
||
beforeAll(() => { | ||
// first ensure that the environment variables are strings with some value | ||
if (typeof execRootDir !== 'string' || execRootDir.length === 0) { | ||
throw new Error(`process.env.JS_BINARY__EXECROOT is empty - can't run tests which rely on it`) | ||
} | ||
if (typeof runfilesDir !== 'string' || runfilesDir.length === 0) { | ||
throw new Error(`process.env.JS_BINARY__RUNFILES is empty - can't run tests which rely on it`) | ||
} | ||
}) | ||
|
||
it(`symlinks non-scoped node_modules (e.g. 'jasmine') to the exec root instead of runfiles to ensure bundlers see a single node_modules tree (https://github.com/aspect-build/rules_js/pull/1043)`, () => { | ||
const jasmineSymlink = fs.readlinkSync('./node_modules/jasmine') | ||
|
||
expect(jasmineSymlink).toContain(execRootDir) | ||
expect(jasmineSymlink).not.toContain(runfilesDir) | ||
}) | ||
|
||
it(`symlinks scoped node_modules (e.g. '@types/node') to the exec root instead of runfiles to ensure bundlers see a single node_modules tree (https://github.com/aspect-build/rules_js/issues/1204)`, () => { | ||
const typesNodeSymlink = fs.readlinkSync('./node_modules/@types/node') | ||
|
||
expect(typesNodeSymlink).toContain(execRootDir) | ||
expect(typesNodeSymlink).not.toContain(runfilesDir) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "js_run_devserver_test", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@types/node": "16.18.11", | ||
"jasmine": "5.1.0" | ||
} | ||
} |
Oops, something went wrong.