Skip to content

Commit

Permalink
added e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Mar 25, 2020
1 parent 6976680 commit 4b36c97
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 0 deletions.
13 changes: 13 additions & 0 deletions e2e/__tests__/__snapshots__/coverageProjects.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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 |
----------------|---------|----------|---------|---------|-------------------
`;
35 changes: 35 additions & 0 deletions e2e/__tests__/coverageProjects.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
2 changes: 2 additions & 0 deletions e2e/coverage-projects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
yarn-error.log
12 changes: 12 additions & 0 deletions e2e/coverage-projects/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"private": true,
"workspaces": {
"packages": [
"packages/*"
]
},
"jest": {
"collectCoverage": true,
"projects": ["packages/*"]
}
}
8 changes: 8 additions & 0 deletions e2e/coverage-projects/packages/add/index.js
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions e2e/coverage-projects/packages/add/index.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
11 changes: 11 additions & 0 deletions e2e/coverage-projects/packages/add/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "add",
"private": true,
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"!**.json",
"!<rootDir>/coverage/**"
]
}
}
8 changes: 8 additions & 0 deletions e2e/coverage-projects/packages/mul/index.js
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions e2e/coverage-projects/packages/mul/index.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
8 changes: 8 additions & 0 deletions e2e/coverage-projects/packages/mul/other_file.js
Original file line number Diff line number Diff line change
@@ -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';
14 changes: 14 additions & 0 deletions e2e/coverage-projects/packages/mul/other_file.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
12 changes: 12 additions & 0 deletions e2e/coverage-projects/packages/mul/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "mul",
"private": true,
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"!**.json",
"!<rootDir>/coverage/**",
"!<rootDir>/index.js"
]
}
}
4 changes: 4 additions & 0 deletions e2e/coverage-projects/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


0 comments on commit 4b36c97

Please sign in to comment.