From f9d578ed954e5eceed94196f3952d66116300222 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 20 Jun 2017 13:17:38 +0800 Subject: [PATCH] fix: ignore frontend files and document files (#65) --- .gitignore | 3 +- appveyor.yml | 2 +- lib/cmd/cov.js | 10 +++++-- 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-files/config/config.default.js | 3 ++ .../fixtures/test-files/config/config.prod.js | 3 ++ test/fixtures/test-files/config/plugin.js | 3 ++ test/fixtures/test-files/config/proxy.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 +++++++++++++------ 19 files changed, 74 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/config/config.default.js create mode 100644 test/fixtures/test-files/config/config.prod.js create mode 100644 test/fixtures/test-files/config/plugin.js create mode 100644 test/fixtures/test-files/config/proxy.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..949e0d71 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -25,8 +25,14 @@ class CovCommand extends Command { // you can add ignore dirs here this[EXCLUDES] = new Set([ - 'examples/**', - 'mocks_*/**', + 'example/', + 'examples/', + 'mocks**/', + 'config/', + '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/config/config.default.js b/test/fixtures/test-files/config/config.default.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/config/config.default.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/config/config.prod.js b/test/fixtures/test-files/config/config.prod.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/config/config.prod.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/config/plugin.js b/test/fixtures/test-files/config/plugin.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/config/plugin.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ''; diff --git a/test/fixtures/test-files/config/proxy.js b/test/fixtures/test-files/config/proxy.js new file mode 100644 index 00000000..17897ee7 --- /dev/null +++ b/test/fixtures/test-files/config/proxy.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')));