Skip to content

Instantly share code, notes, and snippets.

@vsemozhetbyt
Last active May 3, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsemozhetbyt/a6e2f3917a414f8dfe6e66e5dd18095a to your computer and use it in GitHub Desktop.
Save vsemozhetbyt/a6e2f3917a414f8dfe6e66e5dd18095a to your computer and use it in GitHub Desktop.
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