-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jest-config): Removing @swc/core from dependencies (#177)
downgrade @swc/core requirements due to TypeStrong/ts-node#2070 update config generation
- Loading branch information
Showing
11 changed files
with
1,655 additions
and
1,434 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,16 @@ | ||
import type { Config } from 'jest' | ||
import { defaultEsmExtensions, defaultTestMatch, defaultTimeout } from './constants' | ||
|
||
export const base: Partial<Config> = { | ||
collectCoverage: true, | ||
testEnvironment: 'node', | ||
extensionsToTreatAsEsm: defaultEsmExtensions, | ||
testMatch: defaultTestMatch, | ||
moduleNameMapper: { | ||
'^(\\.{1,2}/.*)\\.js$': '$1', | ||
}, | ||
testTimeout: defaultTimeout, | ||
openHandlesTimeout: defaultTimeout, | ||
} | ||
|
||
export default base |
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,29 +1,11 @@ | ||
import { Config } from 'jest' | ||
import type { Config } from 'jest' | ||
import base from './base' | ||
|
||
const base: Partial<Config> = { | ||
collectCoverage: true, | ||
testEnvironment: 'node', | ||
extensionsToTreatAsEsm: ['.ts', '.tsx'], | ||
testMatch: ['**/__tests__/**/?(*.)+(spec|test).[jt]s?(x)'], | ||
transform: { | ||
'^.+\\.(t|j)sx?$': [ | ||
'@swc/jest', | ||
{ | ||
jsc: { | ||
transform: { | ||
react: { | ||
runtime: 'automatic', | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
moduleNameMapper: { | ||
'^(\\.{1,2}/.*)\\.js$': '$1', | ||
}, | ||
testTimeout: 30000, | ||
openHandlesTimeout: 3000, | ||
export const defineConfig = (config: Partial<Config>): Partial<Config> => { | ||
return { | ||
...base, | ||
...(config || {}), | ||
} | ||
} | ||
|
||
export = base | ||
export default defineConfig |
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 const defaultTestMatch = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'] | ||
export const defaultEsmExtensions = ['.ts', '.tsx'] | ||
export const defaultTimeout = 30000 |
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,3 +1,4 @@ | ||
import * as base from './config' | ||
|
||
export = base | ||
export * from './config.js' | ||
export * from './swc.js' | ||
export * from './constants.js' | ||
export * from './interfaces.js' |
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 @@ | ||
export type * as SWC from '@swc/core' | ||
export type * as Jest from 'jest' |
Empty file.
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,32 @@ | ||
import { Config as JestConfig } from 'jest' | ||
import type { Config as SWCConfig } from '@swc/core' | ||
import { getRootSwc, defineJestTransform } from './utils' | ||
|
||
const swc = getRootSwc() | ||
|
||
export const withSWC = (config: Partial<SWCConfig>, jest: Partial<JestConfig>): JestConfig => { | ||
return { | ||
...jest, | ||
...defineJestTransform('@swc/jest', defineSwcConfiguration(config)), | ||
} | ||
} | ||
|
||
export const defineSwcConfiguration = (config: Partial<SWCConfig>): Partial<SWCConfig> => { | ||
const options = { | ||
...(swc || {}), | ||
...(config || {}), | ||
} | ||
return { | ||
...(options || {}), | ||
jsc: { | ||
...(options.jsc || {}), | ||
transform: { | ||
...(options.jsc?.transform || {}), | ||
react: { | ||
runtime: 'automatic', | ||
...(options.jsc?.transform?.react || {}), | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
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,34 @@ | ||
import type { Config as SWCConfig } from '@swc/core' | ||
import type { Config as JestConfig } from 'jest' | ||
import { resolve } from 'path' | ||
import fs from 'node:fs' | ||
|
||
export const getRootSwc = () => { | ||
try { | ||
const root = process.cwd() | ||
const path = resolve(root, '.swcrc') | ||
if (!fs.existsSync(path)) { | ||
return {} | ||
} | ||
const content = fs.readFileSync(path, 'utf-8') | ||
return JSON.parse(content) as Partial<SWCConfig> | ||
} catch (e) { | ||
return {} | ||
} | ||
} | ||
|
||
export const defineJestTransform = ( | ||
name: string = 'babel-jest', | ||
options?: Record<string, unknown>, | ||
): Partial<JestConfig> => { | ||
return { | ||
transform: { | ||
'^.+\\.(t|j)sx?$': [ | ||
name, | ||
{ | ||
...(options || {}), | ||
}, | ||
], | ||
}, | ||
} | ||
} |
Oops, something went wrong.