|
| 1 | +import path, { join } from 'path'; |
| 2 | + |
| 3 | +import { |
| 4 | + createWebpackDevServerDriver, |
| 5 | + WEBPACK_CLI_VERSION, |
| 6 | + WEBPACK_DEV_SERVER_VERSION, |
| 7 | +} from './sandbox/WebpackDevServerDriver'; |
| 8 | +import { createSandbox, Sandbox } from './sandbox/Sandbox'; |
| 9 | +import { readFixture } from './sandbox/Fixture'; |
| 10 | +import { FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION } from './sandbox/Plugin'; |
| 11 | +import { createGenericProcessDriver } from './sandbox/GenericProcessDriver'; |
| 12 | + |
| 13 | +describe('Webpack Inclusive Watcher', () => { |
| 14 | + let sandbox: Sandbox; |
| 15 | + |
| 16 | + beforeAll(async () => { |
| 17 | + sandbox = await createSandbox(); |
| 18 | + }); |
| 19 | + |
| 20 | + beforeEach(async () => { |
| 21 | + await sandbox.reset(); |
| 22 | + }); |
| 23 | + |
| 24 | + afterAll(async () => { |
| 25 | + await sandbox.cleanup(); |
| 26 | + }); |
| 27 | + |
| 28 | + it.each([{ async: false }, { async: true }])( |
| 29 | + 'ignores package.json change for %p', |
| 30 | + async ({ async }) => { |
| 31 | + await sandbox.load([ |
| 32 | + await readFixture(path.join(__dirname, 'fixtures/environment/typescript-basic.fixture'), { |
| 33 | + FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION: JSON.stringify( |
| 34 | + FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION |
| 35 | + ), |
| 36 | + TS_LOADER_VERSION: JSON.stringify('^7.0.0'), |
| 37 | + TYPESCRIPT_VERSION: JSON.stringify('4.6.3'), |
| 38 | + WEBPACK_VERSION: JSON.stringify('^5.0.0'), |
| 39 | + WEBPACK_CLI_VERSION: JSON.stringify(WEBPACK_CLI_VERSION), |
| 40 | + WEBPACK_DEV_SERVER_VERSION: JSON.stringify(WEBPACK_DEV_SERVER_VERSION), |
| 41 | + ASYNC: JSON.stringify(async), |
| 42 | + }), |
| 43 | + await readFixture(join(__dirname, 'fixtures/implementation/typescript-basic.fixture')), |
| 44 | + await readFixture( |
| 45 | + path.join(__dirname, 'fixtures/implementation/typescript-package.fixture') |
| 46 | + ), |
| 47 | + ]); |
| 48 | + |
| 49 | + // add import to typescript-nested-project project |
| 50 | + await sandbox.patch( |
| 51 | + 'src/index.ts', |
| 52 | + "import { getUserName } from './model/User';", |
| 53 | + [ |
| 54 | + "import { getUserName } from './model/User';", |
| 55 | + 'import { sayHello } from "../package";', |
| 56 | + '', |
| 57 | + "sayHello('World');", |
| 58 | + ].join('\n') |
| 59 | + ); |
| 60 | + |
| 61 | + // start webpack dev server |
| 62 | + const process = sandbox.spawn('npm run webpack-dev-server'); |
| 63 | + const baseDriver = createGenericProcessDriver(process); |
| 64 | + const webpackDriver = createWebpackDevServerDriver(process, async); |
| 65 | + |
| 66 | + await webpackDriver.waitForNoErrors(); |
| 67 | + |
| 68 | + // update nested package.json file |
| 69 | + await sandbox.patch('package/package.json', '"1.0.0"', '"1.0.1"'); |
| 70 | + |
| 71 | + // wait for 5 seconds and fail if there is Debug Failure. in the console output |
| 72 | + await expect(() => |
| 73 | + baseDriver.waitForStderrIncludes('Error: Debug Failure.', 5000) |
| 74 | + ).rejects.toEqual( |
| 75 | + new Error('Exceeded time on waiting for "Error: Debug Failure." to appear in the stderr.') |
| 76 | + ); |
| 77 | + |
| 78 | + await webpackDriver.waitForNoErrors(); |
| 79 | + } |
| 80 | + ); |
| 81 | +}); |
0 commit comments