-
Notifications
You must be signed in to change notification settings - Fork 14
/
test.js
99 lines (89 loc) · 2.74 KB
/
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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
const fs = require('fs');
const { run, generateFileList } = require('./index');
let fixtures = fs.readdirSync(`${__dirname}/fixtures/`);
describe('Test Fixtures', () => {
let output;
let writtenFiles;
let fixturesWithErrors = [
'emblem',
'missing-translations',
'unused-translations',
'in-repo-translations',
'external-addon-translations',
'concat-expression',
'chosen-translations',
'unused-whitelist',
];
let fixturesWithFix = ['remove-unused-translations', 'remove-unused-translations-nested'];
let fixturesWithConcat = ['concat-expression'];
let fixturesWithConfig = {
'external-addon-translations': {
externalPaths: ['@*/*', 'external-addon'],
},
'chosen-translations': {
translationFiles: ['**/en.yaml'],
},
'plugin-config': {
babelParserPlugins: ['typescript'],
extensions: ['.ts'],
},
'first-class-component-templates': {
babelParserPlugins: ['typescript'],
extensions: ['.gts'],
},
'unused-whitelist': {
errorOnUnusedWhitelistEntries: true,
whitelist: [
/some\.whitelisted\.translation-(a|b)/,
/some\.unused\.whitelisted\.translation-(a|b)/,
],
},
'custom-t-helpers': {
helpers: ['t-error'],
},
};
beforeEach(() => {
output = '';
writtenFiles = new Map();
});
function log(str = '') {
output += `${str}\n`;
}
function writeToFile(filePath, updatedTranslations) {
let fileName = filePath.split('/').slice(-2).join('/');
writtenFiles.set(fileName, updatedTranslations);
}
for (let fixture of fixtures) {
test(fixture, async () => {
let returnValue = await run(`${__dirname}/fixtures/${fixture}`, {
log,
fix: fixturesWithFix.includes(fixture),
color: false,
writeToFile,
config: fixturesWithConfig[fixture],
analyzeConcatExpression: fixturesWithConcat.includes(fixture),
});
let expectedReturnValue = fixturesWithErrors.includes(fixture) ? 1 : 0;
expect(returnValue).toEqual(expectedReturnValue);
expect(output).toMatchSnapshot();
expect(writtenFiles).toMatchSnapshot();
});
}
});
describe('generateFileList', () => {
const TESTS = [
[['a.js'], 'a.js'],
[['a.js', 'b.js'], 'a.js and b.js'],
[['a.js', 'b.js', 'c.js'], 'a.js, b.js and c.js'],
[['a.js', 'b.js', 'd.js', 'c.js'], 'a.js, b.js, c.js and d.js'],
[['translations/en.json', 'translations/de.json'], 'de.json and en.json'],
];
for (let [input, expected] of TESTS) {
test(expected, () => {
expect(generateFileList(input)).toBe(expected);
});
}
test('passing an empty array throws an error', () => {
expect(() => generateFileList([])).toThrow('Unexpected empty file list');
});
});