Skip to content

Commit c349ad6

Browse files
committed
test: workaround to handle .css.ts
1 parent 36565a7 commit c349ad6

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

jest.config.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ module.exports = {
44
moduleDirectories: ['node_modules'],
55
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
66
testPathIgnorePatterns: ['/node_modules/', '/__tests__/utils'],
7+
transform: {
8+
'\\.css\\.ts$': '<rootDir>/jest.cssTransform.cjs',
9+
'\\.(js|jsx|tsx?)$': 'babel-jest',
10+
},
711
};

jest.cssStub.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Mock for vanilla-extract .css.ts files
2+
// This stub returns a Proxy that returns the key name for any property access
3+
// This allows tests to run without processing vanilla-extract styles
4+
5+
module.exports = new Proxy(
6+
{},
7+
{
8+
get: (target, prop) => {
9+
// Return the property name as the class name
10+
// This makes debugging easier as you can see which class was used
11+
if (typeof prop === 'string') {
12+
return prop;
13+
}
14+
return target[prop];
15+
},
16+
}
17+
);

jest.cssTransform.cjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Custom Jest transformer for vanilla-extract .css.ts files
2+
// This transformer prevents vanilla-extract from executing during tests
3+
// by returning a mock module that exports a Proxy
4+
5+
module.exports = {
6+
process() {
7+
return {
8+
code: `
9+
module.exports = new Proxy({}, {
10+
get: (target, prop) => {
11+
if (typeof prop === 'string') {
12+
return prop;
13+
}
14+
return target[prop];
15+
}
16+
});
17+
`,
18+
};
19+
},
20+
};

0 commit comments

Comments
 (0)