Skip to content

Commit

Permalink
test_runner: refactor cwd handling in test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarchini committed Sep 11, 2024
1 parent 518bb16 commit 9c4aef1
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 24 deletions.
11 changes: 0 additions & 11 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1097,17 +1097,6 @@ generated as part of the test runner output. If no tests are run, a coverage
report is not generated. See the documentation on
[collecting code coverage from tests][] for more details.

### `--experimental-test-cwd=directory`

<!-- YAML
added: CHANGEME
-->

> Stability: 1.0 - Early development
Set the current working directory for the test runner. If not specified, the current
working directory is used.

### `--experimental-test-isolation=mode`

<!-- YAML
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ function sortCoverageFiles(a, b) {

function setupCoverage(options) {
let originalCoverageDirectory = process.env.NODE_V8_COVERAGE;
const cwd = options.testCwd;
const cwd = options.cwd ?? process.cwd();

if (originalCoverageDirectory) {
// NODE_V8_COVERAGE was already specified. Convert it to an absolute path
Expand Down
6 changes: 4 additions & 2 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,12 @@ function setupProcessState(root, globalOptions) {

hook.enable();

const cwd = globalOptions.cwd || process.cwd();

const exceptionHandler =
createProcessEventHandler('uncaughtException', root, globalOptions.testCwd);
createProcessEventHandler('uncaughtException', root, cwd);
const rejectionHandler =
createProcessEventHandler('unhandledRejection', root, globalOptions.testCwd);
createProcessEventHandler('unhandledRejection', root, cwd);
const coverage = configureCoverage(root, globalOptions);
const exitHandler = async () => {
if (root.subtests.length === 0 && (root.hooks.before.length > 0 || root.hooks.after.length > 0)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => {
});

const kIsolatedProcessName = Symbol('kIsolatedProcessName');
const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch', '--experimental-test-cwd'];
const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch'];
const kFilterArgValues = ['--test-reporter', '--test-reporter-destination'];
const kDiagnosticsFilterArgs = ['tests', 'suites', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms'];

Expand Down Expand Up @@ -626,6 +626,7 @@ function run(options = kEmptyObject) {
// behavior has relied on it, so removing it must be done in a semver major.
...parseCommandLine(),
setup, // This line can be removed when parseCommandLine() is removed here.
cwd,
};
const root = createTestTree(rootTestOptions, globalOptions);
let testFiles = files ?? createTestFileList(globPatterns, cwd);
Expand Down Expand Up @@ -678,8 +679,7 @@ function run(options = kEmptyObject) {
};
} else if (isolation === 'none') {
if (watch) {
// TODO
const absoluteTestFiles = ArrayPrototypeMap(testFiles, (file) => isAbsolute(file) ? file : resolve(cwd, file));
const absoluteTestFiles = ArrayPrototypeMap(testFiles, (file) => (isAbsolute(file) ? file : resolve(cwd, file)));
filesWatcher = watchFiles(absoluteTestFiles, opts);
runFiles = async () => {
root.harness.bootstrapPromise = null;
Expand Down
2 changes: 0 additions & 2 deletions lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ function parseCommandLine() {
let functionCoverage;
let destinations;
let isolation;
let testCwd = getOptionValue('--experimental-test-cwd') || process.cwd()
let only = getOptionValue('--test-only');
let reporters;
let shard;
Expand Down Expand Up @@ -312,7 +311,6 @@ function parseCommandLine() {
destinations,
forceExit,
isolation,
testCwd,
branchCoverage,
functionCoverage,
lineCoverage,
Expand Down
4 changes: 0 additions & 4 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,6 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"the line coverage minimum threshold",
&EnvironmentOptions::test_coverage_lines,
kAllowedInEnvvar);

AddOption("--experimental-test-cwd",
"specify the working directory for the test runner",
&EnvironmentOptions::test_runner_cwd);
AddOption("--experimental-test-isolation",
"configures the type of test isolation used in the test runner",
&EnvironmentOptions::test_isolation);
Expand Down
1 change: 0 additions & 1 deletion src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ class EnvironmentOptions : public Options {
bool test_only = false;
bool test_udp_no_try_send = false;
std::string test_isolation = "process";
std::string test_runner_cwd;
std::string test_shard;
std::vector<std::string> test_skip_pattern;
std::vector<std::string> coverage_include_pattern;
Expand Down

0 comments on commit 9c4aef1

Please sign in to comment.