Skip to content

Commit

Permalink
Build: consolidate node_smoke_tests tasks into one
Browse files Browse the repository at this point in the history
- move all the combinations to the JS file
  • Loading branch information
timmywil committed Sep 15, 2023
1 parent 8708189 commit 8ffaa85
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
50 changes: 28 additions & 22 deletions build/tasks/node_smoke_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const fs = require( "fs" );
const util = require( "util" );
const exec = util.promisify( require( "child_process" ).exec );
const verifyNodeVersion = require( "./lib/verifyNodeVersion" );
const { argv } = require( "process" );
const args = argv.slice( 2 );

const allowedModules = [ "commonjs", "module" ];

Expand All @@ -19,26 +17,34 @@ if ( !verifyNodeVersion() ) {
// important so that the tests & the main process don't interfere with
// each other, e.g. so that they don't share the `require` cache.

async function runTests() {
const promises = args.map( async( arg ) => {
const [ moduleType, module ] = arg.split( ":" );
if ( !allowedModules.includes( moduleType ) ) {
throw new Error(
`Usage: \`node_smoke_tests [${allowedModules.join( "|" )}]:JQUERY\``
);
}
const dir = `./test/node_smoke_tests/${moduleType}`;
const files = await fs.promises.readdir( dir, { withFileTypes: true } );
const testFiles = files.filter( ( testFilePath ) => testFilePath.isFile() );
return Promise.all(
testFiles.map( ( testFile ) =>
exec( `node "${dir}/${testFile.name}" "${module}"` )
)
async function runTests( sourceType, module ) {
if ( !allowedModules.includes( sourceType ) ) {
throw new Error(
`Usage: \`node_smoke_tests [${allowedModules.join( "|" )}]:JQUERY\``
);
} );
Promise.all( promises ).then( () => {
console.log( `Node smoke tests passed for ${args.join( ", " )}.` );
} );
}
const dir = `./test/node_smoke_tests/${sourceType}`;
const files = await fs.promises.readdir( dir, { withFileTypes: true } );
const testFiles = files.filter( ( testFilePath ) => testFilePath.isFile() );
await Promise.all(
testFiles.map( ( testFile ) =>
exec( `node "${dir}/${testFile.name}" "${module}"` )
)
);
console.log( `Node smoke tests passed for ${sourceType} "${module}".` );
}

runTests();
async function runDefaultTests() {
await Promise.all( [
runTests( "commonjs", "jquery" ),
runTests( "commonjs", "jquery/slim" ),
runTests( "commonjs", "./dist/jquery.js" ),
runTests( "commonjs", "./dist/jquery.slim.js" ),
runTests( "module", "jquery" ),
runTests( "module", "jquery/slim" ),
runTests( "module", "./dist-module/jquery.module.js" ),
runTests( "module", "./dist-module/jquery.slim.module.js" )
] );
}

runDefaultTests();
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
"test:no-deprecated": "npm run build:main -- -e deprecated && grunt karma:main",
"test:selector-native": "npm run build:main -- -e selector && grunt karma:main",
"test:slim": "npm run build:main -- --slim && grunt karma:main",
"test:node_smoke_tests:commonjs": "node build/tasks/node_smoke_tests.js commonjs:./dist/jquery.js commonjs:jquery commonjs:./dist/jquery.slim.js commonjs:jquery/slim",
"test:node_smoke_tests:module": "node build/tasks/node_smoke_tests.js module:./dist-module/jquery.module.js module:jquery module:./dist-module/jquery.slim.module.js module:jquery/slim",
"test:node_smoke_tests": "npm run build-all-variants && npm run test:node_smoke_tests:commonjs && npm run test:node_smoke_tests:module",
"test:node_smoke_tests": "npm run build-all-variants && node build/tasks/node_smoke_tests.js",
"test:promises_aplus": "npm run build:main && node build/tasks/promises_aplus_tests.js",
"test": "npm run build-all-variants && npm run lint && npm run test:browserless && npm run test:browser && npm run test:esmodules && npm run test:slim && npm run test:no-deprecated && npm run test:selector-native"
},
Expand Down

0 comments on commit 8ffaa85

Please sign in to comment.