|
1 | 1 | import test from "ava" |
| 2 | +import * as path from "path" |
2 | 3 | import Webpack from "webpack" |
3 | 4 |
|
4 | 5 | const browserConfig = require("./webpack.web.config") |
@@ -30,6 +31,58 @@ test("can create a working server bundle with webpack", async t => { |
30 | 31 | const stats = await runWebpack(serverConfig) |
31 | 32 | t.deepEqual(stats.compilation.errors, [], stringifyWebpackError(stats.compilation.errors[0])) |
32 | 33 |
|
33 | | - const bundle = require("./dist.node/main") |
| 34 | + const bundle = require("./dist/app.node/main") |
34 | 35 | await bundle.test() |
35 | 36 | }) |
| 37 | + |
| 38 | +test("can inline a worker into an app bundle", async t => { |
| 39 | + // Bundle browser worker |
| 40 | + let stats = await runWebpack({ |
| 41 | + ...browserConfig, |
| 42 | + entry: require.resolve("./addition-worker"), |
| 43 | + output: { |
| 44 | + filename: "worker.js", |
| 45 | + path: path.resolve(__dirname, "dist/addition-worker.web") |
| 46 | + }, |
| 47 | + target: "webworker" |
| 48 | + }) |
| 49 | + t.deepEqual(stats.compilation.errors, [], stringifyWebpackError(stats.compilation.errors[0])) |
| 50 | + |
| 51 | + // Bundle server worker |
| 52 | + stats = await runWebpack({ |
| 53 | + ...serverConfig, |
| 54 | + entry: require.resolve("./addition-worker"), |
| 55 | + output: { |
| 56 | + filename: "worker.js", |
| 57 | + path: path.resolve(__dirname, "dist/addition-worker.node") |
| 58 | + } |
| 59 | + }) |
| 60 | + t.deepEqual(stats.compilation.errors, [], stringifyWebpackError(stats.compilation.errors[0])) |
| 61 | + |
| 62 | + // Bundle browser app |
| 63 | + stats = await runWebpack({ |
| 64 | + ...browserConfig, |
| 65 | + entry: require.resolve("./app-with-inlined-worker"), |
| 66 | + output: { |
| 67 | + ...serverConfig.output, |
| 68 | + path: path.resolve(__dirname, "dist/app-inlined.web") |
| 69 | + } |
| 70 | + }) |
| 71 | + t.deepEqual(stats.compilation.errors, [], stringifyWebpackError(stats.compilation.errors[0])) |
| 72 | + |
| 73 | + // Bundle server app |
| 74 | + stats = await runWebpack({ |
| 75 | + ...serverConfig, |
| 76 | + entry: require.resolve("./app-with-inlined-worker"), |
| 77 | + output: { |
| 78 | + ...serverConfig.output, |
| 79 | + path: path.resolve(__dirname, "dist/app-inlined.node") |
| 80 | + } |
| 81 | + }) |
| 82 | + t.deepEqual(stats.compilation.errors, [], stringifyWebpackError(stats.compilation.errors[0])) |
| 83 | + |
| 84 | + const bundle = require("./dist/app-inlined.node/main") |
| 85 | + const result = await bundle.test() |
| 86 | + |
| 87 | + t.is(result, "test succeeded") |
| 88 | +}) |
0 commit comments