From 4bc5413fea9ee31b3034b5d990ae6afdc7ca6b99 Mon Sep 17 00:00:00 2001 From: rostog Date: Thu, 31 Jan 2019 11:50:07 +0100 Subject: [PATCH 1/7] copied integration tests --- e2e/__tests__/moduleNameMapper.test.js | 9 ++++++++- .../__tests__/storage/track/Track.test.js | 7 +++++++ .../__tests__/storage/track/TrackExpected.test.js | 7 +++++++ e2e/module-name-mapper-mock/package.json | 8 ++++++++ e2e/module-name-mapper-mock/storage/track/Track.js | 8 ++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js create mode 100644 e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js create mode 100644 e2e/module-name-mapper-mock/package.json create mode 100644 e2e/module-name-mapper-mock/storage/track/Track.js diff --git a/e2e/__tests__/moduleNameMapper.test.js b/e2e/__tests__/moduleNameMapper.test.js index 969b387372ed..7b0e823cc958 100644 --- a/e2e/__tests__/moduleNameMapper.test.js +++ b/e2e/__tests__/moduleNameMapper.test.js @@ -7,7 +7,7 @@ * @flow */ -import runJest from '../runJest'; +import runJest, {json as runWithJson} from '../runJest'; import {extractSummary} from '../Utils'; import {wrap} from 'jest-snapshot-serializer-raw'; @@ -28,3 +28,10 @@ test('moduleNameMapper correct configuration', () => { expect(status).toBe(0); expect(wrap(rest)).toMatchSnapshot(); }); + +test('moduleNameMapper with mocking', () => { + const {json} = runWithJson('module-name-mapper-mock'); + console.log(json); + expect(json.numTotalTests).toBe(2); + expect(json.success).toBe(true); +}); diff --git a/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js b/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js new file mode 100644 index 000000000000..9f45c9c7054f --- /dev/null +++ b/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js @@ -0,0 +1,7 @@ +const {Track} = require('../../../src/storage/track/Track'); +jest.mock('@@storage/track/Track'); + +test('relative import', () => { + const track = new Track(); + expect(track.someRandomFunction).not.toBeCalled(); +}); diff --git a/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js b/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js new file mode 100644 index 000000000000..f4751829f3e9 --- /dev/null +++ b/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js @@ -0,0 +1,7 @@ +const {Track} = require('@@storage/track/Track'); +jest.mock('@@storage/track/Track'); + +test('through moduleNameMapper', () => { + const track = new Track(); + expect(track.someRandomFunction).not.toBeCalled(); +}); diff --git a/e2e/module-name-mapper-mock/package.json b/e2e/module-name-mapper-mock/package.json new file mode 100644 index 000000000000..ce628609d634 --- /dev/null +++ b/e2e/module-name-mapper-mock/package.json @@ -0,0 +1,8 @@ +{ + "jest": { + "moduleNameMapper": { + "^@@storage/(.*)$": "/src/storage/$1" + }, + "testEnvironment": "node" + } +} \ No newline at end of file diff --git a/e2e/module-name-mapper-mock/storage/track/Track.js b/e2e/module-name-mapper-mock/storage/track/Track.js new file mode 100644 index 000000000000..197a1c0f90a1 --- /dev/null +++ b/e2e/module-name-mapper-mock/storage/track/Track.js @@ -0,0 +1,8 @@ +module.exports.Track = class Track { + constructor() { + /**/ + } + someRandomFunction() { + return 42; + } +}; From 75cf142e91185d871da2221f1582bfda0d92f364 Mon Sep 17 00:00:00 2001 From: rostog Date: Sat, 2 Feb 2019 20:07:51 +0100 Subject: [PATCH 2/7] working version, have to run full tests --- .vscode/launch.json | 18 ++++- .../moduleNameMapper.test.js.snap | 2 +- e2e/__tests__/moduleNameMapper.test.js | 1 - .../{ => src}/storage/track/Track.js | 0 packages/jest-resolve/src/index.js | 12 +++ packages/jest-runtime/src/index.js | 74 +++++++++++-------- 6 files changed, 73 insertions(+), 34 deletions(-) rename e2e/module-name-mapper-mock/{ => src}/storage/track/Track.js (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json index f4106b4f6605..2be26bc54e45 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,13 +4,25 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "type": "node", + "request": "attach", + "name": "Attach", + "port": 9229 + }, { "type": "node", "request": "launch", "name": "Debug Jest with current test file", "program": "${workspaceFolder}/packages/jest-cli/bin/jest.js", - "args": ["--runInBand", "${file}"], - "runtimeArgs": ["-r", "flow-remove-types/register"] + "args": [ + "--runInBand", + "${file}" + ], + "runtimeArgs": [ + "-r", + "flow-remove-types/register" + ] } ] -} +} \ No newline at end of file diff --git a/e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap b/e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap index 9609d706b96c..8bc15ab4df46 100644 --- a/e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap +++ b/e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap @@ -30,6 +30,6 @@ FAIL __tests__/index.js 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:435:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:443:17) at Object.require (index.js:10:1) `; diff --git a/e2e/__tests__/moduleNameMapper.test.js b/e2e/__tests__/moduleNameMapper.test.js index 7b0e823cc958..e768af3e48bc 100644 --- a/e2e/__tests__/moduleNameMapper.test.js +++ b/e2e/__tests__/moduleNameMapper.test.js @@ -31,7 +31,6 @@ test('moduleNameMapper correct configuration', () => { test('moduleNameMapper with mocking', () => { const {json} = runWithJson('module-name-mapper-mock'); - console.log(json); expect(json.numTotalTests).toBe(2); expect(json.success).toBe(true); }); diff --git a/e2e/module-name-mapper-mock/storage/track/Track.js b/e2e/module-name-mapper-mock/src/storage/track/Track.js similarity index 100% rename from e2e/module-name-mapper-mock/storage/track/Track.js rename to e2e/module-name-mapper-mock/src/storage/track/Track.js diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index 94784e8c0b51..e7c56273be90 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -272,6 +272,18 @@ class Resolver { return this._modulePathCache[from]; } + getNormalizedPath( + virtualMocks: BooleanObject, + from: Path, + _moduleName?: ?string, + ) { + const moduleName = _moduleName || ''; + return ( + this._getAbsolutePath(virtualMocks, from, moduleName) || + this._getMockPath(from, moduleName) + ); + } + getModuleID( virtualMocks: BooleanObject, from: Path, diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 7c69e5925152..1f5e4b67bf01 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -16,6 +16,7 @@ import type {Jest, LocalModuleRequire} from 'types/Jest'; import type {ModuleMap} from 'jest-haste-map'; import type {MockFunctionMetadata, ModuleMocker} from 'types/Mock'; import type {SourceMapRegistry} from 'types/SourceMaps'; +import type {ErrorWithCode} from 'types/Errors'; import path from 'path'; import HasteMap from 'jest-haste-map'; @@ -376,7 +377,6 @@ class Runtime { from, moduleName, ); - if (this._isolatedMockRegistry && this._isolatedMockRegistry[moduleID]) { return this._isolatedMockRegistry[moduleID]; } else if (this._mockRegistry[moduleID]) { @@ -389,37 +389,41 @@ class Runtime { return (mockRegistry[moduleID] = this._mockFactories[moduleID]()); } - let manualMock = this._resolver.getMockModule(from, moduleName); + const manualMockOrStub = this._resolver.getMockModule(from, moduleName); let modulePath; - if (manualMock) { - modulePath = this._resolveModule(from, manualMock); + if (manualMockOrStub) { + modulePath = this._resolveModule(from, manualMockOrStub); } else { modulePath = this._resolveModule(from, moduleName); } - // If the actual module file has a __mocks__ dir sitting immediately next - // to it, look to see if there is a manual mock for this file. - // - // subDir1/my_module.js - // subDir1/__mocks__/my_module.js - // subDir2/my_module.js - // subDir2/__mocks__/my_module.js - // - // Where some other module does a relative require into each of the - // respective subDir{1,2} directories and expects a manual mock - // corresponding to that particular my_module.js file. - const moduleDir = path.dirname(modulePath); - const moduleFileName = path.basename(modulePath); - const potentialManualMock = path.join( - moduleDir, - '__mocks__', - moduleFileName, - ); - if (fs.existsSync(potentialManualMock)) { - manualMock = true; - modulePath = potentialManualMock; - } - if (manualMock) { + let isManualMock = manualMockOrStub && this._resolver.getModule(moduleName); + if (!isManualMock) { + // If the actual module file has a __mocks__ dir sitting immediately next + // to it, look to see if there is a manual mock for this file. + // + // subDir1/my_module.js + // subDir1/__mocks__/my_module.js + // subDir2/my_module.js + // subDir2/__mocks__/my_module.js + // + // Where some other module does a relative require into each of the + // respective subDir{1,2} directories and expects a manual mock + // corresponding to that particular my_module.js file. + + const moduleDir = path.dirname(modulePath); + const moduleFileName = path.basename(modulePath); + const potentialManualMock = path.join( + moduleDir, + '__mocks__', + moduleFileName, + ); + if (fs.existsSync(potentialManualMock)) { + isManualMock = true; + modulePath = potentialManualMock; + } + } + if (isManualMock) { const localModule: Module = { children: [], exports: {}, @@ -741,8 +745,20 @@ class Runtime { } _generateMock(from: Path, moduleName: string) { - const modulePath = this._resolveModule(from, moduleName); - + const modulePath = this._resolver.getNormalizedPath( + this._virtualMocks, + from, + moduleName, + ); + if (!modulePath) { + const dirname = path.dirname(from); + const relativePath = path.relative(dirname, from); + const err = new Error( + `Cannot find module '${moduleName}' from '${relativePath || '.'}'`, + ); + (err: ErrorWithCode).code = 'MODULE_NOT_FOUND'; + throw err; + } if (!(modulePath in this._mockMetaDataCache)) { // This allows us to handle circular dependencies while generating an // automock From ca2eb4d137e658a19d1b886423aeaabf7598c131 Mon Sep 17 00:00:00 2001 From: rostog Date: Sun, 3 Feb 2019 11:59:32 +0100 Subject: [PATCH 3/7] final version --- packages/jest-resolve/src/index.js | 12 ------------ packages/jest-runtime/src/index.js | 24 +++++++----------------- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index e7c56273be90..94784e8c0b51 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -272,18 +272,6 @@ class Resolver { return this._modulePathCache[from]; } - getNormalizedPath( - virtualMocks: BooleanObject, - from: Path, - _moduleName?: ?string, - ) { - const moduleName = _moduleName || ''; - return ( - this._getAbsolutePath(virtualMocks, from, moduleName) || - this._getMockPath(from, moduleName) - ); - } - getModuleID( virtualMocks: BooleanObject, from: Path, diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 1f5e4b67bf01..15377f22d74e 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -16,7 +16,6 @@ import type {Jest, LocalModuleRequire} from 'types/Jest'; import type {ModuleMap} from 'jest-haste-map'; import type {MockFunctionMetadata, ModuleMocker} from 'types/Mock'; import type {SourceMapRegistry} from 'types/SourceMaps'; -import type {ErrorWithCode} from 'types/Errors'; import path from 'path'; import HasteMap from 'jest-haste-map'; @@ -296,7 +295,6 @@ class Runtime { moduleName, ); let modulePath; - // Some old tests rely on this mocking behavior. Ideally we'll change this // to be more explicit. const moduleResource = moduleName && this._resolver.getModule(moduleName); @@ -397,7 +395,9 @@ class Runtime { modulePath = this._resolveModule(from, moduleName); } - let isManualMock = manualMockOrStub && this._resolver.getModule(moduleName); + let isManualMock = + manualMockOrStub && + !this._resolver._resolveStubModuleName(from, moduleName); if (!isManualMock) { // If the actual module file has a __mocks__ dir sitting immediately next // to it, look to see if there is a manual mock for this file. @@ -446,6 +446,7 @@ class Runtime { } requireModuleOrMock(from: Path, moduleName: string) { + debugger; try { if (this._shouldMock(from, moduleName)) { return this.requireMock(from, moduleName); @@ -745,20 +746,9 @@ class Runtime { } _generateMock(from: Path, moduleName: string) { - const modulePath = this._resolver.getNormalizedPath( - this._virtualMocks, - from, - moduleName, - ); - if (!modulePath) { - const dirname = path.dirname(from); - const relativePath = path.relative(dirname, from); - const err = new Error( - `Cannot find module '${moduleName}' from '${relativePath || '.'}'`, - ); - (err: ErrorWithCode).code = 'MODULE_NOT_FOUND'; - throw err; - } + const modulePath = + this._resolver._resolveStubModuleName(from, moduleName) || + this._resolver.resolveModule(from, moduleName); if (!(modulePath in this._mockMetaDataCache)) { // This allows us to handle circular dependencies while generating an // automock From 2d899bb994e981a0e1c3f222c6aad175dfd15864 Mon Sep 17 00:00:00 2001 From: rostog Date: Sun, 3 Feb 2019 12:32:46 +0100 Subject: [PATCH 4/7] added additional test --- packages/jest-resolve/src/index.js | 4 ++-- .../__tests__/runtime_gen_mock_from_module.test.js | 14 ++++++++++++++ .../test_root/mapped_module_genMockFromModule.js | 3 +++ packages/jest-runtime/src/index.js | 7 +++---- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 packages/jest-runtime/src/__tests__/test_root/mapped_module_genMockFromModule.js diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index 94784e8c0b51..dd9feb66cea7 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -251,7 +251,7 @@ class Resolver { if (mock) { return mock; } else { - const moduleName = this._resolveStubModuleName(from, name); + const moduleName = this.resolveStubModuleName(from, name); if (moduleName) { return this.getModule(moduleName) || moduleName; } @@ -340,7 +340,7 @@ class Resolver { ); } - _resolveStubModuleName(from: Path, moduleName: string): ?Path { + resolveStubModuleName(from: Path, moduleName: string): ?Path { const dirname = path.dirname(from); const paths = this._options.modulePaths; const extensions = this._options.extensions.slice(); diff --git a/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js b/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js index d76898b32d27..2b3fcd8d9403 100644 --- a/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js @@ -10,6 +10,10 @@ let createRuntime; +const moduleNameMapper = { + 'module/name/(.*)': '/mapped_module_$1.js', +}; + describe('Runtime', () => { beforeEach(() => { createRuntime = require('createRuntime'); @@ -35,6 +39,16 @@ describe('Runtime', () => { expect(mock.fn()).toBe(undefined); expect(module.getModuleStateValue()).toBe(origModuleStateValue); })); + + it('resolves stubbed modules correctly', () => + createRuntime(__filename, {moduleNameMapper}).then(runtime => { + const root = runtime.requireModule(runtime.__mockRootPath); + const mockModule = root.jest.genMockFromModule( + 'module/name/genMockFromModule', + ); + console.log(mockModule); + expect(mockModule.test.mock).toBeTruthy(); + })); }); it('creates mock objects in the right environment', () => diff --git a/packages/jest-runtime/src/__tests__/test_root/mapped_module_genMockFromModule.js b/packages/jest-runtime/src/__tests__/test_root/mapped_module_genMockFromModule.js new file mode 100644 index 000000000000..3137b70cc43e --- /dev/null +++ b/packages/jest-runtime/src/__tests__/test_root/mapped_module_genMockFromModule.js @@ -0,0 +1,3 @@ +module.exports = { + test: () => '42', +}; diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 15377f22d74e..2779ecdc3701 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -397,7 +397,7 @@ class Runtime { let isManualMock = manualMockOrStub && - !this._resolver._resolveStubModuleName(from, moduleName); + !this._resolver.resolveStubModuleName(from, moduleName); if (!isManualMock) { // If the actual module file has a __mocks__ dir sitting immediately next // to it, look to see if there is a manual mock for this file. @@ -446,7 +446,6 @@ class Runtime { } requireModuleOrMock(from: Path, moduleName: string) { - debugger; try { if (this._shouldMock(from, moduleName)) { return this.requireMock(from, moduleName); @@ -747,8 +746,8 @@ class Runtime { _generateMock(from: Path, moduleName: string) { const modulePath = - this._resolver._resolveStubModuleName(from, moduleName) || - this._resolver.resolveModule(from, moduleName); + this._resolver.resolveStubModuleName(from, moduleName) || + this._resolveModule(from, moduleName); if (!(modulePath in this._mockMetaDataCache)) { // This allows us to handle circular dependencies while generating an // automock From d5e5a12019625f6d201ed40f0a1128670e51a018 Mon Sep 17 00:00:00 2001 From: rostog Date: Sun, 3 Feb 2019 12:37:18 +0100 Subject: [PATCH 5/7] removed some dev code --- .vscode/launch.json | 18 +++--------------- .../moduleNameMapper.test.js.snap | 2 +- .../runtime_gen_mock_from_module.test.js | 2 +- packages/jest-runtime/src/index.js | 2 ++ 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 2be26bc54e45..f4106b4f6605 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,25 +4,13 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { - "type": "node", - "request": "attach", - "name": "Attach", - "port": 9229 - }, { "type": "node", "request": "launch", "name": "Debug Jest with current test file", "program": "${workspaceFolder}/packages/jest-cli/bin/jest.js", - "args": [ - "--runInBand", - "${file}" - ], - "runtimeArgs": [ - "-r", - "flow-remove-types/register" - ] + "args": ["--runInBand", "${file}"], + "runtimeArgs": ["-r", "flow-remove-types/register"] } ] -} \ No newline at end of file +} diff --git a/e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap b/e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap index 8bc15ab4df46..9609d706b96c 100644 --- a/e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap +++ b/e2e/__tests__/__snapshots__/moduleNameMapper.test.js.snap @@ -30,6 +30,6 @@ FAIL __tests__/index.js 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:443:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:435:17) at Object.require (index.js:10:1) `; diff --git a/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js b/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js index 2b3fcd8d9403..f6d83e6c642a 100644 --- a/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js @@ -40,7 +40,7 @@ describe('Runtime', () => { expect(module.getModuleStateValue()).toBe(origModuleStateValue); })); - it('resolves stubbed modules correctly', () => + it('resolves mapped modules correctly', () => createRuntime(__filename, {moduleNameMapper}).then(runtime => { const root = runtime.requireModule(runtime.__mockRootPath); const mockModule = root.jest.genMockFromModule( diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 2779ecdc3701..806926f45025 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -295,6 +295,7 @@ class Runtime { moduleName, ); let modulePath; + // Some old tests rely on this mocking behavior. Ideally we'll change this // to be more explicit. const moduleResource = moduleName && this._resolver.getModule(moduleName); @@ -375,6 +376,7 @@ class Runtime { from, moduleName, ); + if (this._isolatedMockRegistry && this._isolatedMockRegistry[moduleID]) { return this._isolatedMockRegistry[moduleID]; } else if (this._mockRegistry[moduleID]) { From e99995224db60cc8dad144c7074229d2624ac8f0 Mon Sep 17 00:00:00 2001 From: rostog Date: Sun, 3 Feb 2019 14:03:45 +0100 Subject: [PATCH 6/7] updated change log and cleaned up code --- CHANGELOG.md | 1 + e2e/module-name-mapper-mock/package.json | 2 +- e2e/module-name-mapper-mock/src/storage/track/Track.js | 3 --- .../src/__tests__/runtime_gen_mock_from_module.test.js | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6077184f0f3..3d47f0537aa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- `[jest-runtime]` Fix for mocks not working with module name mapper ([#7787](https://github.com/facebook/jest/pull/7787)) - `[jest-cli]` Break dependency cycle when using Jest programmatically ([#7707](https://github.com/facebook/jest/pull/7707)) - `[jest-config]` Extract setupFilesAfterEnv from preset ([#7724](https://github.com/facebook/jest/pull/7724)) diff --git a/e2e/module-name-mapper-mock/package.json b/e2e/module-name-mapper-mock/package.json index ce628609d634..8a7b6db67be1 100644 --- a/e2e/module-name-mapper-mock/package.json +++ b/e2e/module-name-mapper-mock/package.json @@ -5,4 +5,4 @@ }, "testEnvironment": "node" } -} \ No newline at end of file +} diff --git a/e2e/module-name-mapper-mock/src/storage/track/Track.js b/e2e/module-name-mapper-mock/src/storage/track/Track.js index 197a1c0f90a1..8a13afaca35d 100644 --- a/e2e/module-name-mapper-mock/src/storage/track/Track.js +++ b/e2e/module-name-mapper-mock/src/storage/track/Track.js @@ -1,7 +1,4 @@ module.exports.Track = class Track { - constructor() { - /**/ - } someRandomFunction() { return 42; } diff --git a/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js b/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js index f6d83e6c642a..818b87eaec97 100644 --- a/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js @@ -46,7 +46,7 @@ describe('Runtime', () => { const mockModule = root.jest.genMockFromModule( 'module/name/genMockFromModule', ); - console.log(mockModule); + expect(mockModule.test.mock).toBeTruthy(); })); }); From 18503b92b5f0e1ef7215fad257c941190357e8c0 Mon Sep 17 00:00:00 2001 From: rostog Date: Sun, 3 Feb 2019 14:14:06 +0100 Subject: [PATCH 7/7] added copyright headers --- .../__tests__/storage/track/Track.test.js | 7 +++++++ .../__tests__/storage/track/TrackExpected.test.js | 7 +++++++ e2e/module-name-mapper-mock/src/storage/track/Track.js | 7 +++++++ .../__tests__/test_root/mapped_module_genMockFromModule.js | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js b/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js index 9f45c9c7054f..2a1737478788 100644 --- a/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js +++ b/e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + const {Track} = require('../../../src/storage/track/Track'); jest.mock('@@storage/track/Track'); diff --git a/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js b/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js index f4751829f3e9..86224f67fe7d 100644 --- a/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js +++ b/e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + const {Track} = require('@@storage/track/Track'); jest.mock('@@storage/track/Track'); diff --git a/e2e/module-name-mapper-mock/src/storage/track/Track.js b/e2e/module-name-mapper-mock/src/storage/track/Track.js index 8a13afaca35d..e91d9a9b047b 100644 --- a/e2e/module-name-mapper-mock/src/storage/track/Track.js +++ b/e2e/module-name-mapper-mock/src/storage/track/Track.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + module.exports.Track = class Track { someRandomFunction() { return 42; diff --git a/packages/jest-runtime/src/__tests__/test_root/mapped_module_genMockFromModule.js b/packages/jest-runtime/src/__tests__/test_root/mapped_module_genMockFromModule.js index 3137b70cc43e..9e23e5b26b30 100644 --- a/packages/jest-runtime/src/__tests__/test_root/mapped_module_genMockFromModule.js +++ b/packages/jest-runtime/src/__tests__/test_root/mapped_module_genMockFromModule.js @@ -1,3 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + module.exports = { test: () => '42', };