From 421f004e522d93c5cda11ed49a9333931769abf1 Mon Sep 17 00:00:00 2001 From: TZ Date: Fri, 29 Jun 2018 08:28:59 +0800 Subject: [PATCH 1/5] fix: should exit when no test files found --- lib/cmd/cov.js | 5 ++++- lib/cmd/test.js | 15 +++++++++++---- test/lib/cmd/cov.test.js | 17 +++++++++++++++++ test/lib/cmd/test.test.js | 9 +++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index 2dc2b9b1..c2dad72f 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -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); } @@ -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; } } diff --git a/lib/cmd/test.js b/lib/cmd/test.js index 33317d79..7045b289 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -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); } @@ -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' ]); // 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)) { diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 16064e51..23f6c77f 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -41,6 +41,23 @@ describe('test/lib/cmd/cov.test.js', () => { if (!process.env.NYC_ROOT_ID) assertCoverage(cwd); }); + it('should exit when not test files', function* () { + mm(process.env, 'TESTS', 'test/**/*.nth.js'); + mm(process.env, 'NYC_CWD', cwd); + const child = coffee.fork(eggBin, [ 'cov' ], { cwd }) + // .debug() + .expect('stdout', /No test files found/); + + // only test on npm run test + if (!process.env.NYC_ROOT_ID) { + child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/); + } + + yield child.expect('code', 0).end(); + // only test on npm run test + if (!process.env.NYC_ROOT_ID) assertCoverage(cwd); + }); + it('should hotfixSpawnWrap success on mock windows', function* () { mm(process.env, 'TESTS', 'test/**/*.test.js'); mm(process.env, 'NYC_CWD', cwd); diff --git a/test/lib/cmd/test.test.js b/test/lib/cmd/test.test.js index 304a1759..e659ee5c 100644 --- a/test/lib/cmd/test.test.js +++ b/test/lib/cmd/test.test.js @@ -55,6 +55,15 @@ describe('test/lib/cmd/test.test.js', () => { .end(done); }); + it('should exit when not test files', done => { + mm(process.env, 'TESTS', 'test/**/*.noth.js'); + coffee.fork(eggBin, [ 'test' ], { 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'); From bc1a44599a9c7197fadf97ba5166f8ae0b893f29 Mon Sep 17 00:00:00 2001 From: TZ Date: Fri, 29 Jun 2018 09:46:20 +0800 Subject: [PATCH 2/5] f --- test/lib/cmd/cov.test.js | 3 +-- test/lib/cmd/test.test.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 23f6c77f..ca9e59fc 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -42,9 +42,8 @@ describe('test/lib/cmd/cov.test.js', () => { }); it('should exit when not test files', function* () { - mm(process.env, 'TESTS', 'test/**/*.nth.js'); mm(process.env, 'NYC_CWD', cwd); - const child = coffee.fork(eggBin, [ 'cov' ], { cwd }) + const child = coffee.fork(eggBin, [ 'cov', 'test/**/*.nth.js' ], { cwd }) // .debug() .expect('stdout', /No test files found/); diff --git a/test/lib/cmd/test.test.js b/test/lib/cmd/test.test.js index e659ee5c..b7f76bb5 100644 --- a/test/lib/cmd/test.test.js +++ b/test/lib/cmd/test.test.js @@ -56,8 +56,7 @@ describe('test/lib/cmd/test.test.js', () => { }); it('should exit when not test files', done => { - mm(process.env, 'TESTS', 'test/**/*.noth.js'); - coffee.fork(eggBin, [ 'test' ], { cwd }) + coffee.fork(eggBin, [ 'test', 'test/**/*.nth.js' ], { cwd }) // .debug() .expect('stdout', /No test files found/) .expect('code', 0) From 84231196f69370540f39e0b7c7f7dc50ac0501c2 Mon Sep 17 00:00:00 2001 From: TZ Date: Fri, 29 Jun 2018 09:59:02 +0800 Subject: [PATCH 3/5] trigger ci From fee2fd2afb8a15394015fc017b8c08739b8c7d44 Mon Sep 17 00:00:00 2001 From: TZ Date: Fri, 29 Jun 2018 10:07:39 +0800 Subject: [PATCH 4/5] f --- test/lib/cmd/cov.test.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index ca9e59fc..08358986 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -41,20 +41,13 @@ describe('test/lib/cmd/cov.test.js', () => { if (!process.env.NYC_ROOT_ID) assertCoverage(cwd); }); - it('should exit when not test files', function* () { + it('should exit when not test files', done => { mm(process.env, 'NYC_CWD', cwd); - const child = coffee.fork(eggBin, [ 'cov', 'test/**/*.nth.js' ], { cwd }) + coffee.fork(eggBin, [ 'cov', 'test/**/*.nth.js' ], { cwd }) // .debug() - .expect('stdout', /No test files found/); - - // only test on npm run test - if (!process.env.NYC_ROOT_ID) { - child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/); - } - - yield child.expect('code', 0).end(); - // only test on npm run test - if (!process.env.NYC_ROOT_ID) assertCoverage(cwd); + .expect('stdout', /No test files found/) + .expect('code', 0) + .end(done); }); it('should hotfixSpawnWrap success on mock windows', function* () { From 2c8560757556ccd2f427ad5a1ae279cc6aa3ed75 Mon Sep 17 00:00:00 2001 From: TZ Date: Fri, 29 Jun 2018 10:40:43 +0800 Subject: [PATCH 5/5] f --- test/lib/cmd/cov.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 08358986..5558ba55 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -182,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()