Skip to content

Commit

Permalink
feat: make cli config:init respect es modules
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-melanson committed Sep 29, 2023
1 parent 9f1439a commit 1bccbfa
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cli/config/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ export const run: CliCommand = async (args: CliCommandArgs /* , logger: Logger *
body = JSON.stringify({ ...pkgJson, jest: jestConfig }, undefined, ' ')
} else {
// js config
const usesModules = pkgJson.type === 'module'

const content = []
if (!jestPreset) {
content.push(`${preset.jsImport('tsjPreset')};`, '')
}
content.push(`/** @type {import('ts-jest').JestConfigWithTsJest} */`)
content.push('module.exports = {')
content.push(usesModules ? 'const jestConfig = {' : 'module.exports = {')
if (jestPreset) {
content.push(` preset: '${preset.name}',`)
} else {
Expand All @@ -131,6 +133,10 @@ export const run: CliCommand = async (args: CliCommandArgs /* , logger: Logger *
}
content.push('};')

if (usesModules) {
content.push('\nexport default jestConfig;')
}

// join all together
body = content.join('\n')
}
Expand Down

0 comments on commit 1bccbfa

Please # to comment.