From c87651a99c874809bedbade3de27c38f700535ee Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 20 Jun 2017 12:11:26 +0800 Subject: [PATCH 1/4] fix: ignore frontend files and document files --- .gitignore | 3 +- appveyor.yml | 2 +- lib/cmd/cov.js | 9 ++++-- package.json | 3 +- test/fixtures/test-files/app/assets/index.js | 3 ++ .../test-files/app/assets/subdir/home.js | 3 ++ test/fixtures/test-files/app/public/bar.js | 3 ++ .../test-files/app/public/subdir/home.js | 3 ++ .../test-files/app/view/subdir/home.js | 3 ++ test/fixtures/test-files/docs/home.js | 3 ++ test/fixtures/test-files/example/foo.js | 3 ++ test/fixtures/test-files/examples/foo.js | 3 ++ test/fixtures/test-files/mocks/foo.js | 3 ++ .../fixtures/test-files/mocks_data/foo/foo.js | 3 ++ test/lib/cmd/cov.test.js | 28 +++++++++++++------ 15 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/test-files/app/assets/index.js create mode 100644 test/fixtures/test-files/app/assets/subdir/home.js create mode 100644 test/fixtures/test-files/app/public/bar.js create mode 100644 test/fixtures/test-files/app/public/subdir/home.js create mode 100644 test/fixtures/test-files/app/view/subdir/home.js create mode 100644 test/fixtures/test-files/docs/home.js create mode 100644 test/fixtures/test-files/example/foo.js create mode 100644 test/fixtures/test-files/examples/foo.js create mode 100644 test/fixtures/test-files/mocks/foo.js create mode 100644 test/fixtures/test-files/mocks_data/foo/foo.js diff --git a/.gitignore b/.gitignore index 779a3f16..d8340224 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ coverage/ .tmp .vscode *.log -package-lock.json \ No newline at end of file +package-lock.json +.nyc_output diff --git a/appveyor.yml b/appveyor.yml index 00663727..698d8f9c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,6 +11,6 @@ install: test_script: - node --version - npm --version - - npm run ci + - npm run test build: off diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index c66d07ef..aaba035b 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -25,8 +25,13 @@ class CovCommand extends Command { // you can add ignore dirs here this[EXCLUDES] = new Set([ - 'examples/**', - 'mocks_*/**', + 'example/', + 'examples/', + 'mocks**/', + 'app/assets/', + 'app/view/', + 'app/public/', + 'docs/', ].concat(testExclude.defaultExclude)); } diff --git a/package.json b/package.json index eb0057c2..43f7d7a8 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,8 @@ "test": "npm run lint -- --fix && npm run test-local", "test-local": "node bin/egg-bin.js test -t 3600000", "cov": "nyc -r lcov -r text-summary npm run test-local", - "ci": "npm run lint && npm run pkgfiles && npm run cov", + "ci-test-only": "TESTS=test/lib/cmd/cov.test.js npm run test-local", + "ci": "npm run lint && npm run pkgfiles && npm run ci-test-only && npm run cov", "autod": "autod" }, "engines": { diff --git a/test/fixtures/test-files/app/assets/index.js b/test/fixtures/test-files/app/assets/index.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/app/assets/index.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/app/assets/subdir/home.js b/test/fixtures/test-files/app/assets/subdir/home.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/app/assets/subdir/home.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/app/public/bar.js b/test/fixtures/test-files/app/public/bar.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/app/public/bar.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/app/public/subdir/home.js b/test/fixtures/test-files/app/public/subdir/home.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/app/public/subdir/home.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/app/view/subdir/home.js b/test/fixtures/test-files/app/view/subdir/home.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/app/view/subdir/home.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/docs/home.js b/test/fixtures/test-files/docs/home.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/docs/home.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/example/foo.js b/test/fixtures/test-files/example/foo.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/example/foo.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/examples/foo.js b/test/fixtures/test-files/examples/foo.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/examples/foo.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/mocks/foo.js b/test/fixtures/test-files/mocks/foo.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/mocks/foo.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/mocks_data/foo/foo.js b/test/fixtures/test-files/mocks_data/foo/foo.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/mocks_data/foo/foo.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 9a34fff6..ac7d4e27 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -15,14 +15,19 @@ describe('test/lib/cmd/cov.test.js', () => { it('should success', done => { mm(process.env, 'TESTS', 'test/**/*.test.js'); mm(process.env, 'NYC_CWD', cwd); - coffee.fork(eggBin, [ 'cov' ], { cwd }) - // .debug() + const child = coffee.fork(eggBin, [ 'cov' ], { cwd }) + .debug() .expect('stdout', /should success/) .expect('stdout', /a\.test\.js/) .expect('stdout', /b[\/|\\]b\.test\.js/) - .notExpect('stdout', /a.js/) - // .expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/) - .expect('code', 0) + .notExpect('stdout', /a.js/); + + // only test on npm run test + if (!process.env.NYC_ROOT_ID) { + child.expect('stdout', /Statements {3}: 80% \( 4[\/|\\]5 \)/); + } + + child.expect('code', 0) .end(err => { assert.ifError(err); assert.ok(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json'))); @@ -36,14 +41,19 @@ describe('test/lib/cmd/cov.test.js', () => { it('should success with COV_EXCLUDES', function* () { mm(process.env, 'TESTS', 'test/**/*.test.js'); mm(process.env, 'COV_EXCLUDES', 'ignore/*'); - yield coffee.fork(eggBin, [ 'cov' ], { cwd }) + const child = coffee.fork(eggBin, [ 'cov' ], { cwd }) // .debug() .expect('stdout', /should success/) .expect('stdout', /a\.test\.js/) .expect('stdout', /b[\/|\\]b\.test\.js/) - .notExpect('stdout', /a.js/) - // .expect('stdout', /Statements {3}: 75% \( 3[\/|\\]4 \)/) - .expect('code', 0) + .notExpect('stdout', /a.js/); + + // only test on npm run test + if (!process.env.NYC_ROOT_ID) { + child.expect('stdout', /Statements {3}: 75% \( 3[\/|\\]4 \)/); + } + + yield child.expect('code', 0) .end(); assert(fs.existsSync(path.join(cwd, 'coverage/coverage-final.json'))); assert(fs.existsSync(path.join(cwd, 'coverage/lcov-report/index.html'))); From 583d221307c148044b5c374fefaec9bc1a4c669c Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 20 Jun 2017 12:20:41 +0800 Subject: [PATCH 2/4] f --- lib/cmd/cov.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index aaba035b..cbc2ef2b 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -28,6 +28,7 @@ class CovCommand extends Command { 'example/', 'examples/', 'mocks**/', + 'app/config/', 'app/assets/', 'app/view/', 'app/public/', From 9c2b700917382aed2cfb6e707549c4ee3ac034e9 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 20 Jun 2017 12:24:07 +0800 Subject: [PATCH 3/4] f --- test/fixtures/test-files/app/config/config.default.js | 3 +++ test/fixtures/test-files/app/config/config.prod.js | 3 +++ test/fixtures/test-files/app/config/plugin.js | 3 +++ test/fixtures/test-files/app/config/proxy.js | 3 +++ 4 files changed, 12 insertions(+) create mode 100644 test/fixtures/test-files/app/config/config.default.js create mode 100644 test/fixtures/test-files/app/config/config.prod.js create mode 100644 test/fixtures/test-files/app/config/plugin.js create mode 100644 test/fixtures/test-files/app/config/proxy.js diff --git a/test/fixtures/test-files/app/config/config.default.js b/test/fixtures/test-files/app/config/config.default.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/app/config/config.default.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/app/config/config.prod.js b/test/fixtures/test-files/app/config/config.prod.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/app/config/config.prod.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/app/config/plugin.js b/test/fixtures/test-files/app/config/plugin.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/app/config/plugin.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/app/config/proxy.js b/test/fixtures/test-files/app/config/proxy.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/app/config/proxy.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; From 676de981f6eb2a133c033f6a7123a21b4fb26cb1 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 20 Jun 2017 12:26:43 +0800 Subject: [PATCH 4/4] f --- lib/cmd/cov.js | 2 +- test/fixtures/test-files/{app => }/config/config.default.js | 0 test/fixtures/test-files/{app => }/config/config.prod.js | 0 test/fixtures/test-files/{app => }/config/plugin.js | 0 test/fixtures/test-files/{app => }/config/proxy.js | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename test/fixtures/test-files/{app => }/config/config.default.js (100%) rename test/fixtures/test-files/{app => }/config/config.prod.js (100%) rename test/fixtures/test-files/{app => }/config/plugin.js (100%) rename test/fixtures/test-files/{app => }/config/proxy.js (100%) diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index cbc2ef2b..949e0d71 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -28,7 +28,7 @@ class CovCommand extends Command { 'example/', 'examples/', 'mocks**/', - 'app/config/', + 'config/', 'app/assets/', 'app/view/', 'app/public/', diff --git a/test/fixtures/test-files/app/config/config.default.js b/test/fixtures/test-files/config/config.default.js similarity index 100% rename from test/fixtures/test-files/app/config/config.default.js rename to test/fixtures/test-files/config/config.default.js diff --git a/test/fixtures/test-files/app/config/config.prod.js b/test/fixtures/test-files/config/config.prod.js similarity index 100% rename from test/fixtures/test-files/app/config/config.prod.js rename to test/fixtures/test-files/config/config.prod.js diff --git a/test/fixtures/test-files/app/config/plugin.js b/test/fixtures/test-files/config/plugin.js similarity index 100% rename from test/fixtures/test-files/app/config/plugin.js rename to test/fixtures/test-files/config/plugin.js diff --git a/test/fixtures/test-files/app/config/proxy.js b/test/fixtures/test-files/config/proxy.js similarity index 100% rename from test/fixtures/test-files/app/config/proxy.js rename to test/fixtures/test-files/config/proxy.js