-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathjest.cssTransform.cjs
More file actions
86 lines (81 loc) · 2.81 KB
/
jest.cssTransform.cjs
File metadata and controls
86 lines (81 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Custom Jest transformer for vanilla-extract .css.ts files
// This transformer prevents vanilla-extract from executing during tests
// by returning a mock module that exports a Proxy
module.exports = {
process(_sourceText, sourcePath) {
// Normalize path separators for cross-platform compatibility
const normalizedPath = sourcePath.replace(/\\/g, '/');
const isThemesFile = normalizedPath.includes('/styles/themes.css');
if (isThemesFile) {
// Special handling for themes.css.ts to provide the correct structure
return {
code: `
// Mock theme classes
const mockThemeClass = 'mock-theme-class';
const mockThemes = {
light: {
neon: mockThemeClass,
blue: mockThemeClass,
orange: mockThemeClass,
red: mockThemeClass,
green: mockThemeClass,
deepBlue: mockThemeClass,
grayBlue: mockThemeClass,
},
dark: {
neon: mockThemeClass,
blue: mockThemeClass,
orange: mockThemeClass,
red: mockThemeClass,
green: mockThemeClass,
deepBlue: mockThemeClass,
grayBlue: mockThemeClass,
},
};
module.exports = {
themes: mockThemes,
lightTheme: mockThemeClass,
darkTheme: mockThemeClass,
lightThemeNeon: mockThemeClass,
lightThemeBlue: mockThemeClass,
lightThemeOrange: mockThemeClass,
lightThemeRed: mockThemeClass,
lightThemeGreen: mockThemeClass,
lightThemeDeepBlue: mockThemeClass,
lightThemeGrayBlue: mockThemeClass,
darkThemeNeon: mockThemeClass,
darkThemeBlue: mockThemeClass,
darkThemeOrange: mockThemeClass,
darkThemeRed: mockThemeClass,
darkThemeGreen: mockThemeClass,
darkThemeDeepBlue: mockThemeClass,
darkThemeGrayBlue: mockThemeClass,
};
`,
};
}
// Default handling for all other .css.ts files
return {
code: `
// Mock vanilla-extract styles and recipes
const mockRecipe = (options) => {
// Return a mock class name for recipes
return 'mock-recipe-class';
};
module.exports = new Proxy({}, {
get: (target, prop) => {
if (typeof prop === 'string') {
// If it looks like a recipe (ends with 'Recipe'), return a function
if (prop.toLowerCase().includes('recipe')) {
return mockRecipe;
}
// Otherwise return the property name as a mock class
return prop;
}
return target[prop];
}
});
`,
};
},
};