Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should exit when no test files found #100

Merged
merged 5 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CovCommand extends Command {

// save coverage-xxxx.json to $PWD/coverage
const covArgs = this.getCovArgs(context);
if (!covArgs) return;
debug('covArgs: %j', covArgs);
yield this.helper.forkNode(nycCli, covArgs, opt);
}
Expand Down Expand Up @@ -120,7 +121,9 @@ class CovCommand extends Command {
covArgs.push(exclude);
}
covArgs.push(require.resolve('mocha/bin/_mocha'));
covArgs = covArgs.concat(this.formatTestArgs(context));
const testArgs = this.formatTestArgs(context);
if (!testArgs) return;
covArgs = covArgs.concat(testArgs);
return covArgs;
}
}
Expand Down
15 changes: 11 additions & 4 deletions lib/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TestCommand extends Command {
};
const mochaFile = require.resolve('mocha/bin/_mocha');
const testArgs = this.formatTestArgs(context);
if (!testArgs) return;
debug('run test: %s %s', mochaFile, testArgs.join(' '));
yield this.helper.forkNode(mochaFile, testArgs, opt);
}
Expand Down Expand Up @@ -95,15 +96,21 @@ class TestCommand extends Command {
testArgv.require = requireArr;

// collect test files
let files = testArgv._.slice();
if (!files.length) {
files = [ process.env.TESTS || `test/**/*.test.${testArgv.typescript ? 'ts' : 'js'}` ];
let pattern = testArgv._.slice();
if (!pattern.length) {
pattern = [ process.env.TESTS || `test/**/*.test.${testArgv.typescript ? 'ts' : 'js'}` ];
}
pattern = pattern.concat([ '!test/fixtures', '!test/node_modules' ]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@popomore 这里是不是 unshift 更好点?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样应该没事


// expand glob and skip node_modules and fixtures
files = globby.sync(files.concat([ '!test/fixtures', '!test/node_modules' ]));
const files = globby.sync(pattern);
files.sort();

if (files.length === 0) {
console.log(`No test files found with ${pattern}`);
return;
}

// auto add setup file as the first test file
const setupFile = path.join(process.cwd(), 'test/.setup.js');
if (fs.existsSync(setupFile)) {
Expand Down
10 changes: 10 additions & 0 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ describe('test/lib/cmd/cov.test.js', () => {
if (!process.env.NYC_ROOT_ID) assertCoverage(cwd);
});

it('should exit when not test files', done => {
mm(process.env, 'NYC_CWD', cwd);
coffee.fork(eggBin, [ 'cov', 'test/**/*.nth.js' ], { cwd })
// .debug()
.expect('stdout', /No test files found/)
.expect('code', 0)
.end(done);
});

it('should hotfixSpawnWrap success on mock windows', function* () {
mm(process.env, 'TESTS', 'test/**/*.test.js');
mm(process.env, 'NYC_CWD', cwd);
Expand Down Expand Up @@ -173,6 +182,7 @@ describe('test/lib/cmd/cov.test.js', () => {
});

it('should set EGG_BIN_PREREQUIRE', function* () {
mm(process.env, 'TESTS', 'test/**/*.test.js');
const cwd = path.join(__dirname, '../../fixtures/prerequire');
yield coffee.fork(eggBin, [ 'cov' ], { cwd })
// .debug()
Expand Down
8 changes: 8 additions & 0 deletions test/lib/cmd/test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ describe('test/lib/cmd/test.test.js', () => {
.end(done);
});

it('should exit when not test files', done => {
coffee.fork(eggBin, [ 'test', 'test/**/*.nth.js' ], { cwd })
// .debug()
.expect('stdout', /No test files found/)
.expect('code', 0)
.end(done);
});

it('should use process.env.TEST_REPORTER', done => {
mm(process.env, 'TESTS', 'test/**/*.test.js');
mm(process.env, 'TEST_REPORTER', 'json');
Expand Down