Skip to content

Commit

Permalink
e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
eightypop committed Oct 26, 2018
1 parent d75ca3a commit 230fa8f
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 0 deletions.
9 changes: 9 additions & 0 deletions e2e/__tests__/__snapshots__/transform.test.js.snap
Expand Up @@ -26,3 +26,12 @@ All files | 83.33 | 100 | 50 | 80 | |
------------|----------|----------|----------|----------|-------------------|
"
`;

exports[`transformer-config instruments only specific files and collects coverage 1`] = `
"------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------|----------|----------|----------|----------|-------------------|
All files | 83.33 | 100 | 50 | 80 | |
Covered.js | 83.33 | 100 | 50 | 80 | 13 |
------------|----------|----------|----------|----------|-------------------|"
`;
27 changes: 27 additions & 0 deletions e2e/__tests__/transform.test.js
Expand Up @@ -133,3 +133,30 @@ describe('ecmascript-modules-support', () => {
expect(json.numTotalTests).toBeGreaterThanOrEqual(1);
});
});

describe('transformer-config', () => {
const dir = path.resolve(__dirname, '..', 'transform/transformer-config');

beforeEach(() => {
run('yarn', dir);
});

it('runs transpiled code', () => {
// --no-cache because babel can cache stuff and result in false green
const {json} = runWithJson(dir, ['--no-cache']);
console.log(json);
expect(json.success).toBe(true);
expect(json.numTotalTests).toBeGreaterThanOrEqual(1);
});

it('instruments only specific files and collects coverage', () => {
const {stdout} = runJest(dir, ['--coverage', '--no-cache'], {
stripAnsi: true,
});
expect(stdout).toMatch('Covered.js');
expect(stdout).not.toMatch('NotCovered.js');
expect(stdout).not.toMatch('ExcludedFromCoverage.js');
// coverage result should not change
expect(stdout).toMatchSnapshot();
});
});
1 change: 1 addition & 0 deletions e2e/transform/transformer-config/.babelrc
@@ -0,0 +1 @@
{}
12 changes: 12 additions & 0 deletions e2e/transform/transformer-config/NotCovered.js
@@ -0,0 +1,12 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. 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 thisFunctionIsNeverInstrumented = () => null;

module.exports = {
thisFunctionIsNeverInstrumented,
};
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. 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.
*/

'use strict';

require('../this-directory-is-covered/ExcludedFromCoverage');

it('strips flowtypes using babel-jest and config passed to transformer', () => {
const a: string = 'a';
expect(a).toBe('a');
});
25 changes: 25 additions & 0 deletions e2e/transform/transformer-config/package.json
@@ -0,0 +1,25 @@
{
"dependencies": {
"babel-plugin-transform-flow-strip-types": "6.8.0"
},
"jest": {
"collectCoverageOnlyFrom": {
"<rootDir>/this-directory-is-covered/Covered.js": true,
"<rootDir>/this-directory-is-covered/ExcludedFromCoverage.js": true
},
"coveragePathIgnorePatterns": [
"ExcludedFromCoverage"
],
"testEnvironment": "node",
"transformer": {
"\\.js$": [
"babel-jest",
{
"plugins": [
"babel-plugin-transform-flow-strip-types"
]
}
]
}
}
}
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. 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 thisFunctionIsCovered = (): null => null;

thisFunctionIsCovered();

const thisFunctionIsNotCovered = (): void => {
throw new Error('Never Called');
};

module.exports = {
thisFunctionIsCovered,
thisFunctionIsNotCovered,
};
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. 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.
*/

require('./Covered');
require('../NotCovered');

const thisFunctionIsNeverInstrumented = () => null;

module.exports = {
thisFunctionIsNeverInstrumented,
};
34 changes: 34 additions & 0 deletions e2e/transform/transformer-config/yarn.lock
@@ -0,0 +1,34 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


babel-plugin-syntax-flow@^6.8.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d"
integrity sha1-TDqyCiryaqIM0lmVw5jE63AxDI0=

babel-plugin-transform-flow-strip-types@6.8.0:
version "6.8.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.8.0.tgz#2351d85e3a52152e1a55d3f08ae635e21ece17a0"
integrity sha1-I1HYXjpSFS4aVdPwiuY14h7OF6A=
dependencies:
babel-plugin-syntax-flow "^6.8.0"
babel-runtime "^6.0.0"

babel-runtime@^6.0.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.23.0.tgz#0a9489f144de70efb3ce4300accdb329e2fc543b"
integrity sha1-CpSJ8UTecO+zzkMArM2zKeL8VDs=
dependencies:
core-js "^2.4.0"
regenerator-runtime "^0.10.0"

core-js@^2.4.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.4.1.tgz#4de911e667b0eae9124e34254b53aea6fc618d3e"
integrity sha1-TekR5mew6ukSTjQlS1OupvxhjT4=

regenerator-runtime@^0.10.0:
version "0.10.4"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.4.tgz#74cb6598d3ba2eb18694e968a40e2b3b4df9cf93"
integrity sha1-dMtlmNO6LrGGlOlopA4rO035z5M=

0 comments on commit 230fa8f

Please sign in to comment.