diff --git a/e2e/__tests__/__snapshots__/coverageProjects.test.ts.snap b/e2e/__tests__/__snapshots__/coverageProjects.test.ts.snap new file mode 100644 index 000000000000..7e29846d07b2 --- /dev/null +++ b/e2e/__tests__/__snapshots__/coverageProjects.test.ts.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`outputs coverage report 1`] = ` +----------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +----------------|---------|----------|---------|---------|------------------- +All files | 100 | 100 | 100 | 100 | + add | 100 | 100 | 100 | 100 | + index.js | 100 | 100 | 100 | 100 | + mul | 100 | 100 | 100 | 100 | + other_file.js | 100 | 100 | 100 | 100 | +----------------|---------|----------|---------|---------|------------------- +`; diff --git a/e2e/__tests__/coverageProjects.test.ts b/e2e/__tests__/coverageProjects.test.ts new file mode 100644 index 000000000000..ba8b310a56fe --- /dev/null +++ b/e2e/__tests__/coverageProjects.test.ts @@ -0,0 +1,35 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import * as fs from 'fs'; +import * as path from 'path'; +import {wrap} from 'jest-snapshot-serializer-raw'; +import {run} from '../Utils'; +import runJest from '../runJest'; + +const DIR = path.resolve(__dirname, '../coverage-projects'); + +beforeAll(() => { + run('yarn', DIR); +}); + +test('outputs coverage report', () => { + const {stdout, exitCode} = runJest(DIR, ['--no-cache', '--coverage'], { + stripAnsi: true, + }); + const coverageDir = path.join(DIR, 'coverage'); + + // - the `index.js` file in package `mul` is ignored and should not be in the + // coverage report. + expect(wrap(stdout)).toMatchSnapshot(); + + // `index.js` should only appear once (in package `add`) + expect(stdout.match(/index\.js/g)).toHaveLength(1); + + expect(() => fs.accessSync(coverageDir, fs.F_OK)).not.toThrow(); + expect(exitCode).toBe(0); +}); diff --git a/e2e/coverage-projects/.gitignore b/e2e/coverage-projects/.gitignore new file mode 100644 index 000000000000..2f73502db24b --- /dev/null +++ b/e2e/coverage-projects/.gitignore @@ -0,0 +1,2 @@ +coverage +yarn-error.log diff --git a/e2e/coverage-projects/package.json b/e2e/coverage-projects/package.json new file mode 100644 index 000000000000..e9ff652976d1 --- /dev/null +++ b/e2e/coverage-projects/package.json @@ -0,0 +1,12 @@ +{ + "private": true, + "workspaces": { + "packages": [ + "packages/*" + ] + }, + "jest": { + "collectCoverage": true, + "projects": ["packages/*"] + } +} diff --git a/e2e/coverage-projects/packages/add/index.js b/e2e/coverage-projects/packages/add/index.js new file mode 100644 index 000000000000..58d30edddf98 --- /dev/null +++ b/e2e/coverage-projects/packages/add/index.js @@ -0,0 +1,8 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +module.exports = (x, y) => x + y; diff --git a/e2e/coverage-projects/packages/add/index.test.js b/e2e/coverage-projects/packages/add/index.test.js new file mode 100644 index 000000000000..5d6e8889151d --- /dev/null +++ b/e2e/coverage-projects/packages/add/index.test.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +const add = require('.'); + +describe('add', () => { + it('should add correctly', () => { + expect(add(2, 3)).toBe(5); + }); +}); diff --git a/e2e/coverage-projects/packages/add/package.json b/e2e/coverage-projects/packages/add/package.json new file mode 100644 index 000000000000..9e9b3434b398 --- /dev/null +++ b/e2e/coverage-projects/packages/add/package.json @@ -0,0 +1,11 @@ +{ + "name": "add", + "private": true, + "jest": { + "collectCoverage": true, + "collectCoverageFrom": [ + "!**.json", + "!/coverage/**" + ] + } +} diff --git a/e2e/coverage-projects/packages/mul/index.js b/e2e/coverage-projects/packages/mul/index.js new file mode 100644 index 000000000000..9a4a09c4e52d --- /dev/null +++ b/e2e/coverage-projects/packages/mul/index.js @@ -0,0 +1,8 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +module.exports = (x, y) => x * y; diff --git a/e2e/coverage-projects/packages/mul/index.test.js b/e2e/coverage-projects/packages/mul/index.test.js new file mode 100644 index 000000000000..52fa7671282a --- /dev/null +++ b/e2e/coverage-projects/packages/mul/index.test.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +const mul = require('.'); + +describe('mul', () => { + it('should multiply correctly', () => { + expect(mul(2, 3)).toBe(6); + }); +}); diff --git a/e2e/coverage-projects/packages/mul/other_file.js b/e2e/coverage-projects/packages/mul/other_file.js new file mode 100644 index 000000000000..ee5f8c2515f5 --- /dev/null +++ b/e2e/coverage-projects/packages/mul/other_file.js @@ -0,0 +1,8 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +module.exports = () => 'hello'; diff --git a/e2e/coverage-projects/packages/mul/other_file.test.js b/e2e/coverage-projects/packages/mul/other_file.test.js new file mode 100644 index 000000000000..6bc58beb35d2 --- /dev/null +++ b/e2e/coverage-projects/packages/mul/other_file.test.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +const hello = require('./other_file'); + +describe('other_file', () => { + it('should output hello', () => { + expect(hello()).toBe('hello'); + }); +}); diff --git a/e2e/coverage-projects/packages/mul/package.json b/e2e/coverage-projects/packages/mul/package.json new file mode 100644 index 000000000000..160942bf5654 --- /dev/null +++ b/e2e/coverage-projects/packages/mul/package.json @@ -0,0 +1,12 @@ +{ + "name": "mul", + "private": true, + "jest": { + "collectCoverage": true, + "collectCoverageFrom": [ + "!**.json", + "!/coverage/**", + "!/index.js" + ] + } +} diff --git a/e2e/coverage-projects/yarn.lock b/e2e/coverage-projects/yarn.lock new file mode 100644 index 000000000000..fb57ccd13afb --- /dev/null +++ b/e2e/coverage-projects/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + +