-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(utils):
pathsToModuleNameMapper
resolve path mapping with `path…
- Loading branch information
Showing
6 changed files
with
67 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const a = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import * as utils from 'ts-jest/utils' | ||
import { compilerOptions } from './tsconfig.json'; | ||
|
||
test('utils', () => { | ||
expect(Object.keys(utils)).toEqual(['mocked', 'createJestPreset', 'pathsToModuleNameMapper']) | ||
expect(typeof utils.mocked).toBe('function') | ||
expect(typeof utils.createJestPreset).toBe('function') | ||
expect(typeof utils.pathsToModuleNameMapper).toBe('function') | ||
}) | ||
|
||
test('pathsToModuleNameMapper', () => { | ||
expect(utils.pathsToModuleNameMapper(compilerOptions.paths, { prefix: compilerOptions.baseUrl } )).toEqual({'^foo/(.*)$': 'src/foo/$1'}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "src", | ||
"target": "ES5", | ||
"module": "CommonJS", | ||
"resolveJsonModule": true, | ||
"paths": { | ||
"foo/*": ["foo/*"] | ||
} | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
39 changes: 39 additions & 0 deletions
39
src/config/__snapshots__/paths-to-module-name-mapper.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`pathsToModuleNameMapper should convert tsconfig mapping with given prefix: <rootDir>/ 1`] = ` | ||
Object { | ||
"^api/(.*)$": "<rootDir>/src/api/$1", | ||
"^client$": Array [ | ||
"<rootDir>/src/client", | ||
"<rootDir>/src/client/index", | ||
], | ||
"^log$": "<rootDir>/src/utils/log", | ||
"^mocks/(.*)$": "<rootDir>/test/mocks/$1", | ||
"^server$": "<rootDir>/src/server", | ||
"^test/(.*)$": "<rootDir>/test/$1", | ||
"^test/(.*)/mock$": Array [ | ||
"<rootDir>/test/mocks/$1", | ||
"<rootDir>/test/__mocks__/$1", | ||
], | ||
"^util/(.*)$": "<rootDir>/src/utils/$1", | ||
} | ||
`; | ||
exports[`pathsToModuleNameMapper should convert tsconfig mapping with given prefix: foo 1`] = ` | ||
Object { | ||
"^api/(.*)$": "foo/src/api/$1", | ||
"^client$": Array [ | ||
"foo/src/client", | ||
"foo/src/client/index", | ||
], | ||
"^log$": "foo/src/utils/log", | ||
"^mocks/(.*)$": "foo/test/mocks/$1", | ||
"^server$": "foo/src/server", | ||
"^test/(.*)$": "foo/test/$1", | ||
"^test/(.*)/mock$": Array [ | ||
"foo/test/mocks/$1", | ||
"foo/test/__mocks__/$1", | ||
], | ||
"^util/(.*)$": "foo/src/utils/$1", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters