Skip to content

Commit

Permalink
CLI: Include .mjs and .cjs in default test file extensions
Browse files Browse the repository at this point in the history
These have been included by watch mode since QUnit 2.18, but so far
only benefited you there if you manually passed these as individual
files, or loaded them indirectly at runtime, or used your own glob
that includes mjs and/or cjs.

If you currently run qunit by passing a directory and have matching
files that you want to skip, opt-out by passing `test/*.js` or
`test/**/*.js` explicitly instead of `test/`.

Follows-up #1676.

Cherry-picked from 6f72eeb (3.0.0-dev).

Cherry-picked from 53ee0a7 (3.0.0-dev).
  • Loading branch information
Krinkle committed Jan 18, 2025
1 parent 62f6d7d commit db1d3be
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bin/qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const pkg = require('../package.json');
const description = `Runs tests using the QUnit framework.
Files should be a space-separated list of files, directories, or glob expressions.
Defaults to 'test/**/*.js'.
Defaults to 'test/**/*.{js,mjs,cjs}'.
For more info on working with QUnit, check out https://qunitjs.com.`;

Expand Down
6 changes: 2 additions & 4 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ function getFilesFromArgs (args) {

// Default to files in the test directory
if (!patterns.length) {
// TODO: In QUnit 3.0, change the default to {js,mjs}
patterns.push('test/**/*.js');
patterns.push('test/**/*.{js,mjs,cjs}');
}

const files = new Set();
Expand All @@ -47,8 +46,7 @@ function getFilesFromArgs (args) {
files.add(pattern);
} else {
if (stat && stat.isDirectory()) {
// TODO: In QUnit 3.0, change the default to {js,mjs}
pattern = `${pattern}/**/*.js`;
pattern = `${pattern}/**/*.{js,mjs,cjs}`;
}
const results = glob(pattern, {
cwd: process.cwd(),
Expand Down
2 changes: 1 addition & 1 deletion test/cli/cli-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ not ok 1 global failure
});

QUnit.test('--seed=true generates new random seed', async assert => {
const command = ['qunit', '--seed', 'true', 'basic-one.js', 'test/'];
const command = ['qunit', '--seed', 'true', 'basic-one.js', 'test/first.js', 'test/nested/'];
const execution = await execute(command);

const actualHarness = execution.snapshot
Expand Down
10 changes: 6 additions & 4 deletions test/cli/fixtures/_load-default.tap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# command: ["qunit"]

TAP version 13
ok 1 First > 1
ok 2 Second > 1
1..2
# pass 2
ok 1 Extension CJS > example
ok 2 Extension MJS > example
ok 3 First > 1
ok 4 Second > 1
1..4
# pass 4
# skip 0
# todo 0
# fail 0
10 changes: 6 additions & 4 deletions test/cli/fixtures/_load-dir-file-glob.tap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ TAP version 13
ok 1 Single > has a test
ok 2 A-Test > derp
ok 3 Nested-Test > herp
ok 4 First > 1
ok 5 Second > 1
1..5
# pass 5
ok 4 Extension CJS > example
ok 5 Extension MJS > example
ok 6 First > 1
ok 7 Second > 1
1..7
# pass 7
# skip 0
# todo 0
# fail 0
10 changes: 6 additions & 4 deletions test/cli/fixtures/_load-dir.tap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# command: ["qunit","test"]

TAP version 13
ok 1 First > 1
ok 2 Second > 1
1..2
# pass 2
ok 1 Extension CJS > example
ok 2 Extension MJS > example
ok 3 First > 1
ok 4 Second > 1
1..4
# pass 4
# skip 0
# todo 0
# fail 0
14 changes: 8 additions & 6 deletions test/cli/fixtures/seed.tap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
Running tests with seed: s33d
TAP version 13
ok 1 Second > 1
ok 2 Nested-Test > herp
ok 3 First > 1
ok 4 A-Test > derp
ok 5 Single > has a test
1..5
# pass 5
ok 2 Extension MJS > example
ok 3 Nested-Test > herp
ok 4 Extension CJS > example
ok 5 A-Test > derp
ok 6 First > 1
ok 7 Single > has a test
1..7
# pass 7
# skip 0
# todo 0
# fail 0
5 changes: 5 additions & 0 deletions test/cli/fixtures/test/extension.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
QUnit.module('Extension CJS', function () {
QUnit.test('example', function (assert) {
assert.true(true);
});
});
5 changes: 5 additions & 0 deletions test/cli/fixtures/test/extension.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
QUnit.module('Extension MJS', function () {
QUnit.test('example', function (assert) {
assert.true(true);
});
});
1 change: 1 addition & 0 deletions test/cli/fixtures/test/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('Directory scan should not load TS by default.');
1 change: 1 addition & 0 deletions test/cli/fixtures/test/extension.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Directory scan should not load TXT by default.

0 comments on commit db1d3be

Please sign in to comment.