-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.test.js
57 lines (54 loc) · 1.68 KB
/
index.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 assert = require('assert');
const fs = require('fs');
const path = require('path');
const pipeline = require('./index');
const runCase = (name, fn) => new Promise((resolve, reject) => {
function done(err) {
if (err) {
console.log('============= Assertion failed =============');
reject();
process.exit(1);
} else {
console.log('============= Assertion passed =============');
resolve();
}
}
console.log(`\r\n============= Start test '${name}' =============`);
fn(done);
});
(async function() {
await runCase('test with selection file which already has icons', done => {
const names = ['new1', 'new2'];
pipeline({
icons: ['test-assets/1.svg', 'test-assets/2.svg'],
names,
selectionPath: 'test-assets/selection.json',
forceOverride: true,
whenFinished (result) {
const newSelection = JSON.parse(fs.readFileSync(path.resolve(result.outputDir, 'selection.json')));
assert.deepEqual(
newSelection.icons.slice(0, names.length).map(icon => icon.properties.name),
names
);
done();
}
});
});
await runCase('test with selection which does not have icons', done => {
const names = ['new1', 'new2'];
pipeline({
icons: ['test-assets/1.svg', 'test-assets/2.svg'],
names,
selectionPath: 'test-assets/selection-empty.json',
forceOverride: true,
whenFinished (result) {
const newSelection = JSON.parse(fs.readFileSync(path.resolve(result.outputDir, 'selection.json')));
assert.deepEqual(
newSelection.icons.map(icon => icon.properties.name),
names
);
done();
}
});
});
})();