Skip to content

Commit 50e1477

Browse files
feat(playground): jest-cjs (#60)
1 parent 15b8c29 commit 50e1477

File tree

10 files changed

+2169
-61
lines changed

10 files changed

+2169
-61
lines changed

.github/renovate.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
groupName: 'vitest',
4646
matchPackageNames: ['@vitest/**', 'vitest'],
4747
},
48+
{
49+
groupName: 'jest',
50+
matchPackageNames: ['@globals/jest', 'jest', 'ts-jest'],
51+
},
4852
{
4953
groupName: 'prettier',
5054
matchPackageNames: ['@types/prettier', 'prettier'],

playgrounds/jest-cjs/index.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { faker } from '@faker-js/faker';
2+
import { faker as fakerDe } from '@faker-js/faker/locale/de';
3+
import { faker as fakerFR } from '@faker-js/faker/locale/fr';
4+
import { describe, expect, it } from '@jest/globals';
5+
6+
describe('Faker Jest CJS', () => {
7+
describe.each([
8+
{ title: 'default', fakerInstance: faker },
9+
{ title: 'with locale DE', fakerInstance: fakerDe },
10+
{ title: 'with locale FR', fakerInstance: fakerFR },
11+
])('default', ({ fakerInstance }) => {
12+
it('should be able to access faker', () => {
13+
expect(fakerInstance).toBeTruthy();
14+
expect(typeof fakerInstance).toBe('object');
15+
expect(fakerInstance.definitions.metadata.title).toEqual(expect.any(String));
16+
});
17+
18+
it('should be able to access faker apis', () => {
19+
expect(fakerInstance.person.firstName()).toEqual(expect.any(String));
20+
expect(fakerInstance.location.city()).toEqual(expect.any(String));
21+
expect(fakerInstance.animal.bird()).toEqual(expect.any(String));
22+
});
23+
});
24+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @type {import("jest").Config}
3+
**/
4+
module.exports = {
5+
testEnvironment: 'node',
6+
transformIgnorePatterns: [
7+
// Transformation patterns for Jest to handle ES modules in node_modules.
8+
// Use the appropriate pattern based on your package manager:
9+
//
10+
// For npm:
11+
// 'node_modules/(?!@faker-js).+',
12+
//
13+
// For pnpm:
14+
'node_modules/.pnpm/.+/node_modules/(?!@faker-js).+',
15+
//
16+
// Important: Only one pattern matching Faker should be active at a time to ensure correct module transformation.
17+
],
18+
transform: {
19+
'^.+\\.(t|j)s$': [
20+
'ts-jest',
21+
{
22+
tsconfig: 'tsconfig.bundler.json',
23+
},
24+
],
25+
},
26+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @type {import("jest").Config}
3+
**/
4+
module.exports = {
5+
testEnvironment: 'node',
6+
transformIgnorePatterns: [
7+
// Transformation patterns for Jest to handle ES modules in node_modules.
8+
// Use the appropriate pattern based on your package manager:
9+
//
10+
// For npm:
11+
// 'node_modules/(?!@faker-js).+',
12+
//
13+
// For pnpm:
14+
'node_modules/.pnpm/.+/node_modules/(?!@faker-js).+',
15+
//
16+
// Important: Only one pattern matching Faker should be active at a time to ensure correct module transformation.
17+
],
18+
transform: {
19+
'^.+\\.(t|j)s$': [
20+
'ts-jest',
21+
{
22+
tsconfig: 'tsconfig.json',
23+
useESM: true,
24+
},
25+
],
26+
},
27+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @type {import("jest").Config}
3+
**/
4+
module.exports = {
5+
testEnvironment: 'node',
6+
transformIgnorePatterns: [
7+
// Transformation patterns for Jest to handle ES modules in node_modules.
8+
// Use the appropriate pattern based on your package manager:
9+
//
10+
// For npm:
11+
// 'node_modules/(?!@faker-js).+',
12+
//
13+
// For pnpm:
14+
'node_modules/.pnpm/.+/node_modules/(?!@faker-js).+',
15+
//
16+
// Important: Only one pattern matching Faker should be active at a time to ensure correct module transformation.
17+
],
18+
transform: {
19+
'^.+\\.(t|j)s$': [
20+
'ts-jest',
21+
{
22+
tsconfig: 'tsconfig.node20.json',
23+
},
24+
],
25+
},
26+
};

playgrounds/jest-cjs/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "faker-jest-cjs-test",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "commonjs",
6+
"scripts": {
7+
"test": "pnpm run-s test:node10 test:node20 test:bundler",
8+
"test:node10": "jest --config jest.config.js",
9+
"test:node20": "jest --config jest.config.node20.js",
10+
"test:bundler": "jest --config jest.config.bundler.js"
11+
},
12+
"devDependencies": {
13+
"@jest/globals": "30.2.0",
14+
"jest": "30.2.0",
15+
"ts-jest": "29.4.5"
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "ESNext",
5+
"moduleResolution": "Bundler"
6+
}
7+
}

playgrounds/jest-cjs/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"module": "CommonJS",
4+
"moduleResolution": "Node10",
5+
"target": "ES2022",
6+
"noEmit": true,
7+
"strict": true
8+
},
9+
"files": ["index.spec.ts"]
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "Node20",
5+
"moduleResolution": "NodeNext"
6+
}
7+
}

0 commit comments

Comments
 (0)