Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "fixup"
This reverts commit d7ad6ee.
  • Loading branch information
mcollina committed Jul 19, 2024
commit 51ec7e22dcde84f8fbfa6836791af0c2f8967bac
2 changes: 0 additions & 2 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1263,8 +1263,6 @@ changes:
parallel.
If `false`, it would only run one test file at a time.
**Default:** `false`.
* `cwd` {string} The current working directory for the test runner.
**Default:** `process.cwd()`.
* `files`: {Array} An array containing the list of files to run.
**Default** matching files from [test runner execution model][].
* `forceExit`: {boolean} Configures the test runner to exit the process once
Expand Down
15 changes: 4 additions & 11 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const {
validateFunction,
validateObject,
validateInteger,
validateString,
} = require('internal/validators');
const { getInspectPort, isUsingInspector, isInspectorMessage } = require('internal/util/inspector');
const { isRegExp } = require('internal/util/types');
Expand Down Expand Up @@ -89,7 +88,8 @@ const kCanceledTests = new SafeSet()

let kResistStopPropagation;

function createTestFileList(cwd, patterns) {
function createTestFileList(patterns) {
const cwd = process.cwd();
const hasUserSuppliedPattern = patterns != null;
if (!patterns || patterns.length === 0) {
patterns = [kDefaultPattern];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assign the default patterns in the run() validation. You can do that in this PR, otherwise, I will probably do it in a follow up.

Expand Down Expand Up @@ -421,7 +421,7 @@ function watchFiles(testFiles, opts) {

watcher.on('changed', ({ owners, eventType }) => {
if (!opts.hasFiles && eventType === 'rename') {
const updatedTestFiles = createTestFileList(opts.cwd, opts.globPatterns);
const updatedTestFiles = createTestFileList(opts.globPatterns);

const newFileName = ArrayPrototypeFind(updatedTestFiles, (x) => !ArrayPrototypeIncludes(testFiles, x));
const previousFileName = ArrayPrototypeFind(testFiles, (x) => !ArrayPrototypeIncludes(updatedTestFiles, x));
Expand Down Expand Up @@ -484,7 +484,6 @@ function run(options = kEmptyObject) {
watch,
setup,
only,
cwd,
globPatterns,
} = options;

Expand Down Expand Up @@ -531,11 +530,6 @@ function run(options = kEmptyObject) {
if (setup != null) {
validateFunction(setup, 'options.setup');
}

if (cwd != null) {
validateString(cwd, 'options.cwd');
}

if (testNamePatterns != null) {
if (!ArrayIsArray(testNamePatterns)) {
testNamePatterns = [testNamePatterns];
Expand Down Expand Up @@ -577,7 +571,7 @@ function run(options = kEmptyObject) {
root.postRun();
return root.reporter;
}
let testFiles = files ?? createTestFileList(cwd, globPatterns);
let testFiles = files ?? createTestFileList(globPatterns);

if (shard) {
testFiles = ArrayPrototypeFilter(testFiles, (_, index) => index % shard.total === shard.index - 1);
Expand All @@ -596,7 +590,6 @@ function run(options = kEmptyObject) {
globPatterns,
only,
forceExit,
cwd,
};
if (watch) {
filesWatcher = watchFiles(testFiles, opts);
Expand Down
11 changes: 5 additions & 6 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import tmpdir from '../common/tmpdir.js';

const testFixtures = fixtures.path('test-runner');

// This is needed, because calling run() with no files will
// load files matching from cwd, which includes all content of test/
tmpdir.refresh();
process.chdir(tmpdir.path);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this break running the test suite in worker threads?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, I would need to fix #53867 as well in this PR.

Let's see if it actually breaks something in CI.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it did break in the CI (https://ci.nodejs.org/job/node-test-commit-custom-suites-freestyle/37045/). The issue is that the Node test suite is run within a worker thread in the CI. Any test that uses an API that is unsupported in worker threads needs to be skipped there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need to remove this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll need to add a cwd parameter to run(), otherwise it won't work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would hold off on adding a cwd parameter for now, but I do foresee us adding it in the future. I'm just not sure if it will break anything until the necessary refactoring happens. Another option is to spawn a child process with the correct cwd.


describe('require(\'node:test\').run', { concurrency: true }, () => {
it('should run with no tests', async () => {
const stream = run({ files: [] });
Expand Down Expand Up @@ -504,9 +509,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
});

it('should run with no files', async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these tests be removed? Shouldn't these still work the same?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately they will now fail as they are trying to load all files in test that matches the given glob pattern. They were passing before due to the CLI checks that I removed.

tmpdir.refresh();
const stream = run({
cwd: tmpdir.path,
files: undefined
}).compose(tap);
stream.on('test:fail', common.mustNotCall());
Expand All @@ -517,9 +520,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
});

it('should run with no files and use spec reporter', async () => {
tmpdir.refresh();
const stream = run({
cwd: tmpdir.path,
files: undefined
}).compose(spec);
stream.on('test:fail', common.mustNotCall());
Expand All @@ -530,9 +531,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
});

it('should run with no files and use dot reporter', async () => {
tmpdir.refresh();
const stream = run({
cwd: tmpdir.path,
files: undefined
}).compose(dot);
stream.on('test:fail', common.mustNotCall());
Expand Down