Skip to content

Commit afd3524

Browse files
committed
feat: add test location config
1 parent 9d87d12 commit afd3524

4 files changed

Lines changed: 25 additions & 10 deletions

File tree

lib/commands/package/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ export default class extends Command {
6868
}
6969
}
7070

71-
args.push( "tests/**/*.test.js" );
72-
7371
const packages = [
7472
{
7573
"package": pkg,
@@ -85,9 +83,11 @@ export default class extends Command {
8583
}
8684

8785
for ( const test of packages ) {
86+
if ( !test.cliConfig?.tests.location ) continue;
87+
8888
console.log( "Test package:", test.package.name );
8989

90-
const res = childProcess.spawnSync( "node", args, {
90+
const res = childProcess.spawnSync( "node", [ ...args, test.cliConfig.tests.location ], {
9191
"cwd": test.package.root,
9292
"stdio": "inherit",
9393
} );

lib/package.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,12 +1209,14 @@ export default class Package {
12091209
if ( pkg.cliConfig ) {
12101210

12111211
// "test" script
1212-
if ( ( await glob( "tests/**/*.test.js", { "cwd": pkg.root } ) ).length ) {
1213-
config.scripts ??= {};
1214-
config.scripts.test = `node --test "tests/**/*.test.js"`;
1215-
}
1216-
else {
1217-
delete config.scripts?.test;
1212+
if ( pkg.cliConfig.tests.location ) {
1213+
if ( ( await glob( pkg.cliConfig.tests.location, { "cwd": pkg.root } ) ).length ) {
1214+
config.scripts ??= {};
1215+
config.scripts.test = `node --test "${ pkg.cliConfig.tests.location }"`;
1216+
}
1217+
else {
1218+
delete config.scripts?.test;
1219+
}
12181220
}
12191221

12201222
// dependencies

resources/cli.config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ meta:
5353
dependabotsecurityupdates: false
5454
privateVulnerabilityReporting: true
5555

56+
tests:
57+
location: "tests/**/*.test.js"
58+
5659
release:
5760
enabled: false
5861
releaseBranches: [main]

resources/schemas/cli.config.schema.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@
7373
minItems: 1
7474
uniqueItems: true
7575

76+
tests:
77+
type: object
78+
properties:
79+
location:
80+
anyOf:
81+
- type: "null"
82+
- { type: string, format: glob-pattern }
83+
additionalProperties: false
84+
required: [location]
85+
7686
release:
7787
type: object
7888
properties:
@@ -219,7 +229,7 @@
219229
required: [location]
220230

221231
additionalProperties: false
222-
required: [meta, release, commits]
232+
required: [meta, tests, release, commits]
223233

224234
- $id: dependabot
225235
type: object

0 commit comments

Comments
 (0)