Skip to content
This repository was archived by the owner on Sep 9, 2021. It is now read-only.

Commit 232a08d

Browse files
committedFeb 25, 2017
Check count of chunks in tests
1 parent 0eb6ef8 commit 232a08d

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed
 

‎test/index.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ const makeBundle = (name, options) => del(`expected/${name}`).then(() => {
3434
describe('worker-loader', () => {
3535
it('should create chunk with worker', () =>
3636
makeBundle('worker').then((stats) => {
37-
const workerFile = stats.toJson('minimal').children
37+
const files = stats.toJson('minimal').children
3838
.map(item => item.chunks)
3939
.reduce((acc, item) => acc.concat(item), [])
4040
.map(item => item.files)
41-
.map(item => `expected/worker/${item}`)[0];
42-
assert(workerFile);
43-
assert.notEqual(readFile(workerFile).indexOf('// worker test mark'), -1);
41+
.map(item => `expected/worker/${item}`);
42+
assert.equal(files.length, 1);
43+
assert.notEqual(readFile(files[0]).indexOf('// worker test mark'), -1);
4444
})
4545
);
4646

4747
it('should create chunk with specified name in query', () =>
4848
makeBundle('name-query').then((stats) => {
49-
const file = stats.toJson('minimal').children
49+
const files = stats.toJson('minimal').children
5050
.map(item => item.chunks)
5151
.reduce((acc, item) => acc.concat(item), [])
5252
.map(item => item.files)
53-
.map(item => `expected/name-query/${item}`)[0];
54-
assert.equal(file, 'expected/name-query/namedWorker.js');
55-
assert.notEqual(readFile(file).indexOf('// named worker test mark'), -1);
53+
.map(item => `expected/name-query/${item}`);
54+
assert.equal(files[0], 'expected/name-query/namedWorker.js');
55+
assert.notEqual(readFile(files[0]).indexOf('// named worker test mark'), -1);
5656
})
5757
);
5858

@@ -74,24 +74,22 @@ describe('worker-loader', () => {
7474
.map(item => item.chunks)
7575
.reduce((acc, item) => acc.concat(item), [])
7676
.map(item => item.files)
77-
.map(item => `expected/name-options/${item}`);
78-
const w1 = files.find(file => file === 'expected/name-options/w1.js');
79-
const w2 = files.find(file => file === 'expected/name-options/w2.js');
80-
assert(w1);
81-
assert(w2);
82-
assert.notEqual(readFile(w1).indexOf('// w1 via worker options'), -1);
83-
assert.notEqual(readFile(w2).indexOf('// w2 via worker options'), -1);
77+
.map(item => `expected/name-options/${item}`)
78+
.sort();
79+
assert.equal(files.length, 2);
80+
assert.notEqual(readFile(files[0]).indexOf('// w1 via worker options'), -1);
81+
assert.notEqual(readFile(files[1]).indexOf('// w2 via worker options'), -1);
8482
})
8583
);
8684

8785
it('should inline worker with inline option in query', () =>
8886
makeBundle('inline-query').then((stats) => {
89-
const bundleFile = stats.toJson('minimal').chunks
87+
const files = stats.toJson('minimal').chunks
9088
.map(item => item.files)
9189
.reduce((acc, item) => acc.concat(item), [])
92-
.map(item => `expected/inline-query/${item}`)[0];
93-
assert(bundleFile);
94-
assert.notEqual(readFile(bundleFile).indexOf('// inlined worker test mark'), -1);
90+
.map(item => `expected/inline-query/${item}`);
91+
assert.equal(files.length, 1);
92+
assert.notEqual(readFile(files[0]).indexOf('// inlined worker test mark'), -1);
9593
})
9694
);
9795

@@ -109,13 +107,13 @@ describe('worker-loader', () => {
109107
],
110108
},
111109
}).then((stats) => {
112-
const bundleFile = stats.toJson('minimal').chunks
110+
const files = stats.toJson('minimal').chunks
113111
.map(item => item.files)
114112
.reduce((acc, item) => acc.concat(item), [])
115-
.map(item => `expected/inline-options/${item}`)[0];
116-
assert(bundleFile);
117-
assert.notEqual(readFile(bundleFile).indexOf('// w1 inlined via options'), -1);
118-
assert.notEqual(readFile(bundleFile).indexOf('// w2 inlined via options'), -1);
113+
.map(item => `expected/inline-options/${item}`);
114+
assert.equal(files.length, 1);
115+
assert.notEqual(readFile(files[0]).indexOf('// w1 inlined via options'), -1);
116+
assert.notEqual(readFile(files[0]).indexOf('// w2 inlined via options'), -1);
119117
})
120118
);
121119

0 commit comments

Comments
 (0)
This repository has been archived.