-
Notifications
You must be signed in to change notification settings - Fork 118
/
workflow.test.js
57 lines (45 loc) · 1.59 KB
/
workflow.test.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
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const themeDir = 'theme';
const sourceDir = 'src';
describe('files', () => {
const moduleDirs = ['layout', 'snippets', 'sections', 'templates'];
async function matchFiles(pattern) {
return new Promise((resolve, reject) => {
glob(pattern, null, (error, files) => {
if (error) reject(error);
resolve(files);
});
});
}
async function checkLiquidFiles(extension) {
const patterns = moduleDirs.map((folder) => path.join(sourceDir, folder, `**/*.${extension}`));
for (const pattern of patterns) {
const files = await matchFiles(pattern);
const liquidFiles = files.map((file) => {
return themeDir + file.replace(sourceDir, '').replace(`.${extension}`, '.liquid');
});
files.forEach((file, index) => {
const liquidFile = liquidFiles[index];
const isNotExisting = !fs.existsSync(liquidFile);
const isNotIndex = path.basename(file).indexOf('index.') < 0;
if (isNotExisting && isNotIndex) {
throw Error(`The ${file} must have its own ${liquidFile}`);
}
});
}
}
test('each style file should have its own liquid file', async () => {
const extensions = ['css', 'scss'];
for (const extension of extensions) {
await checkLiquidFiles(extension);
}
});
test('each script file should have its own liquid file', async () => {
const extensions = ['js', 'mjs', 'jsx', 'vue'];
for (const extension of extensions) {
await checkLiquidFiles(extension);
}
});
});