|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const testServer = require('../helpers/test-server'); |
| 4 | +const config = require('../fixtures/provide-plugin-config/webpack.config'); |
| 5 | +const runBrowser = require('../helpers/run-browser'); |
| 6 | + |
| 7 | +describe('ProvidePlugin', () => { |
| 8 | + describe('inline', () => { |
| 9 | + beforeAll((done) => { |
| 10 | + const options = { |
| 11 | + port: 9000, |
| 12 | + host: '0.0.0.0', |
| 13 | + inline: true, |
| 14 | + watchOptions: { |
| 15 | + poll: true, |
| 16 | + }, |
| 17 | + }; |
| 18 | + testServer.startAwaitingCompilation(config, options, done); |
| 19 | + }); |
| 20 | + |
| 21 | + afterAll(testServer.close); |
| 22 | + |
| 23 | + describe('on browser client', () => { |
| 24 | + jest.setTimeout(30000); |
| 25 | + |
| 26 | + it('should inject SockJS client implementation', (done) => { |
| 27 | + runBrowser().then(({ page, browser }) => { |
| 28 | + page.waitForNavigation({ waitUntil: 'load' }).then(() => { |
| 29 | + page |
| 30 | + .evaluate(() => { |
| 31 | + return window.injectedClient === window.expectedClient; |
| 32 | + }) |
| 33 | + .then((isCorrectClient) => { |
| 34 | + expect(isCorrectClient).toBeTruthy(); |
| 35 | + browser.close().then(done); |
| 36 | + }); |
| 37 | + }); |
| 38 | + page.goto('http://localhost:9000/main'); |
| 39 | + }); |
| 40 | + }); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe('not inline', () => { |
| 45 | + beforeAll((done) => { |
| 46 | + const options = { |
| 47 | + port: 9000, |
| 48 | + host: '0.0.0.0', |
| 49 | + inline: false, |
| 50 | + watchOptions: { |
| 51 | + poll: true, |
| 52 | + }, |
| 53 | + }; |
| 54 | + testServer.startAwaitingCompilation(config, options, done); |
| 55 | + }); |
| 56 | + |
| 57 | + afterAll(testServer.close); |
| 58 | + |
| 59 | + describe('on browser client', () => { |
| 60 | + jest.setTimeout(30000); |
| 61 | + |
| 62 | + it('should not inject client implementation', (done) => { |
| 63 | + runBrowser().then(({ page, browser }) => { |
| 64 | + page.waitForNavigation({ waitUntil: 'load' }).then(() => { |
| 65 | + page |
| 66 | + .evaluate(() => { |
| 67 | + // eslint-disable-next-line no-undefined |
| 68 | + return window.injectedClient === undefined; |
| 69 | + }) |
| 70 | + .then((isCorrectClient) => { |
| 71 | + expect(isCorrectClient).toBeTruthy(); |
| 72 | + browser.close().then(done); |
| 73 | + }); |
| 74 | + }); |
| 75 | + page.goto('http://localhost:9000/main'); |
| 76 | + }); |
| 77 | + }); |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments