Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find cwd-dependent Node.js tests
/******************************************************************************/
'use strict';
/******************************************************************************/
const cp = require('child_process');
const fs = require('fs');
const path = require('path');
/******************************************************************************/
const rootPath = 'j:/temp/node-master';
const nodePath = `${rootPath}/Release/node.exe`;
const overPath = path.resolve(rootPath, '..');
const testPath = `${rootPath}/test`;
const cwds = { root: rootPath, over: overPath, test: testPath, subd: '' };
const testSubDirs = [
'abort',
'debugger',
'doctool',
'gc',
'inspector',
'internet',
'known_issues',
'message',
'parallel',
'pseudo-tty',
'pummel',
'sequential',
'tick-processor',
'timers',
];
const skipTests = ['test-https-ci-reneg-attack.js', 'test-tls-ci-reneg-attack.js'];
const flagsRE = /\/\/\s*Flags:\s*(.+)\s*$/m;
/******************************************************************************/
testSubDirs.forEach((subDir) => {
const subdPath = `${testPath}/${subDir}`;
cwds.subd = subdPath;
fs.readdirSync(subdPath)
.filter(fname => path.extname(fname) === '.js' && !skipTests.includes(fname))
.forEach((fname) => {
const filePath = `${subdPath}/${fname}`;
let [, flags] = fs.readFileSync(filePath, 'utf8').match(flagsRE) || [];
flags = flags ? `${flags.replace(/\{PORT\}/i, '12346')} ` : '';
const errors = [];
Object.keys(cwds).forEach((cwdTag) => {
try {
process.chdir(cwds[cwdTag]);
cp.execSync(`${nodePath} ${flags}${filePath}`, { stdio: 'ignore' });
} catch (err) {
errors.push(cwdTag);
}
});
if (errors.length) {
console.log(
`${errors.length} ${errors.join(' ')}: ${flags}${subDir}/${fname}`);
}
});
});
/******************************************************************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.