From 7508200362236eb128508c3be35b04b4124f85db Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Sun, 14 May 2017 20:08:03 +0200 Subject: [PATCH 01/27] Fixes issue-1888 --- packages/jest-resolve/src/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index 0feb1008698d..f6316bdc71fa 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -16,6 +16,8 @@ import path from 'path'; import nodeModulesPaths from 'resolve/lib/node-modules-paths'; import isBuiltinModule from 'is-builtin-module'; import defaultResolver from './default_resolver.js'; +import chalk from 'chalk'; +import {ValidationError} from 'jest-validate'; type ResolverConfig = {| browser?: boolean, @@ -331,7 +333,8 @@ class Resolver { (_, index) => matches[parseInt(index, 10)], ); } - return ( + + const module = this.getModule(moduleName) || Resolver.findNodeModule(moduleName, { basedir: dirname, @@ -339,8 +342,14 @@ class Resolver { extensions, moduleDirectory, paths, - }) - ); + }); + if (!module) { + throw new ValidationError( + 'Configuration error', + `Unknown module in configuration option ${chalk.bold('moduleNameMapper')}\nPlease check: ${regex.toString()}: ${chalk.bold(moduleName)}`, + ); + } + return module; } } } From 0ffa9ca4fae763659f9890f62b10e617eaa019c1 Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Sun, 14 May 2017 20:40:07 +0200 Subject: [PATCH 02/27] Prettier fix and chalk to package.json dependencies --- packages/jest-resolve/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index 265e53bd4665..03d24c27bc03 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -9,6 +9,7 @@ "main": "build/index.js", "dependencies": { "browser-resolve": "^1.11.2", + "chalk": "^1.1.3", "is-builtin-module": "^1.0.0", "resolve": "^1.3.2" }, From c7a412ff764f38a0cdfc83276f7a035840b22c06 Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 09:24:06 +0200 Subject: [PATCH 03/27] Added integration test --- .../__tests__/modulenamemapper-test.js | 23 +++++++++++++++++++ .../__mocks__/styleMock.js | 1 + .../__tests__/index.js | 17 ++++++++++++++ .../moduleNameMapper-correct-config/index.js | 14 +++++++++++ .../package.json | 7 ++++++ .../moduleNameMapper-correct-config/style.css | 0 .../__tests__/index.js | 17 ++++++++++++++ .../moduleNameMapper-wrong-config/index.js | 14 +++++++++++ .../package.json | 7 ++++++ .../moduleNameMapper-wrong-config/style.css | 0 10 files changed, 100 insertions(+) create mode 100644 integration_tests/__tests__/modulenamemapper-test.js create mode 100644 integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js create mode 100644 integration_tests/moduleNameMapper-correct-config/__tests__/index.js create mode 100644 integration_tests/moduleNameMapper-correct-config/index.js create mode 100644 integration_tests/moduleNameMapper-correct-config/package.json create mode 100644 integration_tests/moduleNameMapper-correct-config/style.css create mode 100644 integration_tests/moduleNameMapper-wrong-config/__tests__/index.js create mode 100644 integration_tests/moduleNameMapper-wrong-config/index.js create mode 100644 integration_tests/moduleNameMapper-wrong-config/package.json create mode 100644 integration_tests/moduleNameMapper-wrong-config/style.css diff --git a/integration_tests/__tests__/modulenamemapper-test.js b/integration_tests/__tests__/modulenamemapper-test.js new file mode 100644 index 000000000000..62ce91b3f702 --- /dev/null +++ b/integration_tests/__tests__/modulenamemapper-test.js @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @emails oncall+jsinfra + */ +'use strict'; + +const runJest = require('../runJest'); + +test('moduleNameMapper wrong configuration', () => { + const result = runJest('moduleNameMapper-wrong-config'); + // Should fail because that wrong configuration will throw + expect(result.status).toBe(1); +}); + +test('moduleNameMapper correct configuration', () => { + const result = runJest('moduleNameMapper-correct-config'); + expect(result.status).toBe(0); +}); diff --git a/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js b/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js new file mode 100644 index 000000000000..f053ebf7976e --- /dev/null +++ b/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js new file mode 100644 index 000000000000..4123790c227a --- /dev/null +++ b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + +jest.mock('../'); +const importedFn = require('../'); + +test('moduleNameMapping correct configuration', () => { + importedFn(); + expect(importedFn.mock.calls.length).toBe(1); +}); diff --git a/integration_tests/moduleNameMapper-correct-config/index.js b/integration_tests/moduleNameMapper-correct-config/index.js new file mode 100644 index 000000000000..459cb4e4bf89 --- /dev/null +++ b/integration_tests/moduleNameMapper-correct-config/index.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + */ + +'use strict'; +// Inlcude style so moduleNameMapping triggers +const style = require('./style.css'); +module.exports = () => {}; diff --git a/integration_tests/moduleNameMapper-correct-config/package.json b/integration_tests/moduleNameMapper-correct-config/package.json new file mode 100644 index 000000000000..15b2798ef177 --- /dev/null +++ b/integration_tests/moduleNameMapper-correct-config/package.json @@ -0,0 +1,7 @@ +{ + "jest": { + "moduleNameMapper": { + "\\.(css|less)$": "./__mocks__/styleMock.js" + } + } + } \ No newline at end of file diff --git a/integration_tests/moduleNameMapper-correct-config/style.css b/integration_tests/moduleNameMapper-correct-config/style.css new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js new file mode 100644 index 000000000000..67425cbb5d84 --- /dev/null +++ b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + +jest.mock('../'); +const importedFn = require('../'); + +test('moduleNameMapping wrong configuration', () => { + importedFn(); + expect(importedFn.mock.calls.length).toBe(1); +}); diff --git a/integration_tests/moduleNameMapper-wrong-config/index.js b/integration_tests/moduleNameMapper-wrong-config/index.js new file mode 100644 index 000000000000..459cb4e4bf89 --- /dev/null +++ b/integration_tests/moduleNameMapper-wrong-config/index.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + */ + +'use strict'; +// Inlcude style so moduleNameMapping triggers +const style = require('./style.css'); +module.exports = () => {}; diff --git a/integration_tests/moduleNameMapper-wrong-config/package.json b/integration_tests/moduleNameMapper-wrong-config/package.json new file mode 100644 index 000000000000..8a2858414c78 --- /dev/null +++ b/integration_tests/moduleNameMapper-wrong-config/package.json @@ -0,0 +1,7 @@ +{ + "jest": { + "moduleNameMapper": { + "\\.(css|less)$": "module-that-dont-exist" + } + } + } \ No newline at end of file diff --git a/integration_tests/moduleNameMapper-wrong-config/style.css b/integration_tests/moduleNameMapper-wrong-config/style.css new file mode 100644 index 000000000000..e69de29bb2d1 From 6148367cbc35ac0f23cff50e97e8c8e79a27afe7 Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 20:59:23 +0200 Subject: [PATCH 04/27] Refactored test to use snapshot --- .../moduleNameMapper-test.js.snap | 26 +++++++++++++++++ .../__tests__/modulenamemapper-test.js | 28 ++++++++----------- .../__mocks__/styleMock.js | 9 ++++++ .../__tests__/index.js | 6 +--- .../moduleNameMapper-correct-config/index.js | 3 +- .../package.json | 2 +- .../__tests__/index.js | 6 +--- .../moduleNameMapper-wrong-config/index.js | 5 ++-- .../package.json | 2 +- 9 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap diff --git a/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap b/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap new file mode 100644 index 000000000000..cd38a0ca018c --- /dev/null +++ b/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`moduleNameMapper correct configuration 1`] = ` +" PASS __tests__/index.js + ✓ moduleNameMapping correct configuration + +" +`; + +exports[`moduleNameMapper wrong configuration 1`] = ` +" FAIL __tests__/index.js + ● Test suite failed to run + + Configuration error: + + Unknown module in configuration option moduleNameMapper + Please check: /\\\\.(css|less)$/: module-that-dont-exist + + Configuration error: + + Unknown module in configuration option moduleNameMapper + Please check: /\\\\.(css|less)$/: module-that-dont-exist + + +" +`; diff --git a/integration_tests/__tests__/modulenamemapper-test.js b/integration_tests/__tests__/modulenamemapper-test.js index 62ce91b3f702..d0fdeff4b202 100644 --- a/integration_tests/__tests__/modulenamemapper-test.js +++ b/integration_tests/__tests__/modulenamemapper-test.js @@ -1,23 +1,19 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails oncall+jsinfra - */ -'use strict'; - const runJest = require('../runJest'); +const {extractSummary} = require('../utils'); test('moduleNameMapper wrong configuration', () => { - const result = runJest('moduleNameMapper-wrong-config'); - // Should fail because that wrong configuration will throw - expect(result.status).toBe(1); + const {stderr, status} = runJest('moduleNameMapper-wrong-config'); + const {summary, rest} = extractSummary(stderr); + + expect(status).toBe(1); + expect(rest).toMatchSnapshot(); + }); test('moduleNameMapper correct configuration', () => { - const result = runJest('moduleNameMapper-correct-config'); - expect(result.status).toBe(0); + const {stderr, status} = runJest('moduleNameMapper-correct-config'); + const {summary, rest} = extractSummary(stderr); + + expect(status).toBe(0); + expect(rest).toMatchSnapshot(); }); diff --git a/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js b/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js index f053ebf7976e..d792d512e5bb 100644 --- a/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js +++ b/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js @@ -1 +1,10 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; module.exports = {}; diff --git a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js index 4123790c227a..e660a26c5904 100644 --- a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js +++ b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js @@ -6,12 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -'use strict'; - -jest.mock('../'); const importedFn = require('../'); test('moduleNameMapping correct configuration', () => { - importedFn(); - expect(importedFn.mock.calls.length).toBe(1); + expect(importedFn).toBeDefined(); }); diff --git a/integration_tests/moduleNameMapper-correct-config/index.js b/integration_tests/moduleNameMapper-correct-config/index.js index 459cb4e4bf89..a53d531606c3 100644 --- a/integration_tests/moduleNameMapper-correct-config/index.js +++ b/integration_tests/moduleNameMapper-correct-config/index.js @@ -5,10 +5,9 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * - * @flow */ 'use strict'; // Inlcude style so moduleNameMapping triggers const style = require('./style.css'); -module.exports = () => {}; +module.exports = () => 'test'; diff --git a/integration_tests/moduleNameMapper-correct-config/package.json b/integration_tests/moduleNameMapper-correct-config/package.json index 15b2798ef177..7acd3480d04e 100644 --- a/integration_tests/moduleNameMapper-correct-config/package.json +++ b/integration_tests/moduleNameMapper-correct-config/package.json @@ -4,4 +4,4 @@ "\\.(css|less)$": "./__mocks__/styleMock.js" } } - } \ No newline at end of file +} diff --git a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js index 67425cbb5d84..bd692671721b 100644 --- a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js @@ -6,12 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -'use strict'; - -jest.mock('../'); const importedFn = require('../'); test('moduleNameMapping wrong configuration', () => { - importedFn(); - expect(importedFn.mock.calls.length).toBe(1); + expect(importedFn).toBeDefined(); }); diff --git a/integration_tests/moduleNameMapper-wrong-config/index.js b/integration_tests/moduleNameMapper-wrong-config/index.js index 459cb4e4bf89..82cc497a9d21 100644 --- a/integration_tests/moduleNameMapper-wrong-config/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/index.js @@ -4,11 +4,10 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. - * - * @flow + * */ 'use strict'; // Inlcude style so moduleNameMapping triggers const style = require('./style.css'); -module.exports = () => {}; +module.exports = () => 'test'; diff --git a/integration_tests/moduleNameMapper-wrong-config/package.json b/integration_tests/moduleNameMapper-wrong-config/package.json index 8a2858414c78..4c4c4f63af0d 100644 --- a/integration_tests/moduleNameMapper-wrong-config/package.json +++ b/integration_tests/moduleNameMapper-wrong-config/package.json @@ -4,4 +4,4 @@ "\\.(css|less)$": "module-that-dont-exist" } } - } \ No newline at end of file +} From 1638f31f4816c4beeae3766e5d72f867269ad6ab Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 21:06:51 +0200 Subject: [PATCH 05/27] Rename to camelCase --- .../{modulenamemapper-test.js => moduleNameMapper-test.js} | 1 - 1 file changed, 1 deletion(-) rename integration_tests/__tests__/{modulenamemapper-test.js => moduleNameMapper-test.js} (99%) diff --git a/integration_tests/__tests__/modulenamemapper-test.js b/integration_tests/__tests__/moduleNameMapper-test.js similarity index 99% rename from integration_tests/__tests__/modulenamemapper-test.js rename to integration_tests/__tests__/moduleNameMapper-test.js index d0fdeff4b202..971811d0a3e0 100644 --- a/integration_tests/__tests__/modulenamemapper-test.js +++ b/integration_tests/__tests__/moduleNameMapper-test.js @@ -7,7 +7,6 @@ test('moduleNameMapper wrong configuration', () => { expect(status).toBe(1); expect(rest).toMatchSnapshot(); - }); test('moduleNameMapper correct configuration', () => { From c4ec69c46f7ff230fbda588f982448a40a26b60b Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 21:24:56 +0200 Subject: [PATCH 06/27] Fixed lint warnings --- integration_tests/__tests__/moduleNameMapper-test.js | 4 ++-- integration_tests/moduleNameMapper-correct-config/index.js | 2 +- integration_tests/moduleNameMapper-wrong-config/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integration_tests/__tests__/moduleNameMapper-test.js b/integration_tests/__tests__/moduleNameMapper-test.js index 971811d0a3e0..eb6990fdfece 100644 --- a/integration_tests/__tests__/moduleNameMapper-test.js +++ b/integration_tests/__tests__/moduleNameMapper-test.js @@ -3,7 +3,7 @@ const {extractSummary} = require('../utils'); test('moduleNameMapper wrong configuration', () => { const {stderr, status} = runJest('moduleNameMapper-wrong-config'); - const {summary, rest} = extractSummary(stderr); + const {rest} = extractSummary(stderr); expect(status).toBe(1); expect(rest).toMatchSnapshot(); @@ -11,7 +11,7 @@ test('moduleNameMapper wrong configuration', () => { test('moduleNameMapper correct configuration', () => { const {stderr, status} = runJest('moduleNameMapper-correct-config'); - const {summary, rest} = extractSummary(stderr); + const {rest} = extractSummary(stderr); expect(status).toBe(0); expect(rest).toMatchSnapshot(); diff --git a/integration_tests/moduleNameMapper-correct-config/index.js b/integration_tests/moduleNameMapper-correct-config/index.js index a53d531606c3..1e0a57ed1a89 100644 --- a/integration_tests/moduleNameMapper-correct-config/index.js +++ b/integration_tests/moduleNameMapper-correct-config/index.js @@ -9,5 +9,5 @@ 'use strict'; // Inlcude style so moduleNameMapping triggers -const style = require('./style.css'); +require('./style.css'); module.exports = () => 'test'; diff --git a/integration_tests/moduleNameMapper-wrong-config/index.js b/integration_tests/moduleNameMapper-wrong-config/index.js index 82cc497a9d21..e545da434421 100644 --- a/integration_tests/moduleNameMapper-wrong-config/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/index.js @@ -9,5 +9,5 @@ 'use strict'; // Inlcude style so moduleNameMapping triggers -const style = require('./style.css'); +require('./style.css'); module.exports = () => 'test'; From a4e5cd9098a0b382fcb6778926ceb2f13c78c487 Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 09:24:06 +0200 Subject: [PATCH 07/27] Added integration test --- .../__tests__/moduleNameMapper-test.js | 26 +++++++++++-------- .../__tests__/index.js | 6 ++++- .../moduleNameMapper-correct-config/index.js | 5 ++-- .../package.json | 3 ++- .../__tests__/index.js | 6 ++++- .../moduleNameMapper-wrong-config/index.js | 7 ++--- .../package.json | 2 +- 7 files changed, 35 insertions(+), 20 deletions(-) diff --git a/integration_tests/__tests__/moduleNameMapper-test.js b/integration_tests/__tests__/moduleNameMapper-test.js index eb6990fdfece..5a20570f0f46 100644 --- a/integration_tests/__tests__/moduleNameMapper-test.js +++ b/integration_tests/__tests__/moduleNameMapper-test.js @@ -1,18 +1,22 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @emails oncall+jsinfra + */ +'use strict'; + const runJest = require('../runJest'); -const {extractSummary} = require('../utils'); test('moduleNameMapper wrong configuration', () => { - const {stderr, status} = runJest('moduleNameMapper-wrong-config'); - const {rest} = extractSummary(stderr); - - expect(status).toBe(1); - expect(rest).toMatchSnapshot(); + const result = runJest('moduleNameMapper-wrong-config'); + expect(result.status).toBe(1); }); test('moduleNameMapper correct configuration', () => { - const {stderr, status} = runJest('moduleNameMapper-correct-config'); - const {rest} = extractSummary(stderr); - - expect(status).toBe(0); - expect(rest).toMatchSnapshot(); + const result = runJest('moduleNameMapper-correct-config'); + expect(result.status).toBe(0); }); diff --git a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js index e660a26c5904..4123790c227a 100644 --- a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js +++ b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js @@ -6,8 +6,12 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + +jest.mock('../'); const importedFn = require('../'); test('moduleNameMapping correct configuration', () => { - expect(importedFn).toBeDefined(); + importedFn(); + expect(importedFn.mock.calls.length).toBe(1); }); diff --git a/integration_tests/moduleNameMapper-correct-config/index.js b/integration_tests/moduleNameMapper-correct-config/index.js index 1e0a57ed1a89..459cb4e4bf89 100644 --- a/integration_tests/moduleNameMapper-correct-config/index.js +++ b/integration_tests/moduleNameMapper-correct-config/index.js @@ -5,9 +5,10 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * + * @flow */ 'use strict'; // Inlcude style so moduleNameMapping triggers -require('./style.css'); -module.exports = () => 'test'; +const style = require('./style.css'); +module.exports = () => {}; diff --git a/integration_tests/moduleNameMapper-correct-config/package.json b/integration_tests/moduleNameMapper-correct-config/package.json index 7acd3480d04e..f384a5d214a7 100644 --- a/integration_tests/moduleNameMapper-correct-config/package.json +++ b/integration_tests/moduleNameMapper-correct-config/package.json @@ -4,4 +4,5 @@ "\\.(css|less)$": "./__mocks__/styleMock.js" } } -} + } + diff --git a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js index bd692671721b..67425cbb5d84 100644 --- a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js @@ -6,8 +6,12 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + +jest.mock('../'); const importedFn = require('../'); test('moduleNameMapping wrong configuration', () => { - expect(importedFn).toBeDefined(); + importedFn(); + expect(importedFn.mock.calls.length).toBe(1); }); diff --git a/integration_tests/moduleNameMapper-wrong-config/index.js b/integration_tests/moduleNameMapper-wrong-config/index.js index e545da434421..459cb4e4bf89 100644 --- a/integration_tests/moduleNameMapper-wrong-config/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/index.js @@ -4,10 +4,11 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. - * + * + * @flow */ 'use strict'; // Inlcude style so moduleNameMapping triggers -require('./style.css'); -module.exports = () => 'test'; +const style = require('./style.css'); +module.exports = () => {}; diff --git a/integration_tests/moduleNameMapper-wrong-config/package.json b/integration_tests/moduleNameMapper-wrong-config/package.json index 4c4c4f63af0d..b10a41824293 100644 --- a/integration_tests/moduleNameMapper-wrong-config/package.json +++ b/integration_tests/moduleNameMapper-wrong-config/package.json @@ -4,4 +4,4 @@ "\\.(css|less)$": "module-that-dont-exist" } } -} + } From e42de450586f028e5e7a0b05b567ce13996fa825 Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 20:59:23 +0200 Subject: [PATCH 08/27] Refactored test to use snapshot --- .../__tests__/moduleNameMapper-test.js | 26 ++++++++----------- .../__tests__/index.js | 6 +---- .../moduleNameMapper-correct-config/index.js | 3 +-- .../package.json | 3 +-- .../__tests__/index.js | 6 +---- .../moduleNameMapper-wrong-config/index.js | 5 ++-- .../package.json | 2 +- 7 files changed, 18 insertions(+), 33 deletions(-) diff --git a/integration_tests/__tests__/moduleNameMapper-test.js b/integration_tests/__tests__/moduleNameMapper-test.js index 5a20570f0f46..971811d0a3e0 100644 --- a/integration_tests/__tests__/moduleNameMapper-test.js +++ b/integration_tests/__tests__/moduleNameMapper-test.js @@ -1,22 +1,18 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails oncall+jsinfra - */ -'use strict'; - const runJest = require('../runJest'); +const {extractSummary} = require('../utils'); test('moduleNameMapper wrong configuration', () => { - const result = runJest('moduleNameMapper-wrong-config'); - expect(result.status).toBe(1); + const {stderr, status} = runJest('moduleNameMapper-wrong-config'); + const {summary, rest} = extractSummary(stderr); + + expect(status).toBe(1); + expect(rest).toMatchSnapshot(); }); test('moduleNameMapper correct configuration', () => { - const result = runJest('moduleNameMapper-correct-config'); - expect(result.status).toBe(0); + const {stderr, status} = runJest('moduleNameMapper-correct-config'); + const {summary, rest} = extractSummary(stderr); + + expect(status).toBe(0); + expect(rest).toMatchSnapshot(); }); diff --git a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js index 4123790c227a..e660a26c5904 100644 --- a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js +++ b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js @@ -6,12 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -'use strict'; - -jest.mock('../'); const importedFn = require('../'); test('moduleNameMapping correct configuration', () => { - importedFn(); - expect(importedFn.mock.calls.length).toBe(1); + expect(importedFn).toBeDefined(); }); diff --git a/integration_tests/moduleNameMapper-correct-config/index.js b/integration_tests/moduleNameMapper-correct-config/index.js index 459cb4e4bf89..a53d531606c3 100644 --- a/integration_tests/moduleNameMapper-correct-config/index.js +++ b/integration_tests/moduleNameMapper-correct-config/index.js @@ -5,10 +5,9 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * - * @flow */ 'use strict'; // Inlcude style so moduleNameMapping triggers const style = require('./style.css'); -module.exports = () => {}; +module.exports = () => 'test'; diff --git a/integration_tests/moduleNameMapper-correct-config/package.json b/integration_tests/moduleNameMapper-correct-config/package.json index f384a5d214a7..7acd3480d04e 100644 --- a/integration_tests/moduleNameMapper-correct-config/package.json +++ b/integration_tests/moduleNameMapper-correct-config/package.json @@ -4,5 +4,4 @@ "\\.(css|less)$": "./__mocks__/styleMock.js" } } - } - +} diff --git a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js index 67425cbb5d84..bd692671721b 100644 --- a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js @@ -6,12 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -'use strict'; - -jest.mock('../'); const importedFn = require('../'); test('moduleNameMapping wrong configuration', () => { - importedFn(); - expect(importedFn.mock.calls.length).toBe(1); + expect(importedFn).toBeDefined(); }); diff --git a/integration_tests/moduleNameMapper-wrong-config/index.js b/integration_tests/moduleNameMapper-wrong-config/index.js index 459cb4e4bf89..82cc497a9d21 100644 --- a/integration_tests/moduleNameMapper-wrong-config/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/index.js @@ -4,11 +4,10 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. - * - * @flow + * */ 'use strict'; // Inlcude style so moduleNameMapping triggers const style = require('./style.css'); -module.exports = () => {}; +module.exports = () => 'test'; diff --git a/integration_tests/moduleNameMapper-wrong-config/package.json b/integration_tests/moduleNameMapper-wrong-config/package.json index b10a41824293..4c4c4f63af0d 100644 --- a/integration_tests/moduleNameMapper-wrong-config/package.json +++ b/integration_tests/moduleNameMapper-wrong-config/package.json @@ -4,4 +4,4 @@ "\\.(css|less)$": "module-that-dont-exist" } } - } +} From a3e9a742a58f2037d29d98143ab3d86f2847d894 Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 21:24:56 +0200 Subject: [PATCH 09/27] Fixed lint warnings --- integration_tests/__tests__/moduleNameMapper-test.js | 4 ++-- integration_tests/moduleNameMapper-correct-config/index.js | 2 +- integration_tests/moduleNameMapper-wrong-config/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integration_tests/__tests__/moduleNameMapper-test.js b/integration_tests/__tests__/moduleNameMapper-test.js index 971811d0a3e0..eb6990fdfece 100644 --- a/integration_tests/__tests__/moduleNameMapper-test.js +++ b/integration_tests/__tests__/moduleNameMapper-test.js @@ -3,7 +3,7 @@ const {extractSummary} = require('../utils'); test('moduleNameMapper wrong configuration', () => { const {stderr, status} = runJest('moduleNameMapper-wrong-config'); - const {summary, rest} = extractSummary(stderr); + const {rest} = extractSummary(stderr); expect(status).toBe(1); expect(rest).toMatchSnapshot(); @@ -11,7 +11,7 @@ test('moduleNameMapper wrong configuration', () => { test('moduleNameMapper correct configuration', () => { const {stderr, status} = runJest('moduleNameMapper-correct-config'); - const {summary, rest} = extractSummary(stderr); + const {rest} = extractSummary(stderr); expect(status).toBe(0); expect(rest).toMatchSnapshot(); diff --git a/integration_tests/moduleNameMapper-correct-config/index.js b/integration_tests/moduleNameMapper-correct-config/index.js index a53d531606c3..1e0a57ed1a89 100644 --- a/integration_tests/moduleNameMapper-correct-config/index.js +++ b/integration_tests/moduleNameMapper-correct-config/index.js @@ -9,5 +9,5 @@ 'use strict'; // Inlcude style so moduleNameMapping triggers -const style = require('./style.css'); +require('./style.css'); module.exports = () => 'test'; diff --git a/integration_tests/moduleNameMapper-wrong-config/index.js b/integration_tests/moduleNameMapper-wrong-config/index.js index 82cc497a9d21..e545da434421 100644 --- a/integration_tests/moduleNameMapper-wrong-config/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/index.js @@ -9,5 +9,5 @@ 'use strict'; // Inlcude style so moduleNameMapping triggers -const style = require('./style.css'); +require('./style.css'); module.exports = () => 'test'; From ae6e2e8a52bdd9809c305fda1229e8484d34921b Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Wed, 17 May 2017 00:41:55 +0200 Subject: [PATCH 10/27] Minor fixes --- .../__tests__/__snapshots__/moduleNameMapper-test.js.snap | 4 ++-- integration_tests/__tests__/moduleNameMapper-test.js | 8 ++++++++ .../moduleNameMapper-correct-config/index.js | 1 - .../moduleNameMapper-correct-config/package.json | 8 ++++---- integration_tests/moduleNameMapper-wrong-config/index.js | 1 - .../moduleNameMapper-wrong-config/package.json | 8 ++++---- packages/jest-resolve/package.json | 1 + 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap b/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap index cd38a0ca018c..d1ffd71395e0 100644 --- a/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap +++ b/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap @@ -14,12 +14,12 @@ exports[`moduleNameMapper wrong configuration 1`] = ` Configuration error: Unknown module in configuration option moduleNameMapper - Please check: /\\\\.(css|less)$/: module-that-dont-exist + Please check: /\\\\.(css|less)$/: no-such-module Configuration error: Unknown module in configuration option moduleNameMapper - Please check: /\\\\.(css|less)$/: module-that-dont-exist + Please check: /\\\\.(css|less)$/: no-such-module " diff --git a/integration_tests/__tests__/moduleNameMapper-test.js b/integration_tests/__tests__/moduleNameMapper-test.js index eb6990fdfece..15ce6945a28c 100644 --- a/integration_tests/__tests__/moduleNameMapper-test.js +++ b/integration_tests/__tests__/moduleNameMapper-test.js @@ -1,3 +1,11 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + const runJest = require('../runJest'); const {extractSummary} = require('../utils'); diff --git a/integration_tests/moduleNameMapper-correct-config/index.js b/integration_tests/moduleNameMapper-correct-config/index.js index 1e0a57ed1a89..5e8877f2bd53 100644 --- a/integration_tests/moduleNameMapper-correct-config/index.js +++ b/integration_tests/moduleNameMapper-correct-config/index.js @@ -8,6 +8,5 @@ */ 'use strict'; -// Inlcude style so moduleNameMapping triggers require('./style.css'); module.exports = () => 'test'; diff --git a/integration_tests/moduleNameMapper-correct-config/package.json b/integration_tests/moduleNameMapper-correct-config/package.json index 7acd3480d04e..bae54df851fe 100644 --- a/integration_tests/moduleNameMapper-correct-config/package.json +++ b/integration_tests/moduleNameMapper-correct-config/package.json @@ -1,7 +1,7 @@ { - "jest": { - "moduleNameMapper": { - "\\.(css|less)$": "./__mocks__/styleMock.js" - } + "jest": { + "moduleNameMapper": { + "\\.(css|less)$": "./__mocks__/styleMock.js" } + } } diff --git a/integration_tests/moduleNameMapper-wrong-config/index.js b/integration_tests/moduleNameMapper-wrong-config/index.js index e545da434421..677b56bb752b 100644 --- a/integration_tests/moduleNameMapper-wrong-config/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/index.js @@ -8,6 +8,5 @@ */ 'use strict'; -// Inlcude style so moduleNameMapping triggers require('./style.css'); module.exports = () => 'test'; diff --git a/integration_tests/moduleNameMapper-wrong-config/package.json b/integration_tests/moduleNameMapper-wrong-config/package.json index 4c4c4f63af0d..59634293724b 100644 --- a/integration_tests/moduleNameMapper-wrong-config/package.json +++ b/integration_tests/moduleNameMapper-wrong-config/package.json @@ -1,7 +1,7 @@ { - "jest": { - "moduleNameMapper": { - "\\.(css|less)$": "module-that-dont-exist" - } + "jest": { + "moduleNameMapper": { + "\\.(css|less)$": "no-such-module" } + } } diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index 03d24c27bc03..d2f8f628ba10 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -11,6 +11,7 @@ "browser-resolve": "^1.11.2", "chalk": "^1.1.3", "is-builtin-module": "^1.0.0", + "jest-validate": "^20.0.1", "resolve": "^1.3.2" }, "devDependencies": { From ee40b2093e8b25cd6e0fb9dbba31ba51834b61d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 17 May 2017 10:02:48 +0200 Subject: [PATCH 11/27] Use strict on integration tests --- integration_tests/__tests__/moduleNameMapper-test.js | 2 ++ .../moduleNameMapper-correct-config/__mocks__/styleMock.js | 1 + .../moduleNameMapper-correct-config/__tests__/index.js | 2 ++ integration_tests/moduleNameMapper-correct-config/index.js | 3 ++- .../moduleNameMapper-wrong-config/__tests__/index.js | 2 ++ integration_tests/moduleNameMapper-wrong-config/index.js | 3 ++- 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/integration_tests/__tests__/moduleNameMapper-test.js b/integration_tests/__tests__/moduleNameMapper-test.js index 15ce6945a28c..356666f5e8e1 100644 --- a/integration_tests/__tests__/moduleNameMapper-test.js +++ b/integration_tests/__tests__/moduleNameMapper-test.js @@ -6,6 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + const runJest = require('../runJest'); const {extractSummary} = require('../utils'); diff --git a/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js b/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js index d792d512e5bb..de50a547e3de 100644 --- a/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js +++ b/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js @@ -7,4 +7,5 @@ */ 'use strict'; + module.exports = {}; diff --git a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js index e660a26c5904..b0f43f7eca11 100644 --- a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js +++ b/integration_tests/moduleNameMapper-correct-config/__tests__/index.js @@ -6,6 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + const importedFn = require('../'); test('moduleNameMapping correct configuration', () => { diff --git a/integration_tests/moduleNameMapper-correct-config/index.js b/integration_tests/moduleNameMapper-correct-config/index.js index 5e8877f2bd53..c48c62617105 100644 --- a/integration_tests/moduleNameMapper-correct-config/index.js +++ b/integration_tests/moduleNameMapper-correct-config/index.js @@ -4,9 +4,10 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. - * */ 'use strict'; + require('./style.css'); + module.exports = () => 'test'; diff --git a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js index bd692671721b..332d28be3043 100644 --- a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js @@ -6,6 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + const importedFn = require('../'); test('moduleNameMapping wrong configuration', () => { diff --git a/integration_tests/moduleNameMapper-wrong-config/index.js b/integration_tests/moduleNameMapper-wrong-config/index.js index 677b56bb752b..c48c62617105 100644 --- a/integration_tests/moduleNameMapper-wrong-config/index.js +++ b/integration_tests/moduleNameMapper-wrong-config/index.js @@ -4,9 +4,10 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. - * */ 'use strict'; + require('./style.css'); + module.exports = () => 'test'; From c8e99b03e4b1fab39a2491dfbd8a9380bdf1053a Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 09:24:06 +0200 Subject: [PATCH 12/27] Added integration test --- ...meMapper-test.js.snap => module_name_mapper.test.js.snap} | 0 .../{moduleNameMapper-test.js => module_name_mapper.test.js} | 5 ++--- .../__mocks__/style_mock.js} | 0 .../__tests__/index.js | 0 .../index.js | 0 .../package.json | 2 +- .../style.css | 0 .../__tests__/index.js | 0 .../index.js | 0 .../package.json | 0 .../style.css | 0 11 files changed, 3 insertions(+), 4 deletions(-) rename integration_tests/__tests__/__snapshots__/{moduleNameMapper-test.js.snap => module_name_mapper.test.js.snap} (100%) rename integration_tests/__tests__/{moduleNameMapper-test.js => module_name_mapper.test.js} (84%) rename integration_tests/{moduleNameMapper-correct-config/__mocks__/styleMock.js => module_name_mapper_correct_config/__mocks__/style_mock.js} (100%) rename integration_tests/{moduleNameMapper-correct-config => module_name_mapper_correct_config}/__tests__/index.js (100%) rename integration_tests/{moduleNameMapper-correct-config => module_name_mapper_correct_config}/index.js (100%) rename integration_tests/{moduleNameMapper-correct-config => module_name_mapper_correct_config}/package.json (50%) rename integration_tests/{moduleNameMapper-correct-config => module_name_mapper_correct_config}/style.css (100%) rename integration_tests/{moduleNameMapper-wrong-config => module_name_mapper_wrong_config}/__tests__/index.js (100%) rename integration_tests/{moduleNameMapper-wrong-config => module_name_mapper_wrong_config}/index.js (100%) rename integration_tests/{moduleNameMapper-wrong-config => module_name_mapper_wrong_config}/package.json (100%) rename integration_tests/{moduleNameMapper-wrong-config => module_name_mapper_wrong_config}/style.css (100%) diff --git a/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap b/integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap similarity index 100% rename from integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap rename to integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap diff --git a/integration_tests/__tests__/moduleNameMapper-test.js b/integration_tests/__tests__/module_name_mapper.test.js similarity index 84% rename from integration_tests/__tests__/moduleNameMapper-test.js rename to integration_tests/__tests__/module_name_mapper.test.js index 356666f5e8e1..c3c6dd6dad82 100644 --- a/integration_tests/__tests__/moduleNameMapper-test.js +++ b/integration_tests/__tests__/module_name_mapper.test.js @@ -5,14 +5,13 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ - 'use strict'; const runJest = require('../runJest'); const {extractSummary} = require('../utils'); test('moduleNameMapper wrong configuration', () => { - const {stderr, status} = runJest('moduleNameMapper-wrong-config'); + const {stderr, status} = runJest('module_name_mapper_wrong_config'); const {rest} = extractSummary(stderr); expect(status).toBe(1); @@ -20,7 +19,7 @@ test('moduleNameMapper wrong configuration', () => { }); test('moduleNameMapper correct configuration', () => { - const {stderr, status} = runJest('moduleNameMapper-correct-config'); + const {stderr, status} = runJest('module_name_mapper_correct_config'); const {rest} = extractSummary(stderr); expect(status).toBe(0); diff --git a/integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js b/integration_tests/module_name_mapper_correct_config/__mocks__/style_mock.js similarity index 100% rename from integration_tests/moduleNameMapper-correct-config/__mocks__/styleMock.js rename to integration_tests/module_name_mapper_correct_config/__mocks__/style_mock.js diff --git a/integration_tests/moduleNameMapper-correct-config/__tests__/index.js b/integration_tests/module_name_mapper_correct_config/__tests__/index.js similarity index 100% rename from integration_tests/moduleNameMapper-correct-config/__tests__/index.js rename to integration_tests/module_name_mapper_correct_config/__tests__/index.js diff --git a/integration_tests/moduleNameMapper-correct-config/index.js b/integration_tests/module_name_mapper_correct_config/index.js similarity index 100% rename from integration_tests/moduleNameMapper-correct-config/index.js rename to integration_tests/module_name_mapper_correct_config/index.js diff --git a/integration_tests/moduleNameMapper-correct-config/package.json b/integration_tests/module_name_mapper_correct_config/package.json similarity index 50% rename from integration_tests/moduleNameMapper-correct-config/package.json rename to integration_tests/module_name_mapper_correct_config/package.json index bae54df851fe..52a664c7c235 100644 --- a/integration_tests/moduleNameMapper-correct-config/package.json +++ b/integration_tests/module_name_mapper_correct_config/package.json @@ -1,7 +1,7 @@ { "jest": { "moduleNameMapper": { - "\\.(css|less)$": "./__mocks__/styleMock.js" + "\\.(css|less)$": "./__mocks__/style_mock.js" } } } diff --git a/integration_tests/moduleNameMapper-correct-config/style.css b/integration_tests/module_name_mapper_correct_config/style.css similarity index 100% rename from integration_tests/moduleNameMapper-correct-config/style.css rename to integration_tests/module_name_mapper_correct_config/style.css diff --git a/integration_tests/moduleNameMapper-wrong-config/__tests__/index.js b/integration_tests/module_name_mapper_wrong_config/__tests__/index.js similarity index 100% rename from integration_tests/moduleNameMapper-wrong-config/__tests__/index.js rename to integration_tests/module_name_mapper_wrong_config/__tests__/index.js diff --git a/integration_tests/moduleNameMapper-wrong-config/index.js b/integration_tests/module_name_mapper_wrong_config/index.js similarity index 100% rename from integration_tests/moduleNameMapper-wrong-config/index.js rename to integration_tests/module_name_mapper_wrong_config/index.js diff --git a/integration_tests/moduleNameMapper-wrong-config/package.json b/integration_tests/module_name_mapper_wrong_config/package.json similarity index 100% rename from integration_tests/moduleNameMapper-wrong-config/package.json rename to integration_tests/module_name_mapper_wrong_config/package.json diff --git a/integration_tests/moduleNameMapper-wrong-config/style.css b/integration_tests/module_name_mapper_wrong_config/style.css similarity index 100% rename from integration_tests/moduleNameMapper-wrong-config/style.css rename to integration_tests/module_name_mapper_wrong_config/style.css From 48e965cac068427df37861eb3e29070b2dbfe8ad Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 20:59:23 +0200 Subject: [PATCH 13/27] Refactored test to use snapshot --- .../moduleNameMapper-test.js.snap | 26 +++++++++++++++++++ .../__tests__/auto_reset_mocks.test.js | 11 -------- .../auto-clear-mocks/with-auto-clear/index.js | 1 - .../without-auto-clear/index.js | 1 - .../__tests__/index.js | 3 +++ .../__tests__/index.js | 3 +++ 6 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap diff --git a/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap b/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap new file mode 100644 index 000000000000..cd38a0ca018c --- /dev/null +++ b/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`moduleNameMapper correct configuration 1`] = ` +" PASS __tests__/index.js + ✓ moduleNameMapping correct configuration + +" +`; + +exports[`moduleNameMapper wrong configuration 1`] = ` +" FAIL __tests__/index.js + ● Test suite failed to run + + Configuration error: + + Unknown module in configuration option moduleNameMapper + Please check: /\\\\.(css|less)$/: module-that-dont-exist + + Configuration error: + + Unknown module in configuration option moduleNameMapper + Please check: /\\\\.(css|less)$/: module-that-dont-exist + + +" +`; diff --git a/integration_tests/__tests__/auto_reset_mocks.test.js b/integration_tests/__tests__/auto_reset_mocks.test.js index 2eb5f57792a2..6ea80faa0467 100644 --- a/integration_tests/__tests__/auto_reset_mocks.test.js +++ b/integration_tests/__tests__/auto_reset_mocks.test.js @@ -1,14 +1,3 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails oncall+jsinfra - */ -'use strict'; - const runJest = require('../runJest'); test('suite with auto-reset', () => { diff --git a/integration_tests/auto-clear-mocks/with-auto-clear/index.js b/integration_tests/auto-clear-mocks/with-auto-clear/index.js index caf03bcf32d8..1fb2500df77f 100644 --- a/integration_tests/auto-clear-mocks/with-auto-clear/index.js +++ b/integration_tests/auto-clear-mocks/with-auto-clear/index.js @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * - * @flow */ module.exports = () => {}; diff --git a/integration_tests/auto-clear-mocks/without-auto-clear/index.js b/integration_tests/auto-clear-mocks/without-auto-clear/index.js index caf03bcf32d8..1fb2500df77f 100644 --- a/integration_tests/auto-clear-mocks/without-auto-clear/index.js +++ b/integration_tests/auto-clear-mocks/without-auto-clear/index.js @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * - * @flow */ module.exports = () => {}; diff --git a/integration_tests/module_name_mapper_correct_config/__tests__/index.js b/integration_tests/module_name_mapper_correct_config/__tests__/index.js index b0f43f7eca11..f9e4138503e1 100644 --- a/integration_tests/module_name_mapper_correct_config/__tests__/index.js +++ b/integration_tests/module_name_mapper_correct_config/__tests__/index.js @@ -6,8 +6,11 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +<<<<<<< c8e99b03e4b1fab39a2491dfbd8a9380bdf1053a:integration_tests/module_name_mapper_correct_config/__tests__/index.js 'use strict'; +======= +>>>>>>> Refactored test to use snapshot:integration_tests/moduleNameMapper-correct-config/__tests__/index.js const importedFn = require('../'); test('moduleNameMapping correct configuration', () => { diff --git a/integration_tests/module_name_mapper_wrong_config/__tests__/index.js b/integration_tests/module_name_mapper_wrong_config/__tests__/index.js index 332d28be3043..30eebcc931f9 100644 --- a/integration_tests/module_name_mapper_wrong_config/__tests__/index.js +++ b/integration_tests/module_name_mapper_wrong_config/__tests__/index.js @@ -6,8 +6,11 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +<<<<<<< c8e99b03e4b1fab39a2491dfbd8a9380bdf1053a:integration_tests/module_name_mapper_wrong_config/__tests__/index.js 'use strict'; +======= +>>>>>>> Refactored test to use snapshot:integration_tests/moduleNameMapper-wrong-config/__tests__/index.js const importedFn = require('../'); test('moduleNameMapping wrong configuration', () => { From c2cefb8859fe5772861288578242e1fa5d36d314 Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 21:24:56 +0200 Subject: [PATCH 14/27] Fixed lint warnings --- .../__tests__/moduleNameMapper-test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 integration_tests/__tests__/moduleNameMapper-test.js diff --git a/integration_tests/__tests__/moduleNameMapper-test.js b/integration_tests/__tests__/moduleNameMapper-test.js new file mode 100644 index 000000000000..eb6990fdfece --- /dev/null +++ b/integration_tests/__tests__/moduleNameMapper-test.js @@ -0,0 +1,18 @@ +const runJest = require('../runJest'); +const {extractSummary} = require('../utils'); + +test('moduleNameMapper wrong configuration', () => { + const {stderr, status} = runJest('moduleNameMapper-wrong-config'); + const {rest} = extractSummary(stderr); + + expect(status).toBe(1); + expect(rest).toMatchSnapshot(); +}); + +test('moduleNameMapper correct configuration', () => { + const {stderr, status} = runJest('moduleNameMapper-correct-config'); + const {rest} = extractSummary(stderr); + + expect(status).toBe(0); + expect(rest).toMatchSnapshot(); +}); From c0ca42901738bfdac3e6d544f53a77d536bc71ca Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 09:24:06 +0200 Subject: [PATCH 15/27] Added integration test --- .../moduleNameMapper-test.js.snap | 26 ------------------- .../__tests__/moduleNameMapper-test.js | 18 ------------- .../__tests__/index.js | 3 --- .../__tests__/index.js | 3 --- 4 files changed, 50 deletions(-) delete mode 100644 integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap delete mode 100644 integration_tests/__tests__/moduleNameMapper-test.js diff --git a/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap b/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap deleted file mode 100644 index cd38a0ca018c..000000000000 --- a/integration_tests/__tests__/__snapshots__/moduleNameMapper-test.js.snap +++ /dev/null @@ -1,26 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`moduleNameMapper correct configuration 1`] = ` -" PASS __tests__/index.js - ✓ moduleNameMapping correct configuration - -" -`; - -exports[`moduleNameMapper wrong configuration 1`] = ` -" FAIL __tests__/index.js - ● Test suite failed to run - - Configuration error: - - Unknown module in configuration option moduleNameMapper - Please check: /\\\\.(css|less)$/: module-that-dont-exist - - Configuration error: - - Unknown module in configuration option moduleNameMapper - Please check: /\\\\.(css|less)$/: module-that-dont-exist - - -" -`; diff --git a/integration_tests/__tests__/moduleNameMapper-test.js b/integration_tests/__tests__/moduleNameMapper-test.js deleted file mode 100644 index eb6990fdfece..000000000000 --- a/integration_tests/__tests__/moduleNameMapper-test.js +++ /dev/null @@ -1,18 +0,0 @@ -const runJest = require('../runJest'); -const {extractSummary} = require('../utils'); - -test('moduleNameMapper wrong configuration', () => { - const {stderr, status} = runJest('moduleNameMapper-wrong-config'); - const {rest} = extractSummary(stderr); - - expect(status).toBe(1); - expect(rest).toMatchSnapshot(); -}); - -test('moduleNameMapper correct configuration', () => { - const {stderr, status} = runJest('moduleNameMapper-correct-config'); - const {rest} = extractSummary(stderr); - - expect(status).toBe(0); - expect(rest).toMatchSnapshot(); -}); diff --git a/integration_tests/module_name_mapper_correct_config/__tests__/index.js b/integration_tests/module_name_mapper_correct_config/__tests__/index.js index f9e4138503e1..b0f43f7eca11 100644 --- a/integration_tests/module_name_mapper_correct_config/__tests__/index.js +++ b/integration_tests/module_name_mapper_correct_config/__tests__/index.js @@ -6,11 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -<<<<<<< c8e99b03e4b1fab39a2491dfbd8a9380bdf1053a:integration_tests/module_name_mapper_correct_config/__tests__/index.js 'use strict'; -======= ->>>>>>> Refactored test to use snapshot:integration_tests/moduleNameMapper-correct-config/__tests__/index.js const importedFn = require('../'); test('moduleNameMapping correct configuration', () => { diff --git a/integration_tests/module_name_mapper_wrong_config/__tests__/index.js b/integration_tests/module_name_mapper_wrong_config/__tests__/index.js index 30eebcc931f9..332d28be3043 100644 --- a/integration_tests/module_name_mapper_wrong_config/__tests__/index.js +++ b/integration_tests/module_name_mapper_wrong_config/__tests__/index.js @@ -6,11 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -<<<<<<< c8e99b03e4b1fab39a2491dfbd8a9380bdf1053a:integration_tests/module_name_mapper_wrong_config/__tests__/index.js 'use strict'; -======= ->>>>>>> Refactored test to use snapshot:integration_tests/moduleNameMapper-wrong-config/__tests__/index.js const importedFn = require('../'); test('moduleNameMapping wrong configuration', () => { From f0238fcaf982c5f35e0e37535f4398e2f18f659e Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Tue, 16 May 2017 20:59:23 +0200 Subject: [PATCH 16/27] Refactored test to use snapshot --- .../__tests__/auto_clear_mocks.test.js | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/integration_tests/__tests__/auto_clear_mocks.test.js b/integration_tests/__tests__/auto_clear_mocks.test.js index 96f87259f9db..eb6990fdfece 100644 --- a/integration_tests/__tests__/auto_clear_mocks.test.js +++ b/integration_tests/__tests__/auto_clear_mocks.test.js @@ -1,22 +1,18 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails oncall+jsinfra - */ -'use strict'; - const runJest = require('../runJest'); +const {extractSummary} = require('../utils'); + +test('moduleNameMapper wrong configuration', () => { + const {stderr, status} = runJest('moduleNameMapper-wrong-config'); + const {rest} = extractSummary(stderr); -test('suite with auto-clear', () => { - const result = runJest('auto-clear-mocks/with-auto-clear'); - expect(result.status).toBe(0); + expect(status).toBe(1); + expect(rest).toMatchSnapshot(); }); -test('suite without auto-clear', () => { - const result = runJest('auto-clear-mocks/without-auto-clear'); - expect(result.status).toBe(0); +test('moduleNameMapper correct configuration', () => { + const {stderr, status} = runJest('moduleNameMapper-correct-config'); + const {rest} = extractSummary(stderr); + + expect(status).toBe(0); + expect(rest).toMatchSnapshot(); }); From 2d4978838df0e4a94f4411ab4df2f2634e67c0ee Mon Sep 17 00:00:00 2001 From: Johan Lindgren Date: Wed, 17 May 2017 00:41:55 +0200 Subject: [PATCH 17/27] Minor fixes --- integration_tests/__tests__/auto_clear_mocks.test.js | 8 ++++++++ .../module_name_mapper_correct_config/index.js | 1 - .../module_name_mapper_wrong_config/index.js | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/integration_tests/__tests__/auto_clear_mocks.test.js b/integration_tests/__tests__/auto_clear_mocks.test.js index eb6990fdfece..15ce6945a28c 100644 --- a/integration_tests/__tests__/auto_clear_mocks.test.js +++ b/integration_tests/__tests__/auto_clear_mocks.test.js @@ -1,3 +1,11 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + const runJest = require('../runJest'); const {extractSummary} = require('../utils'); diff --git a/integration_tests/module_name_mapper_correct_config/index.js b/integration_tests/module_name_mapper_correct_config/index.js index c48c62617105..3d02540ddc0e 100644 --- a/integration_tests/module_name_mapper_correct_config/index.js +++ b/integration_tests/module_name_mapper_correct_config/index.js @@ -7,7 +7,6 @@ */ 'use strict'; - require('./style.css'); module.exports = () => 'test'; diff --git a/integration_tests/module_name_mapper_wrong_config/index.js b/integration_tests/module_name_mapper_wrong_config/index.js index c48c62617105..3d02540ddc0e 100644 --- a/integration_tests/module_name_mapper_wrong_config/index.js +++ b/integration_tests/module_name_mapper_wrong_config/index.js @@ -7,7 +7,6 @@ */ 'use strict'; - require('./style.css'); module.exports = () => 'test'; From 3961af0abd3896f64292c88045a4a96f19c6ef7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 17 May 2017 10:02:48 +0200 Subject: [PATCH 18/27] Use strict on integration tests --- integration_tests/__tests__/auto_clear_mocks.test.js | 2 ++ integration_tests/module_name_mapper_correct_config/index.js | 1 + integration_tests/module_name_mapper_wrong_config/index.js | 1 + 3 files changed, 4 insertions(+) diff --git a/integration_tests/__tests__/auto_clear_mocks.test.js b/integration_tests/__tests__/auto_clear_mocks.test.js index 15ce6945a28c..356666f5e8e1 100644 --- a/integration_tests/__tests__/auto_clear_mocks.test.js +++ b/integration_tests/__tests__/auto_clear_mocks.test.js @@ -6,6 +6,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + const runJest = require('../runJest'); const {extractSummary} = require('../utils'); diff --git a/integration_tests/module_name_mapper_correct_config/index.js b/integration_tests/module_name_mapper_correct_config/index.js index 3d02540ddc0e..c48c62617105 100644 --- a/integration_tests/module_name_mapper_correct_config/index.js +++ b/integration_tests/module_name_mapper_correct_config/index.js @@ -7,6 +7,7 @@ */ 'use strict'; + require('./style.css'); module.exports = () => 'test'; diff --git a/integration_tests/module_name_mapper_wrong_config/index.js b/integration_tests/module_name_mapper_wrong_config/index.js index 3d02540ddc0e..c48c62617105 100644 --- a/integration_tests/module_name_mapper_wrong_config/index.js +++ b/integration_tests/module_name_mapper_wrong_config/index.js @@ -7,6 +7,7 @@ */ 'use strict'; + require('./style.css'); module.exports = () => 'test'; From be6995f33c6a404443c9c18c7691a9f7ecd53a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 27 Jun 2017 22:25:27 +0200 Subject: [PATCH 19/27] Use Error instead of ValidationError to avoid duplicate message --- .../module_name_mapper.test.js.snap | 10 ++++------ packages/jest-resolve/src/index.js | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap b/integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap index d1ffd71395e0..d6895f2ed461 100644 --- a/integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap +++ b/integration_tests/__tests__/__snapshots__/module_name_mapper.test.js.snap @@ -14,13 +14,11 @@ exports[`moduleNameMapper wrong configuration 1`] = ` Configuration error: Unknown module in configuration option moduleNameMapper - Please check: /\\\\.(css|less)$/: no-such-module + Please check: - Configuration error: - - Unknown module in configuration option moduleNameMapper - Please check: /\\\\.(css|less)$/: no-such-module - + \\"moduleNameMapper\\": { + \\"/\\\\.(css|less)$/\\": \\"no-such-module\\" + } " `; diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index f6316bdc71fa..6b4eade2c8e5 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -17,7 +17,6 @@ import nodeModulesPaths from 'resolve/lib/node-modules-paths'; import isBuiltinModule from 'is-builtin-module'; import defaultResolver from './default_resolver.js'; import chalk from 'chalk'; -import {ValidationError} from 'jest-validate'; type ResolverConfig = {| browser?: boolean, @@ -319,8 +318,8 @@ class Resolver { const paths = this._options.modulePaths; const extensions = this._options.extensions; const moduleDirectory = this._options.moduleDirectories; - const moduleNameMapper = this._options.moduleNameMapper; + if (moduleNameMapper) { for (const {moduleName: mappedModuleName, regex} of moduleNameMapper) { if (regex.test(moduleName)) { @@ -344,10 +343,18 @@ class Resolver { paths, }); if (!module) { - throw new ValidationError( - 'Configuration error', - `Unknown module in configuration option ${chalk.bold('moduleNameMapper')}\nPlease check: ${regex.toString()}: ${chalk.bold(moduleName)}`, + const error = new Error( + chalk.red(`${chalk.bold('Configuration error')}: + +Unknown module in configuration option ${chalk.bold('moduleNameMapper')} +Please check: + +"moduleNameMapper": { + "${regex.toString()}": "${chalk.bold(moduleName)}" +}`), ); + error.stack = ''; + throw error; } return module; } From 0859f303544d0e3a6a1a13996ec59bc6e23faede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 27 Jun 2017 22:33:03 +0200 Subject: [PATCH 20/27] Add fb copyright back to auto_reset_mocks test --- integration_tests/__tests__/auto_reset_mocks.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/integration_tests/__tests__/auto_reset_mocks.test.js b/integration_tests/__tests__/auto_reset_mocks.test.js index 6ea80faa0467..e191596cc179 100644 --- a/integration_tests/__tests__/auto_reset_mocks.test.js +++ b/integration_tests/__tests__/auto_reset_mocks.test.js @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @emails oncall+jsinfra + */ + +'use strict'; + const runJest = require('../runJest'); test('suite with auto-reset', () => { From e5bd79d96cd3b154b64ce4eab1a33a93e75848c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 27 Jun 2017 22:34:56 +0200 Subject: [PATCH 21/27] Removed jest-validate dep from jest-resolve --- packages/jest-resolve/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index d2f8f628ba10..03d24c27bc03 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -11,7 +11,6 @@ "browser-resolve": "^1.11.2", "chalk": "^1.1.3", "is-builtin-module": "^1.0.0", - "jest-validate": "^20.0.1", "resolve": "^1.3.2" }, "devDependencies": { From 22f13ed2757b3456423d5177acd8359462462452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 28 Jun 2017 08:31:25 +0200 Subject: [PATCH 22/27] Run prettier --- packages/jest-config/src/__tests__/normalize.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index 8d10cd35eb4a..6e61a522e859 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -837,8 +837,8 @@ describe('preset', () => { }); test('merges with options and moduleNameMapper preset is overridden by options', () => { - // Object initializer not used for properties as a workaround for - // sort-keys eslint rule while specifing properties in + // Object initializer not used for properties as a workaround for + // sort-keys eslint rule while specifing properties in // non-alphabetical order for a better test const moduleNameMapper = {}; moduleNameMapper.e = 'ee'; From 5f4b5b0d95f8284b7e882d05d8766064f0768c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 29 Jun 2017 07:28:54 +0200 Subject: [PATCH 23/27] Revert auto_clear_mocks change --- .../__tests__/auto_clear_mocks.test.js | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/integration_tests/__tests__/auto_clear_mocks.test.js b/integration_tests/__tests__/auto_clear_mocks.test.js index 356666f5e8e1..96f87259f9db 100644 --- a/integration_tests/__tests__/auto_clear_mocks.test.js +++ b/integration_tests/__tests__/auto_clear_mocks.test.js @@ -4,25 +4,19 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. + * + * @emails oncall+jsinfra */ - 'use strict'; const runJest = require('../runJest'); -const {extractSummary} = require('../utils'); -test('moduleNameMapper wrong configuration', () => { - const {stderr, status} = runJest('moduleNameMapper-wrong-config'); - const {rest} = extractSummary(stderr); - - expect(status).toBe(1); - expect(rest).toMatchSnapshot(); +test('suite with auto-clear', () => { + const result = runJest('auto-clear-mocks/with-auto-clear'); + expect(result.status).toBe(0); }); -test('moduleNameMapper correct configuration', () => { - const {stderr, status} = runJest('moduleNameMapper-correct-config'); - const {rest} = extractSummary(stderr); - - expect(status).toBe(0); - expect(rest).toMatchSnapshot(); +test('suite without auto-clear', () => { + const result = runJest('auto-clear-mocks/without-auto-clear'); + expect(result.status).toBe(0); }); From fe24f1add3c26e7327830b6ceb1313266690f289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 29 Jun 2017 07:29:29 +0200 Subject: [PATCH 24/27] Revert auto_reset_mocks change --- integration_tests/__tests__/auto_reset_mocks.test.js | 1 - integration_tests/auto-clear-mocks/with-auto-clear/index.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/__tests__/auto_reset_mocks.test.js b/integration_tests/__tests__/auto_reset_mocks.test.js index e191596cc179..2eb5f57792a2 100644 --- a/integration_tests/__tests__/auto_reset_mocks.test.js +++ b/integration_tests/__tests__/auto_reset_mocks.test.js @@ -7,7 +7,6 @@ * * @emails oncall+jsinfra */ - 'use strict'; const runJest = require('../runJest'); diff --git a/integration_tests/auto-clear-mocks/with-auto-clear/index.js b/integration_tests/auto-clear-mocks/with-auto-clear/index.js index 1fb2500df77f..caf03bcf32d8 100644 --- a/integration_tests/auto-clear-mocks/with-auto-clear/index.js +++ b/integration_tests/auto-clear-mocks/with-auto-clear/index.js @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * + * @flow */ module.exports = () => {}; From f6e5b14ebb18a0394fa9d3c0e8265b2b1adc4bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 29 Jun 2017 07:54:28 +0200 Subject: [PATCH 25/27] Normalize test paths on windows --- integration_tests/__tests__/module_name_mapper.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integration_tests/__tests__/module_name_mapper.test.js b/integration_tests/__tests__/module_name_mapper.test.js index c3c6dd6dad82..0560b1912c2d 100644 --- a/integration_tests/__tests__/module_name_mapper.test.js +++ b/integration_tests/__tests__/module_name_mapper.test.js @@ -9,13 +9,14 @@ const runJest = require('../runJest'); const {extractSummary} = require('../utils'); +const slash = require('slash'); test('moduleNameMapper wrong configuration', () => { const {stderr, status} = runJest('module_name_mapper_wrong_config'); const {rest} = extractSummary(stderr); expect(status).toBe(1); - expect(rest).toMatchSnapshot(); + expect(slash(rest)).toMatchSnapshot(); }); test('moduleNameMapper correct configuration', () => { @@ -23,5 +24,5 @@ test('moduleNameMapper correct configuration', () => { const {rest} = extractSummary(stderr); expect(status).toBe(0); - expect(rest).toMatchSnapshot(); + expect(slash(rest)).toMatchSnapshot(); }); From 7f2ad5a4c7dce2c44e698ae0047503c541e78947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 29 Jun 2017 08:19:04 +0200 Subject: [PATCH 26/27] Don't use slash to normalize summary --- integration_tests/__tests__/module_name_mapper.test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/integration_tests/__tests__/module_name_mapper.test.js b/integration_tests/__tests__/module_name_mapper.test.js index 0560b1912c2d..81a2078bade6 100644 --- a/integration_tests/__tests__/module_name_mapper.test.js +++ b/integration_tests/__tests__/module_name_mapper.test.js @@ -9,14 +9,17 @@ const runJest = require('../runJest'); const {extractSummary} = require('../utils'); -const slash = require('slash'); + +// To pass on Windows +const normalizeSummaryPaths = string => + string.replace('__tests__\\index.js', '__tests__/index.js'); test('moduleNameMapper wrong configuration', () => { const {stderr, status} = runJest('module_name_mapper_wrong_config'); const {rest} = extractSummary(stderr); expect(status).toBe(1); - expect(slash(rest)).toMatchSnapshot(); + expect(normalizeSummaryPaths(rest)).toMatchSnapshot(); }); test('moduleNameMapper correct configuration', () => { @@ -24,5 +27,5 @@ test('moduleNameMapper correct configuration', () => { const {rest} = extractSummary(stderr); expect(status).toBe(0); - expect(slash(rest)).toMatchSnapshot(); + expect(normalizeSummaryPaths(rest)).toMatchSnapshot(); }); From 62952cd8bd92359788d9876949da9976394f57cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 29 Jun 2017 08:26:47 +0200 Subject: [PATCH 27/27] Skip test on windows --- integration_tests/__tests__/module_name_mapper.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integration_tests/__tests__/module_name_mapper.test.js b/integration_tests/__tests__/module_name_mapper.test.js index 81a2078bade6..9338e10fa35a 100644 --- a/integration_tests/__tests__/module_name_mapper.test.js +++ b/integration_tests/__tests__/module_name_mapper.test.js @@ -9,17 +9,17 @@ const runJest = require('../runJest'); const {extractSummary} = require('../utils'); +const skipOnWindows = require('skipOnWindows'); -// To pass on Windows -const normalizeSummaryPaths = string => - string.replace('__tests__\\index.js', '__tests__/index.js'); +// Works on windows, we just need to adjust snapshot test output +skipOnWindows.suite(); test('moduleNameMapper wrong configuration', () => { const {stderr, status} = runJest('module_name_mapper_wrong_config'); const {rest} = extractSummary(stderr); expect(status).toBe(1); - expect(normalizeSummaryPaths(rest)).toMatchSnapshot(); + expect(rest).toMatchSnapshot(); }); test('moduleNameMapper correct configuration', () => { @@ -27,5 +27,5 @@ test('moduleNameMapper correct configuration', () => { const {rest} = extractSummary(stderr); expect(status).toBe(0); - expect(normalizeSummaryPaths(rest)).toMatchSnapshot(); + expect(rest).toMatchSnapshot(); });