Skip to content

Commit

Permalink
Enhanced ts-jest cli to fix warning message.
Browse files Browse the repository at this point in the history
Before this patch, when I run jest test with jest.config.js generated
`ts-jest config:init`, it shows below warning message:

```
ts-jest[config] (WARN) Unable to find the root of the project where ts-jest has been installed.
```

This patch addresses the issue kulshekhar#959
  • Loading branch information
beenotung committed Oct 10, 2020
1 parent 49b4bf0 commit 3530c45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/cli/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ Jest configuration written to "${normalize('/foo/bar/jest.config.js')}".
`module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
globals: {
'ts-jest': {
packageJson: 'package.json',
},
},
};`,
],
])
Expand Down
9 changes: 5 additions & 4 deletions src/cli/config/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ export const run: CliCommand = async (args: Arguments /* , logger: Logger */) =>
}
if (!jsdom) content.push(" testEnvironment: 'node',")

content.push(' globals: {')
content.push(" 'ts-jest': {")
content.push(" packageJson: 'package.json',")
if (tsconfig || shouldPostProcessWithBabel) {
content.push(' globals: {')
content.push(" 'ts-jest': {")
if (tsconfig) content.push(` tsconfig: ${stringifyJson5(tsconfig)},`)
if (shouldPostProcessWithBabel) content.push(' babelConfig: true,')
content.push(' },')
content.push(' },')
}
content.push(' },')
content.push(' },')
content.push('};')

// join all together
Expand Down

0 comments on commit 3530c45

Please sign in to comment.