|
| 1 | +import path from "path"; |
1 | 2 | import { webpack } from "./helpers"; |
2 | 3 | import RobotstxtPlugin from "../src/RobotstxtPlugin"; |
3 | 4 |
|
4 | 5 | describe("plugin", () => { |
5 | 6 | it("should execute successfully", async () => { |
6 | | - const stats = await webpack("entry.js"); |
7 | | - |
8 | | - const { warnings, errors, assets } = stats.compilation; |
| 7 | + const { stats, compiler } = await webpack("entry.js"); |
| 8 | + const { warnings, errors } = stats.compilation; |
9 | 9 |
|
10 | 10 | expect(warnings).toMatchSnapshot("warnings"); |
11 | 11 | expect(errors).toMatchSnapshot("errors"); |
12 | | - expect(assets["robots.txt"].source()).toMatchSnapshot(); |
| 12 | + expect( |
| 13 | + // eslint-disable-next-line no-sync |
| 14 | + compiler.outputFileSystem.readFileSync( |
| 15 | + path.resolve(compiler.outputPath, "robots.txt"), |
| 16 | + "utf-8" |
| 17 | + ) |
| 18 | + ).toMatchSnapshot(); |
13 | 19 | }); |
14 | 20 |
|
15 | 21 | it("should execute successfully #2", async () => { |
16 | | - const stats = await webpack("entry.js", { |
17 | | - plugins: [new RobotstxtPlugin()] |
| 22 | + const { stats, compiler } = await webpack("entry.js", { |
| 23 | + plugins: [new RobotstxtPlugin()], |
18 | 24 | }); |
19 | 25 |
|
20 | | - const { warnings, errors, assets } = stats.compilation; |
| 26 | + const { warnings, errors } = stats.compilation; |
21 | 27 |
|
22 | 28 | expect(warnings).toMatchSnapshot("warnings"); |
23 | 29 | expect(errors).toMatchSnapshot("errors"); |
24 | | - expect(assets["robots.txt"].source()).toMatchSnapshot(); |
| 30 | + expect( |
| 31 | + // eslint-disable-next-line no-sync |
| 32 | + compiler.outputFileSystem.readFileSync( |
| 33 | + path.resolve(compiler.outputPath, "robots.txt"), |
| 34 | + "utf-8" |
| 35 | + ) |
| 36 | + ).toMatchSnapshot(); |
25 | 37 | }); |
26 | 38 |
|
27 | 39 | it("should execute successfully with `filePath` option", async () => { |
28 | | - const stats = await webpack("entry.js", { |
| 40 | + const { stats, compiler } = await webpack("entry.js", { |
29 | 41 | pluginOptions: { |
30 | | - filePath: "robots.dev.txt" |
31 | | - } |
| 42 | + filePath: "robots.dev.txt", |
| 43 | + }, |
32 | 44 | }); |
33 | 45 |
|
34 | | - const { warnings, errors, assets } = stats.compilation; |
| 46 | + const { warnings, errors } = stats.compilation; |
35 | 47 |
|
36 | 48 | expect(warnings).toMatchSnapshot("warnings"); |
37 | 49 | expect(errors).toMatchSnapshot("errors"); |
38 | | - expect(assets["robots.dev.txt"].source()).toMatchSnapshot(); |
| 50 | + expect( |
| 51 | + // eslint-disable-next-line no-sync |
| 52 | + compiler.outputFileSystem.readFileSync( |
| 53 | + path.resolve(compiler.outputPath, "robots.dev.txt"), |
| 54 | + "utf-8" |
| 55 | + ) |
| 56 | + ).toMatchSnapshot(); |
39 | 57 | }); |
40 | 58 |
|
41 | 59 | it("should throw error on invalid `generate-robotstxt` options", async () => { |
42 | | - const stats = await webpack("entry.js", { |
| 60 | + const { stats } = await webpack("entry.js", { |
43 | 61 | pluginOptions: { |
44 | | - policy: {} |
45 | | - } |
| 62 | + policy: {}, |
| 63 | + }, |
46 | 64 | }); |
47 | 65 |
|
48 | 66 | const { warnings, errors } = stats.compilation; |
|
0 commit comments