Skip to content

Commit 04a12d7

Browse files
committed
test: improve examples folder
- Use Jest `.ts` config files - Improve `monorepo-app` example
1 parent 547eb6f commit 04a12d7

File tree

97 files changed

+365
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+365
-395
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { Config } from 'jest'
12
import { createJsWithBabelEsmPreset } from 'ts-jest'
23

3-
/** @type {import('ts-jest').JestConfigWithTsJest} */
44
export default {
55
displayName: 'js-with-babel',
66
...createJsWithBabelEsmPreset({
77
babelConfig: true,
88
tsconfig: 'tsconfig-esm-isolated.json',
99
}),
10-
}
10+
} satisfies Config
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { Config } from 'jest'
12
import { createJsWithBabelEsmPreset } from 'ts-jest'
23

3-
/** @type {import('ts-jest').JestConfigWithTsJest} */
44
export default {
55
displayName: 'js-with-babel',
66
...createJsWithBabelEsmPreset({
77
babelConfig: true,
88
tsconfig: 'tsconfig-esm.json',
99
}),
10-
}
10+
} satisfies Config
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const { createJsWithBabelPreset } = require('ts-jest')
1+
import type { Config } from 'jest'
2+
import { createJsWithBabelPreset } from 'ts-jest'
23

3-
/** @type {import('ts-jest').JestConfigWithTsJest} */
4-
module.exports = {
4+
export default {
55
displayName: 'js-with-babel',
66
...createJsWithBabelPreset({
77
babelConfig: true,
88
tsconfig: 'tsconfig-isolated.json',
99
}),
10-
}
10+
} satisfies Config

examples/js-with-babel/jest.config.cjs

-9
This file was deleted.

examples/js-with-babel/jest.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Config } from 'jest'
2+
import { createJsWithBabelPreset } from 'ts-jest'
3+
4+
export default {
5+
displayName: 'js-with-babel',
6+
...createJsWithBabelPreset({
7+
babelConfig: true,
8+
}),
9+
} satisfies Config

examples/js-with-babel/package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"test": "jest -c=jest.config.cjs --no-cache",
7-
"test-isolated": "jest -c=jest-isolated.config.cjs --no-cache",
8-
"test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.mjs --no-cache",
9-
"test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.mjs --no-cache"
6+
"test": "jest -c=jest.config.ts --no-cache",
7+
"test-isolated": "jest -c=jest-isolated.config.ts --no-cache",
8+
"test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.ts --no-cache",
9+
"test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.ts --no-cache"
1010
},
1111
"devDependencies": {
1212
"@babel/core": "^7.26.10",
1313
"@babel/preset-env": "^7.26.9",
14-
"@tsconfig/strictest": "^2.0.5",
1514
"@types/jest": "^29.5.14",
1615
"babel-jest": "^29.7.0",
1716
"cross-env": "^7.0.3",

examples/js-with-babel/tsconfig.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
2-
"extends": "@tsconfig/strictest/tsconfig.json",
2+
"extends": "../tsconfig-base.spec.json",
33
"compilerOptions": {
4-
"module": "Node16",
5-
"target": "ESNext",
4+
"module": "CommonJS",
65
"allowJs": true,
7-
"types": ["jest"],
86
"isolatedModules": false
97
}
108
}

examples/js-with-ts/jest-esm-isolated.config.mjs

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Config } from 'jest'
2+
import { createJsWithTsEsmPreset } from 'ts-jest'
3+
4+
export default {
5+
displayName: 'js-with-ts',
6+
...createJsWithTsEsmPreset({
7+
tsconfig: 'tsconfig-esm-isolated.json',
8+
}),
9+
} satisfies Config

examples/js-with-ts/jest-esm.config.mjs

-9
This file was deleted.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Config } from 'jest'
2+
import { createJsWithTsEsmPreset } from 'ts-jest'
3+
4+
export default {
5+
displayName: 'js-with-ts',
6+
...createJsWithTsEsmPreset({
7+
tsconfig: 'tsconfig-esm.json',
8+
}),
9+
} satisfies Config

examples/js-with-ts/jest-isolated.config.cjs

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Config } from 'jest'
2+
import { createJsWithTsPreset } from 'ts-jest'
3+
4+
export default {
5+
displayName: 'js-with-ts',
6+
...createJsWithTsPreset({
7+
tsconfig: 'tsconfig-isolated.json',
8+
}),
9+
transformIgnorePatterns: ['!node_modules/(?!lodash-es)'],
10+
} satisfies Config

examples/js-with-ts/jest.config.cjs

-7
This file was deleted.

examples/js-with-ts/jest.config.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Config } from 'jest'
2+
import { createJsWithTsPreset } from 'ts-jest'
3+
4+
export default {
5+
displayName: 'js-with-ts',
6+
...createJsWithTsPreset(),
7+
transformIgnorePatterns: ['!node_modules/(?!lodash-es)'],
8+
} satisfies Config

examples/js-with-ts/package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"test": "jest -c=jest.config.cjs --no-cache",
7-
"test-isolated": "jest -c=jest-isolated.config.cjs --no-cache",
8-
"test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.mjs --no-cache",
9-
"test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.mjs --no-cache"
6+
"test": "jest -c=jest.config.ts --no-cache",
7+
"test-isolated": "jest -c=jest-isolated.config.ts --no-cache",
8+
"test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.ts --no-cache",
9+
"test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.ts --no-cache"
1010
},
1111
"devDependencies": {
12-
"@tsconfig/strictest": "^2.0.5",
12+
"@types/lodash-es": "^4.17.12",
1313
"@types/jest": "^29.5.14",
1414
"cross-env": "^7.0.3",
15+
"lodash-es": "^4.17.21",
1516
"jest": "^29.7.0",
1617
"ts-jest": "^29.3.0",
1718
"typescript": "~5.5.4"
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import { test, expect } from '@jest/globals'
1+
import camelCase from 'lodash-es/camelCase'
22

33
import { getWelcomeMessage } from './welcome-message'
4-
import welcomePerson from './welcome-person'
54

65
test('should show welcome message', () => {
7-
expect(getWelcomeMessage()).toMatchInlineSnapshot(`"Welcome to ts-jest!!!"`)
8-
})
9-
10-
test('should show welcome person message', () => {
11-
// @ts-expect-error in ESM mode, `default` is kept after compilation
12-
expect(welcomePerson.default ? welcomePerson.default : welcomePerson).toMatchInlineSnapshot(`"Welcome to ts-jest!!!"`)
6+
expect(camelCase(getWelcomeMessage())).toBe('welcomeToTsJest')
137
})

examples/js-with-ts/src/welcome-person.js

-3
This file was deleted.

examples/js-with-ts/tsconfig.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
2-
"extends": "@tsconfig/strictest/tsconfig.json",
2+
"extends": "../tsconfig-base.spec.json",
33
"compilerOptions": {
4-
"module": "Node16",
5-
"target": "ESNext",
4+
"module": "CommonJS",
65
"allowJs": true,
7-
"types": ["jest"],
86
"isolatedModules": false
97
}
108
}

examples/monorepo-app/jest-esm-isolated.config.mjs

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Config } from 'jest'
2+
3+
export default {
4+
projects: [
5+
'<rootDir>/type-commonjs/jest-esm-isolated.config.ts',
6+
'<rootDir>/type-module/jest-esm-isolated.config.ts',
7+
],
8+
} satisfies Config

examples/monorepo-app/jest-esm.config.mjs

-4
This file was deleted.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { Config } from 'jest'
2+
3+
export default {
4+
projects: ['<rootDir>/type-commonjs/jest-esm.config.ts', '<rootDir>/type-module/jest-esm.config.ts'],
5+
} satisfies Config

examples/monorepo-app/jest-isolated.config.cjs

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { Config } from 'jest'
2+
3+
export default {
4+
projects: ['<rootDir>/type-commonjs/jest-isolated.config.ts', '<rootDir>/type-module/jest-isolated.config.ts'],
5+
} satisfies Config

examples/monorepo-app/jest.config.cjs

-4
This file was deleted.

examples/monorepo-app/jest.config.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { Config } from 'jest'
2+
3+
export default {
4+
projects: ['<rootDir>/type-commonjs/jest.config.ts', '<rootDir>/type-module/jest.config.ts'],
5+
} satisfies Config

examples/monorepo-app/package.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
{
22
"name": "monorepo-app",
33
"version": "0.0.0",
4+
"workspaces": [
5+
"type-commonjs",
6+
"type-module",
7+
"shared"
8+
],
49
"scripts": {
5-
"test": "jest -c=jest.config.cjs --no-cache",
6-
"test-isolated": "jest -c=jest-isolated.config.cjs --no-cache",
7-
"test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.mjs --no-cache",
8-
"test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.mjs --no-cache"
10+
"build": "tsc -b",
11+
"test": "jest -c=jest.config.ts --no-cache",
12+
"test-isolated": "jest -c=jest-isolated.config.ts --no-cache",
13+
"test-esm": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm.config.ts --no-cache",
14+
"test-esm-isolated": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest -c=jest-esm-isolated.config.ts --no-cache"
915
},
1016
"devDependencies": {
11-
"@tsconfig/strictest": "^2.0.5",
1217
"@types/jest": "^29.5.14",
1318
"cross-env": "^7.0.3",
1419
"jest": "^29.7.0",

examples/monorepo-app/project-1/jest-esm-isolated.config.mjs

-9
This file was deleted.

examples/monorepo-app/project-1/jest-esm.config.mjs

-9
This file was deleted.

examples/monorepo-app/project-1/jest-isolated.config.cjs

-9
This file was deleted.

examples/monorepo-app/project-1/jest.config.cjs

-7
This file was deleted.

examples/monorepo-app/project-1/test/welcome-message.spec.ts

-5
This file was deleted.

examples/monorepo-app/project-1/tsconfig-esm.json

-3
This file was deleted.

examples/monorepo-app/project-2/jest-esm-isolated.config.mjs

-9
This file was deleted.

examples/monorepo-app/project-2/jest-esm.config.mjs

-9
This file was deleted.

examples/monorepo-app/project-2/jest-isolated.config.cjs

-9
This file was deleted.

examples/monorepo-app/project-2/jest.config.cjs

-7
This file was deleted.

examples/monorepo-app/project-2/test/welcome-message.spec.ts

-5
This file was deleted.

examples/monorepo-app/project-2/tsconfig-esm.json

-3
This file was deleted.

examples/monorepo-app/project-2/tsconfig.json

-3
This file was deleted.

0 commit comments

Comments
 (0)