-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transformers): add
path-mapping
custom AST transformer (#1927)
Usage detail see https://kulshekhar.github.io/ts-jest/user/config/astTransformers
- Loading branch information
Showing
33 changed files
with
4,602 additions
and
29 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { getWelcomeMessage } from '@share/foo' | ||
|
||
test('should return welcome message', () => { | ||
const userName = 'github-user' | ||
|
||
expect(getWelcomeMessage(userName)).toEqual(`yolo ${userName}`) | ||
}) |
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,6 @@ | ||
test('should return welcome message', async () => { | ||
const userName = 'github-user' | ||
const foo = await import('@share/foo') | ||
|
||
expect(foo.getWelcomeMessage(userName)).toEqual(`yolo ${userName}`) | ||
}) |
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,7 @@ | ||
import { getWelcomeMessage } from '@share/export' | ||
|
||
test('should return welcome message', async () => { | ||
const userName = '' | ||
|
||
expect(getWelcomeMessage(userName)).toEqual(`yolo ${userName}`) | ||
}) |
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,7 @@ | ||
import foo from '@share/foo' | ||
|
||
test('should return welcome message', () => { | ||
const userName = 'github-user' | ||
|
||
expect(foo(userName)).toBe(`yolo ${userName}`) | ||
}) |
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,7 @@ | ||
import foo = require('@share/foo') | ||
|
||
test('should return welcome message', () => { | ||
const userName = 'github-user' | ||
|
||
expect(foo.getWelcomeMessage(userName)).toEqual(`yolo ${userName}`) | ||
}) |
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,7 @@ | ||
const foo = require('@share/foo') | ||
|
||
test('should return welcome message', () => { | ||
const userName = 'github-user' | ||
|
||
expect(foo.getWelcomeMessage(userName)).toEqual(`yolo ${userName}`) | ||
}) |
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,7 @@ | ||
import * as foo from '@share/foo' | ||
|
||
test('should return welcome message', () => { | ||
const userName = 'github-user' | ||
|
||
expect(foo.getWelcomeMessage(userName)).toEqual(`yolo ${userName}`) | ||
}) |
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,9 @@ | ||
import type { Foo } from '@share/foo' | ||
|
||
test('should work', () => { | ||
const a: Foo = { | ||
bar: 1, | ||
} | ||
|
||
expect(a).toBeTruthy() | ||
}) |
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 { getWelcomeMessage } from '@share/foo' |
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,13 @@ | ||
export function getWelcomeMessage(username: string): string { | ||
return `yolo ${username}`; | ||
} | ||
|
||
function getMessage(username: string) { | ||
return getWelcomeMessage(username) | ||
} | ||
|
||
export interface Foo { | ||
bar: number | ||
} | ||
|
||
export default getMessage |
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,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@share/*": ["share/*"] | ||
} | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
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,4 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testEnvironment: 'node' | ||
} |
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,2 @@ | ||
.idea | ||
node_modules |
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,9 @@ | ||
# A project to demonstrate how to setup `ts-jest` only to work together with `jest` | ||
|
||
## Installation | ||
Run `yarn` to install dependencies | ||
|
||
## Overview about configuration | ||
The project contains: | ||
- A `jest.config.js` which contains config for `ts-jest`. | ||
- A `tsconfig.json` which contains config for `typescript`. |
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,23 @@ | ||
import { isStoreOwner } from './foo'; | ||
import { getWelcomeMessage } from '@share/get-welcome-message'; | ||
import type { Foo } from '@share/typings' | ||
|
||
describe('Test optional chaining', () => { | ||
test(`should work`, () => { | ||
expect(isStoreOwner({ | ||
isStoreOwner: false, | ||
})).toEqual(false) | ||
}) | ||
|
||
test(`test export *`, () => { | ||
expect(getWelcomeMessage('foo')).toEqual('yolo foo') | ||
}) | ||
|
||
test(`test import type`, () => { | ||
const foo: Foo = { | ||
bar: 1, | ||
} | ||
|
||
expect(foo).toBeTruthy() | ||
}) | ||
}); |
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,5 @@ | ||
interface User { | ||
isStoreOwner: boolean | ||
} | ||
|
||
export const isStoreOwner = (user: User) => user?.isStoreOwner; |
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,16 @@ | ||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
/** @typedef {import('ts-jest')} */ | ||
/** @type {import('@jest/types').Config.InitialOptions} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
globals: { | ||
'ts-jest': { | ||
astTransformers: { | ||
before: [ | ||
'ts-jest/dist/transformers/path-mapping' | ||
] | ||
} | ||
} | ||
} | ||
}; |
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 @@ | ||
{ | ||
"name": "ts-jest-example", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/jest": "26.x", | ||
"jest": "26.x", | ||
"ts-jest": "26.x", | ||
"typescript": "~4.0.2" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
e2e/__external-repos__/path-mapping/src/share/get-welcome-message.spec.ts
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,21 @@ | ||
import { getWelcomeMessage } from './get-welcome-message'; | ||
|
||
describe(`getWelcomeMessage()`, (): void => { | ||
let username: string; | ||
|
||
describe(`when the given username is a simple string`, (): void => { | ||
beforeEach( | ||
(): void => { | ||
username = `C0ZEN`; | ||
} | ||
); | ||
|
||
it(`should return a message for this username`, (): void => { | ||
expect.assertions(1); | ||
|
||
const result = getWelcomeMessage(username); | ||
|
||
expect(result).toStrictEqual(`yolo C0ZEN`); | ||
}); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
e2e/__external-repos__/path-mapping/src/share/get-welcome-message.ts
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,3 @@ | ||
export function getWelcomeMessage(username: string): string { | ||
return `yolo ${username}`; | ||
} |
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,3 @@ | ||
export interface Foo { | ||
bar: number | ||
} |
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,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"baseUrl": ".", | ||
"declaration": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"paths": { | ||
"@share/*": ["src/share/*"] | ||
} | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
Oops, something went wrong.