-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
/
pigment.test.ts
81 lines (76 loc) · 2.12 KB
/
pigment.test.ts
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
import * as fs from 'node:fs';
import * as path from 'node:path';
import { expect } from 'chai';
import { asyncResolveFallback } from '@wyw-in-js/shared';
import { TransformCacheCollection, transform, createFileReporter } from '@wyw-in-js/transform';
import { preprocessor } from '@pigment-css/react/utils';
const files = fs.readdirSync(path.join(__dirname, 'fixtures'));
const theme = {
palette: {
primary: {
main: 'red',
},
},
size: {
font: {
h1: '3rem',
},
},
components: {
MuiSlider: {
styleOverrides: {
rail: {
fontSize: '3rem',
},
},
},
},
};
describe('zero-runtime', () => {
files.forEach((file) => {
it(`test input file ${file}`, async () => {
if (file.includes('.output.')) {
return;
}
const cache = new TransformCacheCollection();
const { emitter: eventEmitter } = createFileReporter(false);
const inputFilePath = path.join(__dirname, 'fixtures', file);
const outputFilePath = path.join(__dirname, 'fixtures', file.replace('.input.', '.output.'));
const outputCssFilePath = path.join(
__dirname,
'fixtures',
file.replace('.input.js', '.output.css'),
);
const inputContent = fs.readFileSync(inputFilePath, 'utf8');
const outputContent = fs.readFileSync(outputFilePath, 'utf8');
const outputCssContent = fs.readFileSync(outputCssFilePath, 'utf8');
const pluginOptions = {
themeArgs: {
theme,
},
babelOptions: {
configFile: false,
babelrc: false,
},
tagResolver(_source: string, tag: string) {
return require.resolve(`../exports/${tag}`);
},
};
const result = await transform(
{
options: {
filename: inputFilePath,
preprocessor,
pluginOptions,
},
cache,
eventEmitter,
},
inputContent,
asyncResolveFallback,
);
expect(result.cssText).to.equal(outputCssContent);
expect(result.code.trim()).to.equal(outputContent.trim());
});
});
});