2019-10-08 22:17:55 +00:00
|
|
|
"use strict";
|
2015-04-26 17:33:05 +00:00
|
|
|
|
2019-10-08 22:17:55 +00:00
|
|
|
module.exports = ( grunt ) => {
|
2019-03-04 17:30:51 +00:00
|
|
|
const fs = require( "fs" );
|
|
|
|
const spawnTest = require( "./lib/spawn_test.js" );
|
|
|
|
const testsDir = "./test/node_smoke_tests/";
|
2020-01-07 22:59:08 +00:00
|
|
|
const nodeSmokeTests = [];
|
2015-04-26 17:33:05 +00:00
|
|
|
|
|
|
|
// Fire up all tests defined in test/node_smoke_tests/*.js in spawned sub-processes.
|
|
|
|
// All the files under test/node_smoke_tests/*.js are supposed to exit with 0 code
|
|
|
|
// on success or another one on failure. Spawning in sub-processes is
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
fs.readdirSync( testsDir )
|
2019-03-04 17:30:51 +00:00
|
|
|
.filter( ( testFilePath ) =>
|
|
|
|
fs.statSync( testsDir + testFilePath ).isFile() &&
|
|
|
|
/\.js$/.test( testFilePath )
|
|
|
|
)
|
|
|
|
.forEach( ( testFilePath ) => {
|
|
|
|
const taskName = `node_${ testFilePath.replace( /\.js$/, "" ) }`;
|
2015-04-26 17:33:05 +00:00
|
|
|
|
|
|
|
grunt.registerTask( taskName, function() {
|
2019-03-04 17:30:51 +00:00
|
|
|
spawnTest( this.async(), `node "test/node_smoke_tests/${ testFilePath }"` );
|
2015-04-26 17:33:05 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
nodeSmokeTests.push( taskName );
|
|
|
|
} );
|
|
|
|
|
|
|
|
grunt.registerTask( "node_smoke_tests", nodeSmokeTests );
|
|
|
|
};
|