-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.test.js
83 lines (67 loc) · 2.21 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
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
const tap = require('tap');
const sinon = require('sinon');
const { onPostBuild } = require('./index');
tap.test('calls utils.run with defaults', async (t) => {
const run = sinon.fake();
await onPostBuild({
inputs: { ext: 'html' },
constants: { PUBLISH_DIR: '_site' },
utils: { run },
});
const expected = ['html-validate', ['--ext', 'html', '_site']];
const actual = run.getCall(0).args;
t.sameStrict(actual, expected, 'Function called with incorrect parameters');
});
tap.test('overwrites config path', async (t) => {
const run = sinon.fake();
await onPostBuild({
inputs: { ext: 'html', config: 'config.json' },
constants: { PUBLISH_DIR: '_site' },
utils: { run },
});
const expected = ['html-validate', ['--config', 'config.json', '--ext', 'html', '_site']];
const actual = run.getCall(0).args;
t.sameStrict(actual, expected, 'Function called with incorrect parameters');
});
tap.test('overwrites source path', async (t) => {
const run = sinon.fake();
await onPostBuild({
inputs: { ext: 'html', path: 'dist' },
constants: { PUBLISH_DIR: '_site' },
utils: { run },
});
const expected = ['html-validate', ['--ext', 'html', 'dist']];
const actual = run.getCall(0).args;
t.sameStrict(actual, expected, 'Function called with incorrect parameters');
});
tap.test('catches validation error', async (t) => {
const error = new Error('Something is wrong');
error.exitCode = 1;
const run = () => { throw error; };
const failBuild = (msg, err) => ({ msg, err });
const actual = await onPostBuild({
inputs: { ext: 'html' },
constants: { PUBLISH_DIR: '_site' },
utils: { run, build: { failBuild } },
});
const expected = {
msg: 'Invalid HTML',
err: { error },
};
t.sameStrict(actual, expected);
});
tap.test('catches unkown error', async (t) => {
const error = new Error('Something is wrong');
const run = () => { throw error; };
const failBuild = (msg, err) => ({ msg, err });
const actual = await onPostBuild({
inputs: { ext: 'html' },
constants: { PUBLISH_DIR: '_site' },
utils: { run, build: { failBuild } },
});
const expected = {
msg: 'Unknown error',
err: { error },
};
t.sameStrict(actual, expected);
});