Skip to content

Commit

Permalink
fix(testrunner): properly run tests when the first arg is a file (#3472)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder authored Aug 14, 2020
1 parent 69e1e71 commit 0c798f0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ program
.option('--timeout <timeout>', 'Specify test timeout threshold (in milliseconds), default: 10000', 10000)
.action(async (command) => {
// Collect files
const files = [];
collectFiles(path.join(process.cwd(), command.args[0]), command.args.slice(1), files);
const files = collectFiles(path.join(process.cwd(), command.args[0]), command.args.slice(1));
const rootSuite = new Mocha.Suite('', new Mocha.Context(), true);

let total = 0;
Expand All @@ -61,6 +60,11 @@ program
mocha.suite.title = path.basename(file);
}

if (!total) {
console.error('No tests found.');
process.exit(1);
}

// Filter tests.
if (rootSuite.hasOnly())
rootSuite.filterOnly();
Expand Down Expand Up @@ -88,12 +92,13 @@ program

program.parse(process.argv);

function collectFiles(dir, filters, files) {
function collectFiles(dir, filters) {
if (fs.statSync(dir).isFile())
return [dir];
const files = [];
for (const name of fs.readdirSync(dir)) {
if (fs.lstatSync(path.join(dir, name)).isDirectory()) {
collectFiles(path.join(dir, name), filters, files);
files.push(...collectFiles(path.join(dir, name), filters));
continue;
}
if (!name.includes('spec'))
Expand All @@ -109,4 +114,5 @@ function collectFiles(dir, filters, files) {
}
}
}
return files;
}

0 comments on commit 0c798f0

Please sign in to comment.