|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const path = require("path"); |
| 4 | +const fs = require("graceful-fs"); |
| 5 | + |
| 6 | +const webpack = require(".."); |
| 7 | + |
| 8 | +it("should cache assets", done => { |
| 9 | + const entry1File = path.join(__dirname, "js", "BannerPlugin", "entry1.js"); |
| 10 | + const entry2File = path.join(__dirname, "js", "BannerPlugin", "entry2.js"); |
| 11 | + try { |
| 12 | + fs.mkdirSync(path.join(__dirname, "js", "BannerPlugin"), { |
| 13 | + recursive: true |
| 14 | + }); |
| 15 | + } catch (e) { |
| 16 | + // empty |
| 17 | + } |
| 18 | + const compiler = webpack({ |
| 19 | + mode: "development", |
| 20 | + entry: { |
| 21 | + entry1: entry1File, |
| 22 | + entry2: entry2File |
| 23 | + }, |
| 24 | + output: { |
| 25 | + path: path.join(__dirname, "js", "BannerPlugin", "output") |
| 26 | + }, |
| 27 | + plugins: [new webpack.BannerPlugin("banner is a string")] |
| 28 | + }); |
| 29 | + fs.writeFileSync(entry1File, "1", "utf-8"); |
| 30 | + fs.writeFileSync(entry2File, "1", "utf-8"); |
| 31 | + compiler.run(err => { |
| 32 | + if (err) return done(err); |
| 33 | + fs.writeFileSync(entry2File, "2", "utf-8"); |
| 34 | + compiler.run((err, stats) => { |
| 35 | + const { assets } = stats.toJson(); |
| 36 | + expect(assets.find(as => as.name === "entry1.js").emitted).toBe(false); |
| 37 | + expect(assets.find(as => as.name === "entry2.js").emitted).toBe(true); |
| 38 | + done(err); |
| 39 | + }); |
| 40 | + }); |
| 41 | +}); |
0 commit comments