-
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.
fix(cli): change options to better reflect the new presets
- Loading branch information
Showing
7 changed files
with
134 additions
and
48 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
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,55 @@ | ||
import { TsJestPresets } from '../../types' | ||
|
||
/** @internal */ | ||
export enum JestPresetNames { | ||
default = 'ts-jest/presets/default', | ||
jsWithTs = 'ts-jest/presets/js-with-ts', | ||
jsWIthBabel = 'ts-jest/presets/js-with-babel', | ||
} | ||
|
||
/** @internal */ | ||
export interface TsJestPresetDescriptor { | ||
name: string | ||
fullName: string | ||
label: string | ||
jsVarName: string | ||
value: TsJestPresets | ||
isDefault: boolean | ||
jsImport(varName?: string): string | ||
} | ||
|
||
const definePreset = (fullName: string): TsJestPresetDescriptor => ({ | ||
fullName, | ||
get name() { | ||
return this.isDefault ? 'ts-jest' : fullName | ||
}, | ||
get label() { | ||
return fullName.split('/').pop()! | ||
}, | ||
get jsVarName() { | ||
return this.isDefault | ||
? 'defaults' | ||
: fullName | ||
.split('/') | ||
.pop()! | ||
.replace(/\-([a-z])/g, (_, l) => l.toUpperCase()) | ||
}, | ||
get value() { | ||
return require(`../../../${fullName.replace(/^ts-jest\//, '')}/jest-preset`) | ||
}, | ||
jsImport(varName = 'tsjPreset') { | ||
return `const { ${this.jsVarName}: ${varName} } = require('${this.fullName}')` | ||
}, | ||
get isDefault() { | ||
return fullName === JestPresetNames.default | ||
}, | ||
}) | ||
|
||
/** @internal */ | ||
export const allPresets: Record<JestPresetNames, TsJestPresetDescriptor> = {} as any | ||
/** @internal */ | ||
export const defaults = (allPresets[JestPresetNames.default] = definePreset(JestPresetNames.default)) | ||
/** @internal */ | ||
export const jsWithTs = (allPresets[JestPresetNames.jsWithTs] = definePreset(JestPresetNames.jsWithTs)) | ||
/** @internal */ | ||
export const jsWIthBabel = (allPresets[JestPresetNames.jsWIthBabel] = definePreset(JestPresetNames.jsWIthBabel)) |
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