|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const testBin = require('../helpers/test-bin'); |
| 4 | +const isWebpack5 = require('../helpers/isWebpack5'); |
| 5 | + |
| 6 | +describe('DevServer', () => { |
| 7 | + const webpack5Test = isWebpack5 ? it : it.skip; |
| 8 | + |
| 9 | + it('should add devServer entry points to a single entry point', (done) => { |
| 10 | + testBin('--config ./test/fixtures/dev-server/default-config.js') |
| 11 | + .then((output) => { |
| 12 | + expect(output.exitCode).toEqual(0); |
| 13 | + expect(output.stderr).toContain('client/default/index.js?'); |
| 14 | + done(); |
| 15 | + }) |
| 16 | + .catch(done); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should add devServer entry points to a multi entry point object', (done) => { |
| 20 | + testBin('--config ./test/fixtures/dev-server/multi-entry.js') |
| 21 | + .then((output) => { |
| 22 | + expect(output.exitCode).toEqual(0); |
| 23 | + expect(output.stderr).toContain('client/default/index.js?'); |
| 24 | + expect(output.stderr).toContain('foo.js'); |
| 25 | + expect(output.stderr).toContain('bar.js'); |
| 26 | + done(); |
| 27 | + }) |
| 28 | + .catch(done); |
| 29 | + }); |
| 30 | + |
| 31 | + webpack5Test('should supports entry as descriptor', (done) => { |
| 32 | + testBin('--config ./test/fixtures/entry-as-descriptor/webpack.config --stats detailed') |
| 33 | + .then((output) => { |
| 34 | + expect(output.exitCode).toEqual(0); |
| 35 | + expect(output.stderr).toContain('foo.js'); |
| 36 | + done(); |
| 37 | + }) |
| 38 | + .catch(done); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should only prepends devServer entry points to "web" target', (done) => { |
| 42 | + testBin('--config ./test/fixtures/dev-server/default-config.js --target web') |
| 43 | + .then((output) => { |
| 44 | + expect(output.exitCode).toEqual(0); |
| 45 | + expect(output.stderr).toContain('client/default/index.js?'); |
| 46 | + expect(output.stderr).toContain('foo.js'); |
| 47 | + done(); |
| 48 | + }) |
| 49 | + .catch(done); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should not prepend devServer entry points to "node" target', (done) => { |
| 53 | + testBin('--config ./test/fixtures/dev-server/default-config.js --target node') |
| 54 | + .then((output) => { |
| 55 | + expect(output.exitCode).toEqual(0); |
| 56 | + expect(output.stderr).not.toContain('client/default/index.js?'); |
| 57 | + expect(output.stderr).toContain('foo.js'); |
| 58 | + done(); |
| 59 | + }) |
| 60 | + .catch(done); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should prepends the hot runtime to "node" target as well', (done) => { |
| 64 | + testBin('--config ./test/fixtures/dev-server/default-config.js --target node --hot') |
| 65 | + .then((output) => { |
| 66 | + expect(output.exitCode).toEqual(0); |
| 67 | + expect(output.stderr).toContain('webpack/hot/dev-server'); |
| 68 | + done(); |
| 69 | + }) |
| 70 | + .catch(done); |
| 71 | + }); |
| 72 | + |
| 73 | + it('does not use client.path when default', (done) => { |
| 74 | + testBin('--config ./test/fixtures/dev-server/client-default-path-config.js') |
| 75 | + .then((output) => { |
| 76 | + expect(output.exitCode).toEqual(0); |
| 77 | + expect(output.stderr).not.toContain('&path=/ws'); |
| 78 | + done(); |
| 79 | + }) |
| 80 | + .catch(done); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should use client.path when custom', (done) => { |
| 84 | + testBin('--config ./test/fixtures/dev-server/client-custom-path-config.js') |
| 85 | + .then((output) => { |
| 86 | + expect(output.exitCode).toEqual(0); |
| 87 | + expect(output.stderr).toContain('&path=/custom/path'); |
| 88 | + done(); |
| 89 | + }) |
| 90 | + .catch(done); |
| 91 | + }); |
| 92 | +}); |
0 commit comments