|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const path = require("path"); |
| 4 | +const Watchpack = require("../lib"); |
| 5 | +const TestHelper = require("./helpers/TestHelper"); |
| 6 | + |
| 7 | +const fixtures = path.join(__dirname, "fixtures"); |
| 8 | +const testHelper = new TestHelper(fixtures); |
| 9 | + |
| 10 | +// eslint-disable-next-line jest/no-confusing-set-timeout |
| 11 | +jest.setTimeout(20000); |
| 12 | + |
| 13 | +describe("Missing file below a path that is a file (#226)", () => { |
| 14 | + beforeEach((done) => { |
| 15 | + testHelper.before(done); |
| 16 | + }); |
| 17 | + |
| 18 | + /** @type {InstanceType<typeof Watchpack>[]} */ |
| 19 | + let watchers = []; |
| 20 | + |
| 21 | + afterEach((done) => { |
| 22 | + // closed here, not in the test, so a failure cannot leave one running |
| 23 | + for (const w of watchers) w.close(); |
| 24 | + watchers = []; |
| 25 | + jest.restoreAllMocks(); |
| 26 | + testHelper.after(done); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should report the file once its parent turns from a file into a directory", (done) => { |
| 30 | + // a resolver tried `foo/index.js` while `foo` is a file |
| 31 | + testHelper.file("foo"); |
| 32 | + const missing = path.join(fixtures, "foo", "index.js"); |
| 33 | + const errors = jest.spyOn(console, "error").mockImplementation(() => {}); |
| 34 | + testHelper.tick(1000, () => { |
| 35 | + const w = new Watchpack({ aggregateTimeout: 100 }); |
| 36 | + watchers.push(w); |
| 37 | + w.on("change", (item) => { |
| 38 | + expect(item).toBe(missing); |
| 39 | + expect(errors).not.toHaveBeenCalled(); |
| 40 | + done(); |
| 41 | + }); |
| 42 | + w.watch({ missing: [missing], startTime: Date.now() }); |
| 43 | + testHelper.tick(1000, () => { |
| 44 | + testHelper.remove("foo"); |
| 45 | + testHelper.dir("foo"); |
| 46 | + testHelper.file(path.join("foo", "index.js")); |
| 47 | + }); |
| 48 | + }); |
| 49 | + }); |
| 50 | +}); |
0 commit comments