|
2 | 2 |
|
3 | 3 | const assert = require('assert');
|
4 | 4 | const addDevServerEntrypoints = require('../lib/util/addDevServerEntrypoints');
|
| 5 | +const config = require('./fixtures/simple-config/webpack.config'); |
5 | 6 |
|
6 | 7 | describe('Entry', () => {
|
7 |
| - it('default to src if no entry point is given', (done) => { |
| 8 | + it('adds devServer entry points to a single entry point', () => { |
| 9 | + const webpackOptions = Object.assign({}, config); |
| 10 | + const devServerOptions = {}; |
| 11 | + |
| 12 | + addDevServerEntrypoints(webpackOptions, devServerOptions); |
| 13 | + |
| 14 | + assert.equal(webpackOptions.entry.length, 2); |
| 15 | + assert(webpackOptions.entry[0].indexOf('client/index.js?') !== -1); |
| 16 | + assert.equal(webpackOptions.entry[1], './foo.js'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('adds devServer entry points to a multi-module entry point', () => { |
| 20 | + const webpackOptions = Object.assign({}, config, { |
| 21 | + entry: ['./foo.js', './bar.js'] |
| 22 | + }); |
| 23 | + const devServerOptions = {}; |
| 24 | + |
| 25 | + addDevServerEntrypoints(webpackOptions, devServerOptions); |
| 26 | + |
| 27 | + assert.equal(webpackOptions.entry.length, 3); |
| 28 | + assert(webpackOptions.entry[0].indexOf('client/index.js?') !== -1); |
| 29 | + assert.equal(webpackOptions.entry[1], './foo.js'); |
| 30 | + assert.equal(webpackOptions.entry[2], './bar.js'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('adds devServer entry points to a multi entry point object', () => { |
| 34 | + const webpackOptions = Object.assign({}, config, { |
| 35 | + entry: { |
| 36 | + foo: './foo.js', |
| 37 | + bar: './bar.js' |
| 38 | + } |
| 39 | + }); |
| 40 | + const devServerOptions = {}; |
| 41 | + |
| 42 | + addDevServerEntrypoints(webpackOptions, devServerOptions); |
| 43 | + |
| 44 | + assert.equal(webpackOptions.entry.foo.length, 2); |
| 45 | + assert(webpackOptions.entry.foo[0].indexOf('client/index.js?') !== -1); |
| 46 | + assert.equal(webpackOptions.entry.foo[1], './foo.js'); |
| 47 | + assert.equal(webpackOptions.entry.bar[1], './bar.js'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('defaults to src if no entry point is given', () => { |
8 | 51 | const webpackOptions = {};
|
9 | 52 | const devServerOptions = {};
|
10 | 53 |
|
11 | 54 | addDevServerEntrypoints(webpackOptions, devServerOptions);
|
12 | 55 |
|
13 |
| - assert(webpackOptions.entry.length, 2); |
14 |
| - assert(webpackOptions.entry[1], './src'); |
| 56 | + assert.equal(webpackOptions.entry.length, 2); |
| 57 | + assert.equal(webpackOptions.entry[1], './src'); |
| 58 | + }); |
| 59 | + |
| 60 | + it('preserves dynamic entry points', (done) => { |
| 61 | + let i = 0; |
| 62 | + const webpackOptions = { |
| 63 | + // simulate dynamic entry |
| 64 | + entry: () => { |
| 65 | + i += 1; |
| 66 | + return `./src-${i}.js`; |
| 67 | + } |
| 68 | + }; |
| 69 | + const devServerOptions = {}; |
| 70 | + |
| 71 | + addDevServerEntrypoints(webpackOptions, devServerOptions); |
| 72 | + |
| 73 | + assert(typeof webpackOptions.entry, 'function'); |
| 74 | + |
| 75 | + webpackOptions.entry().then(entryFirstRun => ( |
| 76 | + webpackOptions.entry().then((entrySecondRun) => { |
| 77 | + assert.equal(entryFirstRun.length, 2); |
| 78 | + assert.equal(entryFirstRun[1], './src-1.js'); |
| 79 | + |
| 80 | + assert.equal(entrySecondRun.length, 2); |
| 81 | + assert.equal(entrySecondRun[1], './src-2.js'); |
| 82 | + done(); |
| 83 | + }) |
| 84 | + )).catch(done); |
| 85 | + }); |
| 86 | + |
| 87 | + it('preserves asynchronous dynamic entry points', (done) => { |
| 88 | + let i = 0; |
| 89 | + const webpackOptions = { |
| 90 | + // simulate async dynamic entry |
| 91 | + entry: () => new Promise((resolve) => { |
| 92 | + i += 1; |
| 93 | + resolve(`./src-${i}.js`); |
| 94 | + }) |
| 95 | + }; |
| 96 | + const devServerOptions = {}; |
| 97 | + |
| 98 | + addDevServerEntrypoints(webpackOptions, devServerOptions); |
| 99 | + |
| 100 | + assert(typeof webpackOptions.entry, 'function'); |
| 101 | + |
| 102 | + webpackOptions.entry().then(entryFirstRun => ( |
| 103 | + webpackOptions.entry().then((entrySecondRun) => { |
| 104 | + assert.equal(entryFirstRun.length, 2); |
| 105 | + assert.equal(entryFirstRun[1], './src-1.js'); |
15 | 106 |
|
16 |
| - done(); |
| 107 | + assert.equal(entrySecondRun.length, 2); |
| 108 | + assert.equal(entrySecondRun[1], './src-2.js'); |
| 109 | + done(); |
| 110 | + }) |
| 111 | + )).catch(done); |
17 | 112 | });
|
18 | 113 | });
|
0 commit comments