From 37a0187a6d005ffebf46f42e7cf81f462c1ddd1f Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Mon, 13 Aug 2018 01:23:10 +0200 Subject: [PATCH] perf: faster tests --- e2e/__cases__/source-maps/echo.spec.ts | 8 - e2e/__cases__/source-maps/echo.ts | 7 - e2e/__cases__/source-maps/main.spec.ts | 23 ++ e2e/__cases__/source-maps/main.ts | 7 + .../__snapshots__/source-map.test.ts.snap | 391 +++++++++--------- e2e/__tests__/source-map.test.ts | 45 +- 6 files changed, 228 insertions(+), 253 deletions(-) delete mode 100644 e2e/__cases__/source-maps/echo.spec.ts delete mode 100644 e2e/__cases__/source-maps/echo.ts create mode 100644 e2e/__cases__/source-maps/main.spec.ts create mode 100644 e2e/__cases__/source-maps/main.ts diff --git a/e2e/__cases__/source-maps/echo.spec.ts b/e2e/__cases__/source-maps/echo.spec.ts deleted file mode 100644 index 86eed8fbd9..0000000000 --- a/e2e/__cases__/source-maps/echo.spec.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { echo } from './echo'; - -describe('echo', () => { - it('echoes', () => { - console.log('WITHIN TEST'); - expect(echo('repeat')).toEqual('repeat'); - }); -}); diff --git a/e2e/__cases__/source-maps/echo.ts b/e2e/__cases__/source-maps/echo.ts deleted file mode 100644 index ebba250674..0000000000 --- a/e2e/__cases__/source-maps/echo.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function echo(shout: string) { - console.log('WITHIN SOURCE'); - if (process.env.__FORCE_FAIL) { - throw new Error('WITHIN SOURCE'); - } - return shout; -} diff --git a/e2e/__cases__/source-maps/main.spec.ts b/e2e/__cases__/source-maps/main.spec.ts new file mode 100644 index 0000000000..239af9e793 --- /dev/null +++ b/e2e/__cases__/source-maps/main.spec.ts @@ -0,0 +1,23 @@ +import { consoleLog, throwError } from './main'; + +describe('console.log()', () => { + test('from sources', () => { + consoleLog(); + expect(true).toBe(true); + }); + test('from tests', () => { + console.log('WITHIN TEST'); + expect(true).toBe(true); + }); +}); + +describe('throw new Error()', () => { + test('throws from sources', () => { + throwError(); + expect(true).toBe(true); + }); + test('throws from tests', () => { + throw new Error('WITHIN TEST'); + expect(true).toBe(true); + }); +}); diff --git a/e2e/__cases__/source-maps/main.ts b/e2e/__cases__/source-maps/main.ts new file mode 100644 index 0000000000..7b5240a2cf --- /dev/null +++ b/e2e/__cases__/source-maps/main.ts @@ -0,0 +1,7 @@ +export function consoleLog() { + console.log('WITHIN SOURCE'); +} + +export function throwError() { + throw new Error('WITHIN SOURCE'); +} diff --git a/e2e/__tests__/__snapshots__/source-map.test.ts.snap b/e2e/__tests__/__snapshots__/source-map.test.ts.snap index 192f4106a7..74b4978535 100644 --- a/e2e/__tests__/__snapshots__/source-map.test.ts.snap +++ b/e2e/__tests__/__snapshots__/source-map.test.ts.snap @@ -1,288 +1,271 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`console.log() should pass reporting correct line number using template "default" 1`] = ` -jest exit code: 0 - ===[ STDOUT ]=================================================================== - console.log echo.spec.ts:5 - WITHIN TEST - - console.log echo.ts:2 - WITHIN SOURCE - ===[ STDERR ]=================================================================== - PASS ./echo.spec.ts - echo - √ echoes - - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ +exports[`using template "default" should have the soure mpas comment 1`] = ` +"\\"use strict\\"; +exports.__esModule = true; +function consoleLog() { + console.log('WITHIN SOURCE'); +} +exports.consoleLog = consoleLog; +function throwError() { + throw new Error('WITHIN SOURCE'); +} +exports.throwError = throwError; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1haW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQTtJQUNFLE9BQU8sQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLENBQUM7QUFDL0IsQ0FBQztBQUZELGdDQUVDO0FBRUQ7SUFDRSxNQUFNLElBQUksS0FBSyxDQUFDLGVBQWUsQ0FBQyxDQUFDO0FBQ25DLENBQUM7QUFGRCxnQ0FFQyJ9" `; -exports[`console.log() should pass reporting correct line number using template "with-babel-6" 1`] = ` -jest exit code: 0 +exports[`using template "default" should report correct line numbers 1`] = ` +jest exit code: 1 ===[ STDOUT ]=================================================================== - console.log echo.spec.ts:5 - WITHIN TEST - - console.log echo.ts:2 + console.log main.ts:2 WITHIN SOURCE - ===[ STDERR ]=================================================================== - PASS ./echo.spec.ts - echo - √ echoes - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`console.log() should pass reporting correct line number using template "with-babel-7" 1`] = ` -jest exit code: 0 - ===[ STDOUT ]=================================================================== - console.log echo.spec.ts:5 + console.log main.spec.ts:9 WITHIN TEST + ===[ STDERR ]=================================================================== + FAIL ./main.spec.ts + console.log() + √ from sources + √ from tests + throw new Error() + × throws from sources + × throws from tests + + ● throw new Error() › throws from sources - console.log echo.ts:2 WITHIN SOURCE - ===[ STDERR ]=================================================================== - PASS ./echo.spec.ts - echo - √ echoes - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`console.log() should pass reporting correct line number using template "with-jest-22" 1`] = ` -jest exit code: 0 - ===[ STDOUT ]=================================================================== - console.log echo.spec.ts:5 + 4 | + 5 | export function throwError() { + > 6 | throw new Error('WITHIN SOURCE'); + | ^ + 7 | } + 8 | + + at Object.throwError (main.ts:6:9) + at Object. (main.spec.ts:16:5) + + ● throw new Error() › throws from tests + WITHIN TEST - console.log echo.ts:2 - WITHIN SOURCE - ===[ STDERR ]=================================================================== - PASS ./echo.spec.ts - echo - √ echoes + 18 | }); + 19 | test('throws from tests', () => { + > 20 | throw new Error('WITHIN TEST'); + | ^ + 21 | expect(true).toBe(true); + 22 | }); + 23 | }); + + at Object. (main.spec.ts:20:11) - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total + Test Suites: 1 failed, 1 total + Tests: 2 failed, 2 passed, 4 total Snapshots: 0 total Time: XXs Ran all test suites. ================================================================================ `; -exports[`debugging should include special comment when using template "default" 1`] = ` -"\\"use strict\\"; -exports.__esModule = true; -function echo(shout) { - console.log('WITHIN SOURCE'); - if (process.env.__FORCE_FAIL) { - throw new Error('WITHIN SOURCE'); - } - return shout; -} -exports.echo = echo; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWNoby5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImVjaG8udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxjQUFxQixLQUFhO0lBQ2hDLE9BQU8sQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLENBQUM7SUFDN0IsSUFBSSxPQUFPLENBQUMsR0FBRyxDQUFDLFlBQVksRUFBRTtRQUM1QixNQUFNLElBQUksS0FBSyxDQUFDLGVBQWUsQ0FBQyxDQUFDO0tBQ2xDO0lBQ0QsT0FBTyxLQUFLLENBQUM7QUFDZixDQUFDO0FBTkQsb0JBTUMifQ==" -`; - -exports[`debugging should include special comment when using template "with-babel-6" 1`] = ` +exports[`using template "with-babel-6" should have the soure mpas comment 1`] = ` "\\"use strict\\"; exports.__esModule = true; -function echo(shout) { +function consoleLog() { console.log('WITHIN SOURCE'); - if (process.env.__FORCE_FAIL) { - throw new Error('WITHIN SOURCE'); - } - return shout; } -exports.echo = echo; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImVjaG8udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsU0FBQSxJQUFBLENBQXFCLEtBQXJCLEVBQWtDO0FBQ2hDLFlBQVEsR0FBUixDQUFZLGVBQVo7QUFDQSxRQUFJLFFBQVEsR0FBUixDQUFZLFlBQWhCLEVBQThCO0FBQzVCLGNBQU0sSUFBSSxLQUFKLENBQVUsZUFBVixDQUFOO0FBQ0Q7QUFDRCxXQUFPLEtBQVA7QUFDRDtBQU5ELFFBQUEsSUFBQSxHQUFBLElBQUEiLCJzb3VyY2VSb290IjoiIn0=" -`; - -exports[`debugging should include special comment when using template "with-babel-7" 1`] = ` -"\\"use strict\\"; - -exports.__esModule = true; - -function echo(shout) { - console.log('WITHIN SOURCE'); - - if (process.env.__FORCE_FAIL) { +exports.consoleLog = consoleLog; +function throwError() { throw new Error('WITHIN SOURCE'); - } - - return shout; -} - -exports.echo = echo; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImVjaG8udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUFBLFNBQUEsSUFBQSxDQUFxQixLQUFyQixFQUFrQztBQUNoQyxFQUFBLE9BQU8sQ0FBQyxHQUFSLENBQVksZUFBWjs7QUFDQSxNQUFJLE9BQU8sQ0FBQyxHQUFSLENBQVksWUFBaEIsRUFBOEI7QUFDNUIsVUFBTSxJQUFJLEtBQUosQ0FBVSxlQUFWLENBQU47QUFDRDs7QUFDRCxTQUFPLEtBQVA7QUFDRDs7QUFORCxPQUFBLENBQUEsSUFBQSxHQUFBLElBQUEiLCJzb3VyY2VSb290IjoiIn0=" -`; - -exports[`debugging should include special comment when using template "with-jest-22" 1`] = ` -"\\"use strict\\"; -exports.__esModule = true; -function echo(shout) { - console.log('WITHIN SOURCE'); - if (process.env.__FORCE_FAIL) { - throw new Error('WITHIN SOURCE'); - } - return shout; } -exports.echo = echo; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWNoby5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImVjaG8udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxjQUFxQixLQUFhO0lBQ2hDLE9BQU8sQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLENBQUM7SUFDN0IsSUFBSSxPQUFPLENBQUMsR0FBRyxDQUFDLFlBQVksRUFBRTtRQUM1QixNQUFNLElBQUksS0FBSyxDQUFDLGVBQWUsQ0FBQyxDQUFDO0tBQ2xDO0lBQ0QsT0FBTyxLQUFLLENBQUM7QUFDZixDQUFDO0FBTkQsb0JBTUMifQ==" +exports.throwError = throwError; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsU0FBQSxVQUFBLEdBQUE7QUFDRSxZQUFRLEdBQVIsQ0FBWSxlQUFaO0FBQ0Q7QUFGRCxRQUFBLFVBQUEsR0FBQSxVQUFBO0FBSUEsU0FBQSxVQUFBLEdBQUE7QUFDRSxVQUFNLElBQUksS0FBSixDQUFVLGVBQVYsQ0FBTjtBQUNEO0FBRkQsUUFBQSxVQUFBLEdBQUEsVUFBQSIsInNvdXJjZVJvb3QiOiIifQ==" `; -exports[`throw new Error() should fail reporting correct line number using template "default" 1`] = ` +exports[`using template "with-babel-6" should report correct line numbers 1`] = ` jest exit code: 1 ===[ STDOUT ]=================================================================== - console.log echo.spec.ts:5 - WITHIN TEST - - console.log echo.ts:2 + console.log main.ts:2 WITHIN SOURCE + + console.log main.spec.ts:9 + WITHIN TEST ===[ STDERR ]=================================================================== - FAIL ./echo.spec.ts - echo - × echoes + FAIL ./main.spec.ts + console.log() + √ from sources + √ from tests + throw new Error() + × throws from sources + × throws from tests - ● echo › echoes + ● throw new Error() › throws from sources WITHIN SOURCE - 2 | console.log('WITHIN SOURCE'); - 3 | if (process.env.__FORCE_FAIL) { - > 4 | throw new Error('WITHIN SOURCE'); - | ^ - 5 | } - 6 | return shout; + 4 | + 5 | export function throwError() { + > 6 | throw new Error('WITHIN SOURCE'); + | ^ 7 | } + 8 | - at Object.echo (echo.ts:4:11) - at Object. (echo.spec.ts:6:12) - - Test Suites: 1 failed, 1 total - Tests: 1 failed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`throw new Error() should fail reporting correct line number using template "with-babel-6" 1`] = ` -jest exit code: 1 - ===[ STDOUT ]=================================================================== - console.log echo.spec.ts:5 - WITHIN TEST - - console.log echo.ts:2 - WITHIN SOURCE - ===[ STDERR ]=================================================================== - FAIL ./echo.spec.ts - echo - × echoes + at Object.throwError (main.ts:6:9) + at Object. (main.spec.ts:16:5) - ● echo › echoes + ● throw new Error() › throws from tests - WITHIN SOURCE + WITHIN TEST - 2 | console.log('WITHIN SOURCE'); - 3 | if (process.env.__FORCE_FAIL) { - > 4 | throw new Error('WITHIN SOURCE'); - | ^ - 5 | } - 6 | return shout; - 7 | } + 18 | }); + 19 | test('throws from tests', () => { + > 20 | throw new Error('WITHIN TEST'); + | ^ + 21 | expect(true).toBe(true); + 22 | }); + 23 | }); - at Object.echo (echo.ts:4:11) - at Object. (echo.spec.ts:6:12) + at Object. (main.spec.ts:20:11) Test Suites: 1 failed, 1 total - Tests: 1 failed, 1 total + Tests: 2 failed, 2 passed, 4 total Snapshots: 0 total Time: XXs Ran all test suites. ================================================================================ `; -exports[`throw new Error() should fail reporting correct line number using template "with-babel-7" 1`] = ` +exports[`using template "with-babel-7" should have the soure mpas comment 1`] = ` +"\\"use strict\\"; + +exports.__esModule = true; + +function consoleLog() { + console.log('WITHIN SOURCE'); +} + +exports.consoleLog = consoleLog; + +function throwError() { + throw new Error('WITHIN SOURCE'); +} + +exports.throwError = throwError; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUFBLFNBQUEsVUFBQSxHQUFBO0FBQ0UsRUFBQSxPQUFPLENBQUMsR0FBUixDQUFZLGVBQVo7QUFDRDs7QUFGRCxPQUFBLENBQUEsVUFBQSxHQUFBLFVBQUE7O0FBSUEsU0FBQSxVQUFBLEdBQUE7QUFDRSxRQUFNLElBQUksS0FBSixDQUFVLGVBQVYsQ0FBTjtBQUNEOztBQUZELE9BQUEsQ0FBQSxVQUFBLEdBQUEsVUFBQSIsInNvdXJjZVJvb3QiOiIifQ==" +`; + +exports[`using template "with-babel-7" should report correct line numbers 1`] = ` jest exit code: 1 ===[ STDOUT ]=================================================================== - console.log echo.spec.ts:5 - WITHIN TEST - - console.log echo.ts:2 + console.log main.ts:2 WITHIN SOURCE + + console.log main.spec.ts:9 + WITHIN TEST ===[ STDERR ]=================================================================== - FAIL ./echo.spec.ts - echo - × echoes + FAIL ./main.spec.ts + console.log() + √ from sources + √ from tests + throw new Error() + × throws from sources + × throws from tests - ● echo › echoes + ● throw new Error() › throws from sources WITHIN SOURCE - 2 | console.log('WITHIN SOURCE'); - 3 | if (process.env.__FORCE_FAIL) { - > 4 | throw new Error('WITHIN SOURCE'); - | ^ - 5 | } - 6 | return shout; + 4 | + 5 | export function throwError() { + > 6 | throw new Error('WITHIN SOURCE'); + | ^ 7 | } + 8 | + + at Object.throwError (main.ts:6:9) + at Object. (main.spec.ts:16:5) + + ● throw new Error() › throws from tests + + WITHIN TEST + + 18 | }); + 19 | test('throws from tests', () => { + > 20 | throw new Error('WITHIN TEST'); + | ^ + 21 | expect(true).toBe(true); + 22 | }); + 23 | }); - at Object.echo (echo.ts:4:11) - at Object. (echo.spec.ts:6:12) + at Object. (main.spec.ts:20:11) Test Suites: 1 failed, 1 total - Tests: 1 failed, 1 total + Tests: 2 failed, 2 passed, 4 total Snapshots: 0 total Time: XXs Ran all test suites. ================================================================================ `; -exports[`throw new Error() should fail reporting correct line number using template "with-jest-22" 1`] = ` +exports[`using template "with-jest-22" should have the soure mpas comment 1`] = ` +"\\"use strict\\"; +exports.__esModule = true; +function consoleLog() { + console.log('WITHIN SOURCE'); +} +exports.consoleLog = consoleLog; +function throwError() { + throw new Error('WITHIN SOURCE'); +} +exports.throwError = throwError; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1haW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQTtJQUNFLE9BQU8sQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLENBQUM7QUFDL0IsQ0FBQztBQUZELGdDQUVDO0FBRUQ7SUFDRSxNQUFNLElBQUksS0FBSyxDQUFDLGVBQWUsQ0FBQyxDQUFDO0FBQ25DLENBQUM7QUFGRCxnQ0FFQyJ9" +`; + +exports[`using template "with-jest-22" should report correct line numbers 1`] = ` jest exit code: 1 ===[ STDOUT ]=================================================================== - console.log echo.spec.ts:5 - WITHIN TEST - - console.log echo.ts:2 + console.log main.ts:2 WITHIN SOURCE + + console.log main.spec.ts:9 + WITHIN TEST ===[ STDERR ]=================================================================== - FAIL ./echo.spec.ts - echo - × echoes + FAIL ./main.spec.ts + console.log() + √ from sources + √ from tests + throw new Error() + × throws from sources + × throws from tests - ● echo › echoes + ● throw new Error() › throws from sources WITHIN SOURCE - 2 | console.log('WITHIN SOURCE'); - 3 | if (process.env.__FORCE_FAIL) { - > 4 | throw new Error('WITHIN SOURCE'); - 5 | } - 6 | return shout; + 4 | + 5 | export function throwError() { + > 6 | throw new Error('WITHIN SOURCE'); 7 | } + 8 | + + at Object.throwError (main.ts:6:9) + at Object. (main.spec.ts:16:5) + + ● throw new Error() › throws from tests + + WITHIN TEST + + 18 | }); + 19 | test('throws from tests', () => { + > 20 | throw new Error('WITHIN TEST'); + 21 | expect(true).toBe(true); + 22 | }); + 23 | }); - at Object.echo (echo.ts:4:11) - at Object. (echo.spec.ts:6:12) + at Object. (main.spec.ts:20:11) Test Suites: 1 failed, 1 total - Tests: 1 failed, 1 total + Tests: 2 failed, 2 passed, 4 total Snapshots: 0 total Time: XXs Ran all test suites. diff --git a/e2e/__tests__/source-map.test.ts b/e2e/__tests__/source-map.test.ts index e5440cb3de..b387596c7c 100644 --- a/e2e/__tests__/source-map.test.ts +++ b/e2e/__tests__/source-map.test.ts @@ -1,46 +1,23 @@ import { configureTestCase } from '../__helpers__/test-case'; import { allPackageSets } from '../__helpers__/templates'; -describe('console.log()', () => { - const testCase = configureTestCase('source-maps', { args: ['--no-cache'] }); - - testCase.runWithTemplates(allPackageSets, 0, (runTest, { templateName }) => { - it(`should pass reporting correct line number using template "${templateName}"`, () => { - const result = runTest(); - expect(result.status).toBe(0); - expect(result).toMatchSnapshot(); - }); - }); +const testCase = configureTestCase('source-maps', { + args: ['--no-cache'], + writeIo: true, }); -describe('throw new Error()', () => { - const testCase = configureTestCase('source-maps', { - args: ['--no-cache'], - env: { __FORCE_FAIL: '1' }, - }); - - testCase.runWithTemplates(allPackageSets, 1, (runTest, { templateName }) => { - it(`should fail reporting correct line number using template "${templateName}"`, () => { - const result = runTest(); +testCase.runWithTemplates(allPackageSets, 1, (runTest, { templateName }) => { + describe(`using template "${templateName}"`, () => { + const result = runTest(); + it(`should report correct line numbers`, () => { expect(result.status).toBe(1); expect(result).toMatchSnapshot(); }); - }); -}); -// when there are some issues with debugging, it's usually becasue source mpas are not inlined -// and the debugger cannot find the line where to go -describe('debugging', () => { - // tslint:disable-next-line:max-line-length - const testCase = configureTestCase('source-maps', { - args: ['--no-cache'], - writeIo: true, - }); - testCase.runWithTemplates(allPackageSets, 0, (runTest, { templateName }) => { - it(`should include special comment when using template "${templateName}"`, () => { - const result = runTest(); - expect(result.status).toBe(0); - expect(result.ioDataFor('echo.ts').out).toMatchSnapshot(); + // when there are some issues with debugging, it's usually becasue source mpas are not inlined + // and the debugger cannot find the line where to go + it(`should have the soure mpas comment`, () => { + expect(result.ioDataFor('main.ts').out).toMatchSnapshot(); }); }); });