forked from rsuite/rsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstylesSpec.js
72 lines (65 loc) · 2.34 KB
/
stylesSpec.js
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
const assert = require('chai').assert;
const { basename, join, resolve } = require('path');
const { existsSync, readFileSync } = require('fs');
const glob = require('glob');
const IGNORE_COMPONENTS = [
'Schema',
'DOMHelper',
'Whisper',
'SafeAnchor',
'Portal',
'IntlProvider',
'Affix',
'RangeSlider',
'Overlay',
'CustomProvider',
'Plaintext'
];
const THEMES = ['default', 'dark'];
const STYLED_COMPONENTS = glob
.sync(resolve(__dirname, '../src/[A-Z]*'))
.map(path => basename(path))
.filter(componentName => !IGNORE_COMPONENTS.includes(componentName));
function shouldHasStyleFile() {
console.log('Should has style file.');
STYLED_COMPONENTS.map(function testStyleFile(componentName) {
const indexFile = join(__dirname, `../src/${componentName}/styles/index.ts`);
const defaultFile = join(__dirname, `../src/${componentName}/styles/themes/default.ts`);
const darkFile = join(__dirname, `../src/${componentName}/styles/themes/dark.ts`);
assert.equal(existsSync(indexFile), true, `${indexFile} should exists.`);
assert.equal(existsSync(defaultFile), true, `${defaultFile} should exists.`);
assert.equal(existsSync(darkFile), true, `${darkFile} should exists.`);
});
}
function shouldImportCoreFile() {
console.log('Should Import core file.');
STYLED_COMPONENTS.map(function testStyleFile(componentName) {
THEMES.forEach(theme => {
const tsFile = join(__dirname, `../src/${componentName}/styles/themes/${theme}.ts`);
const fileContent = readFileSync(tsFile, { encoding: 'utf-8' });
const importDarkResource = fileContent
.split('\n')
.filter(text => Boolean(text) && /^import '\.\.\/\.\.\/\.\.\/[A-Z].*/.test(text));
assert.equal(
fileContent.indexOf(`import '../../../styles/themes/${theme}/core.less';`),
0,
`${tsFile} should import ${theme}/core.less at the first line.`
);
assert.equal(
importDarkResource.every(text =>
new RegExp(
`^import '\\.\\.\\/\\.\\.\\/\\.\\.\\/[A-Z].*\\/styles\\/themes\\/${theme}';$`
).test(text)
),
true,
`
${tsFile} should import dark file eg: **/themes/${theme}.
Current:
${importDarkResource.join('\n')}
`
);
});
});
}
[shouldHasStyleFile, shouldImportCoreFile].forEach(test => test());
console.log('Successful!');