Skip to content

Commit 24f10af

Browse files
PabloSzxjaredpalmer
authored andcommitted
Write Jest configuration file (#75)
* Write Jest Configuration File needed for compatibility with Visual Studio Code with Jest extension * Verify if file doesn't already exists
1 parent 851da83 commit 24f10af

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/createJestConfig.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
14
export function createJestConfig(
25
_: (relativePath: string) => void,
36
rootDir: string
47
) {
5-
return {
8+
const config = {
69
transform: {
710
'.(ts|tsx)': require.resolve('ts-jest/dist'),
811
},
@@ -17,4 +20,17 @@ export function createJestConfig(
1720
require.resolve('jest-watch-typeahead/testname'),
1821
],
1922
};
23+
24+
if (!fs.existsSync(path.join(rootDir, 'jest.config.js')))
25+
fs.writeFile(
26+
path.join(rootDir, 'jest.config.js'),
27+
`module.exports = ${JSON.stringify(config, null, 4)}`,
28+
err => {
29+
if (err) {
30+
console.error('Error trying to save the Jest configuration file!');
31+
}
32+
}
33+
);
34+
35+
return config;
2036
}

0 commit comments

Comments
 (0)