Skip to content

Commit c0f2ed8

Browse files
committed
cp dines
1 parent 2bceaa2 commit c0f2ed8

18 files changed

Lines changed: 1039 additions & 350 deletions

jest.config.js

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,80 @@
1+
import { pathsToModuleNameMapper } from 'ts-jest';
2+
import { readFileSync } from 'fs';
3+
import { fileURLToPath } from 'url';
4+
import { dirname } from 'path';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = dirname(__filename);
8+
9+
// Read and parse tsconfig.json
10+
const tsconfig = JSON.parse(readFileSync('./tsconfig.json', 'utf8'));
11+
const compilerOptions = tsconfig.compilerOptions;
12+
113
export default {
2-
preset: 'ts-jest',
14+
// Use the default ESM preset for ts-jest
15+
preset: 'ts-jest/presets/default-esm',
16+
17+
// Test environment
318
testEnvironment: 'node',
19+
20+
// Test discovery
421
roots: ['<rootDir>/tests'],
522
testMatch: ['**/__tests__/**/*.test.ts'],
23+
24+
// Coverage configuration
625
collectCoverageFrom: [
726
'src/**/*.{ts,tsx}',
827
'!src/**/*.d.ts',
928
'!src/**/*.test.{ts,tsx}',
1029
'!src/**/*.spec.{ts,tsx}',
1130
],
31+
32+
// Setup files
1233
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
34+
35+
// Module name mapping for path aliases
1336
moduleNameMapper: {
37+
// Handle .js extensions for TypeScript files in ESM
1438
'^(\\.{1,2}/.*)\\.js$': '$1',
39+
// Map TypeScript path aliases to actual file paths
40+
...pathsToModuleNameMapper(compilerOptions.paths, {
41+
prefix: '<rootDir>/',
42+
useESM: true
43+
}),
44+
// Mock problematic ESM modules
45+
'^figures$': '<rootDir>/tests/__mocks__/figures.js',
46+
'^is-unicode-supported$': '<rootDir>/tests/__mocks__/is-unicode-supported.js',
47+
'^conf$': '<rootDir>/tests/__mocks__/conf.js',
1548
},
49+
50+
// Transform configuration
1651
transform: {
17-
'^.+\\.tsx?$': 'ts-jest',
18-
},
19-
extensionsToTreatAsEsm: ['.ts', '.tsx'],
20-
globals: {
21-
'ts-jest': {
52+
'^.+\\.tsx?$': ['ts-jest', {
2253
useESM: true,
23-
},
54+
tsconfig: {
55+
...compilerOptions,
56+
// Override some options for Jest
57+
rootDir: '.',
58+
module: 'ESNext',
59+
moduleResolution: 'Node',
60+
allowSyntheticDefaultImports: true,
61+
esModuleInterop: true,
62+
}
63+
}],
2464
},
65+
66+
// Transform ignore patterns for node_modules
67+
transformIgnorePatterns: [
68+
'node_modules/(?!(conf|@runloop|ink|react|ink-big-text|ink-gradient|ink-spinner|ink-text-input|ink-select-input|ink-box|ink-text|figures|is-unicode-supported)/)'
69+
],
70+
71+
// Treat these extensions as ESM
72+
extensionsToTreatAsEsm: ['.ts', '.tsx'],
73+
74+
// Test timeout
2575
testTimeout: 30000,
76+
77+
// Coverage thresholds
2678
coverageThreshold: {
2779
global: {
2880
branches: 80,
@@ -31,6 +83,16 @@ export default {
3183
statements: 80,
3284
},
3385
},
86+
87+
88+
// Module file extensions
89+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
90+
91+
// Clear mocks between tests
92+
clearMocks: true,
93+
94+
// Restore mocks between tests
95+
restoreMocks: true,
3496
};
3597

3698

tests/__mocks__/conf.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Conf {
2+
constructor(options = {}) {
3+
this.store = new Map();
4+
this.defaults = options.defaults || {};
5+
}
6+
7+
get(key, defaultValue) {
8+
return this.store.get(key) ?? this.defaults[key] ?? defaultValue;
9+
}
10+
11+
set(key, value) {
12+
this.store.set(key, value);
13+
}
14+
15+
delete(key) {
16+
this.store.delete(key);
17+
}
18+
19+
clear() {
20+
this.store.clear();
21+
}
22+
23+
has(key) {
24+
return this.store.has(key) || key in this.defaults;
25+
}
26+
27+
get size() {
28+
return this.store.size;
29+
}
30+
31+
*[Symbol.iterator]() {
32+
for (const [key, value] of this.store) {
33+
yield [key, value];
34+
}
35+
}
36+
}
37+
38+
module.exports = Conf;
39+
module.exports.default = Conf;

tests/__mocks__/figures.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Mock for figures module
2+
module.exports = {
3+
tick: '✓',
4+
cross: '✗',
5+
star: '★',
6+
square: '▇',
7+
squareSmall: '◻',
8+
squareSmallFilled: '◼',
9+
play: '▶',
10+
circle: '◯',
11+
circleFilled: '◉',
12+
circleDotted: '◌',
13+
circleDouble: '◎',
14+
circleCircle: 'ⓞ',
15+
circleCross: 'ⓧ',
16+
circlePipe: 'Ⓘ',
17+
circleQuestionMark: '?⃝',
18+
bullet: '•',
19+
dot: '․',
20+
line: '─',
21+
ellipsis: '…',
22+
pointer: '❯',
23+
pointerSmall: '›',
24+
info: 'ℹ',
25+
warning: '⚠',
26+
hamburger: '☰',
27+
smiley: '㋡',
28+
mustache: '෴',
29+
heart: '♥',
30+
arrowUp: '↑',
31+
arrowDown: '↓',
32+
arrowLeft: '←',
33+
arrowRight: '→',
34+
radioOn: '◉',
35+
radioOff: '◯',
36+
checkboxOn: '☑',
37+
checkboxOff: '☐',
38+
checkboxOnOff: '☒',
39+
bulletWhite: '◦',
40+
home: '⌂',
41+
menu: '☰',
42+
line: '─',
43+
ellipsis: '…',
44+
pointer: '❯',
45+
pointerSmall: '›',
46+
info: 'ℹ',
47+
warning: '⚠',
48+
hamburger: '☰',
49+
smiley: '㋡',
50+
mustache: '෴',
51+
heart: '♥',
52+
arrowUp: '↑',
53+
arrowDown: '↓',
54+
arrowLeft: '←',
55+
arrowRight: '→',
56+
radioOn: '◉',
57+
radioOff: '◯',
58+
checkboxOn: '☑',
59+
checkboxOff: '☐',
60+
checkboxOnOff: '☒',
61+
bulletWhite: '◦',
62+
home: '⌂',
63+
menu: '☰'
64+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Mock for is-unicode-supported module
2+
module.exports = function isUnicodeSupported() {
3+
return true;
4+
};

0 commit comments

Comments
 (0)