-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
88 lines (73 loc) · 2.22 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
'use strict';
const path = require('path');
const projector = require('./');
const FIXTURE = path.join(__dirname, 'fixture.js');
const MOCK_ARGS = [{ foo: 'bar' }];
let expectError = () => {
throw new Error('Promise should have errored instead of fulfilling.');
};
test('projector(script)', () => {
return projector(FIXTURE).then(res => {
expect(res.MOCK_RUN).toBe(true);
expect(res.EXPORT_NAME).toBe('default');
expect(res.MOCK_ARGS).toEqual([]);
});
});
test('projector(script, args)', () => {
return projector(FIXTURE, MOCK_ARGS).then(res => {
expect(res.MOCK_RUN).toBe(true);
expect(res.EXPORT_NAME).toBe('default');
expect(res.MOCK_ARGS).toEqual(MOCK_ARGS);
});
});
test('projector(script, exportName)', () => {
return projector(FIXTURE, 'named').then(res => {
expect(res.MOCK_RUN).toBe(true);
expect(res.EXPORT_NAME).toBe('named');
expect(res.MOCK_ARGS).toEqual([]);
});
});
test('projector(script, exportName, args)', () => {
return projector(FIXTURE, 'named', MOCK_ARGS).then(res => {
expect(res.MOCK_RUN).toBe(true);
expect(res.EXPORT_NAME).toBe('named');
expect(res.MOCK_ARGS).toEqual(MOCK_ARGS);
});
});
test('projector(script, undefined, args)', () => {
return projector(FIXTURE, undefined, MOCK_ARGS).then(res => {
expect(res.MOCK_RUN).toBe(true);
expect(res.EXPORT_NAME).toBe('default');
expect(res.MOCK_ARGS).toEqual(MOCK_ARGS);
});
});
test('error on non-string fixture', () => {
expect(() => {
projector(42);
}).toThrow();
});
test('error on non-string export', () => {
expect(() => {
projector(FIXTURE, 42);
}).toThrow();
});
test('error on non-array args', () => {
expect(() => {
projector(FIXTURE, 'default', 42);
}).toThrow();
});
test('error on object args in export position', () => {
expect(() => {
projector(FIXTURE, {});
}).toThrow();
});
test('on error', () => {
return projector(FIXTURE, 'error', MOCK_ARGS).then(expectError, err => {
expect(err.message).toEqual('MOCK_ERROR');
});
});
test('on missing export', () => {
return projector(FIXTURE, 'MISSING_EXPORT').then(expectError, err => {
expect(err.message).toContain(`Module "${FIXTURE}" does not have export named "MISSING_EXPORT"`);
});
});