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

Commit 983c6f1

Browse files
committedFeb 22, 2017
Test name option in config
1 parent b207f3e commit 983c6f1

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed
 

‎test/fixtures/name-options/entry.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const w1 = require('./w1.js');
2+
const s2 = require('./w2.js');

‎test/fixtures/name-options/w1.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// w1 via worker options

‎test/fixtures/name-options/w2.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// w2 via worker options
File renamed without changes.
File renamed without changes.

‎test/index.js

+34-7
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,55 @@ const makeBundle = (name, options) => del(`expected/${name}`).then(() => {
3030
});
3131

3232
describe('worker-loader', () => {
33-
it('should create chunk with worker via query', () =>
34-
makeBundle('worker-query').then((stats) => {
33+
it('should create chunk with worker', () =>
34+
makeBundle('worker').then((stats) => {
3535
const workerFile = stats.toJson('minimal').children
3636
.map(item => item.chunks)
3737
.reduce((acc, item) => acc.concat(item), [])
3838
.map(item => item.files)
39-
.map(item => `expected/worker-query/${item}`)[0];
39+
.map(item => `expected/worker/${item}`)[0];
4040
assert(workerFile);
4141
assert.notEqual(readFile(workerFile).indexOf('// worker test mark'), -1);
4242
})
4343
);
4444

4545
it('should create chunk with specified name in query', () =>
4646
makeBundle('name-query').then((stats) => {
47-
const workerFile = 'expected/name-query/namedWorker.js';
48-
const receivedWorkerFile = stats.toJson('minimal').children
47+
const file = stats.toJson('minimal').children
4948
.map(item => item.chunks)
5049
.reduce((acc, item) => acc.concat(item), [])
5150
.map(item => item.files)
5251
.map(item => `expected/name-query/${item}`)[0];
53-
assert.equal(receivedWorkerFile, workerFile);
54-
assert.notEqual(readFile(workerFile).indexOf('// named worker test mark'), -1);
52+
assert.equal(file, 'expected/name-query/namedWorker.js');
53+
assert.notEqual(readFile(file).indexOf('// named worker test mark'), -1);
54+
})
55+
);
56+
57+
it('should create named chunks with workers via options', () =>
58+
makeBundle('name-options', {
59+
module: {
60+
rules: [
61+
{
62+
test: /(w1|w2)\.js$/,
63+
loader: '../index.js',
64+
options: {
65+
name: '[name].js',
66+
},
67+
},
68+
],
69+
},
70+
}).then((stats) => {
71+
const files = stats.toJson('minimal').children
72+
.map(item => item.chunks)
73+
.reduce((acc, item) => acc.concat(item), [])
74+
.map(item => item.files)
75+
.map(item => `expected/name-options/${item}`);
76+
assert.deepEqual(files, [
77+
'expected/name-options/w1.js',
78+
'expected/name-options/w2.js',
79+
]);
80+
assert.notEqual(readFile(files[0]).indexOf('// w1 via worker options'), -1);
81+
assert.notEqual(readFile(files[1]).indexOf('// w2 via worker options'), -1);
5582
})
5683
);
5784

0 commit comments

Comments
 (0)
This repository has been archived.