-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.js
61 lines (51 loc) · 1.75 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
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'];
let fixturesWithFix = ['remove-unused-translations', 'remove-unused-translations-nested'];
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,
});
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');
});
});