forked from bigcommerce/stencil-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildConfigManager.spec.js
93 lines (67 loc) · 3.29 KB
/
BuildConfigManager.spec.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
const { promisify } = require('util');
const BuildConfigManager = require('./BuildConfigManager');
const cwd = process.cwd();
describe('BuildConfigManager integration tests', () => {
afterEach(() => {
jest.restoreAllMocks();
});
describe('constructor', () => {
it('should return an instance with correct watchOptions taken from the config file', () => {
const buildConfig = new BuildConfigManager({
workDir: `${cwd}/test/_mocks/build-config/valid-config`,
});
expect(buildConfig.watchOptions).toBeInstanceOf(Object);
expect(buildConfig.watchOptions.files).toBeInstanceOf(Array);
expect(buildConfig.watchOptions.ignored).toBeInstanceOf(Array);
});
});
describe('production method', () => {
it('should resolve successfully for "valid-config"', async () => {
const buildConfig = new BuildConfigManager({
workDir: `${cwd}/test/_mocks/build-config/valid-config`,
});
buildConfig.initWorker();
expect(buildConfig.production).toBeInstanceOf(Function);
await promisify(buildConfig.production.bind(buildConfig))();
buildConfig.stopWorker();
});
it('should resolve successfully for "legacy-config"', async () => {
const buildConfig = new BuildConfigManager({
workDir: `${cwd}/test/_mocks/build-config/legacy-config`,
});
buildConfig.initWorker();
expect(buildConfig.production).toBeInstanceOf(Function);
await promisify(buildConfig.production.bind(buildConfig))();
buildConfig.stopWorker();
});
it('should reject with "worker terminated" message for "noworker-config"', async () => {
const buildConfig = new BuildConfigManager({
workDir: `${cwd}/test/_mocks/build-config/noworker-config`,
});
const initedBuildConfig = buildConfig.initWorker();
expect(buildConfig.production).toBeInstanceOf(Function);
await expect(
promisify(initedBuildConfig.production.bind(initedBuildConfig))(),
).rejects.toContain('worker terminated');
buildConfig.stopWorker();
});
});
describe('development method', () => {
it('should reload the browser when a message "reload" is received from stencil.conf.js (valid-config)', async () => {
const buildConfig = new BuildConfigManager({
workDir: `${cwd}/test/_mocks/build-config/valid-config`,
});
expect(buildConfig.development).toBeInstanceOf(Function);
await new Promise((done) => buildConfig.initWorker().development({ reload: done }));
buildConfig.stopWorker();
});
it('should reload the browser when "reload" method is called from stencil.conf.js (legacy-config)', async () => {
const buildConfig = new BuildConfigManager({
workDir: `${cwd}/test/_mocks/build-config/legacy-config`,
});
expect(buildConfig.development).toBeInstanceOf(Function);
await new Promise((done) => buildConfig.initWorker().development({ reload: done }));
buildConfig.stopWorker();
});
});
});