* @param {number} changeTimeout change timeout * @param {boolean=} invalidate need invalidate?
(changeTimeout, invalidate)
| 32 | * @param {boolean=} invalidate need invalidate? |
| 33 | */ |
| 34 | function createTestCase(changeTimeout, invalidate) { |
| 35 | describe(`time between changes ${changeTimeout}ms${ |
| 36 | invalidate ? class="st">" with invalidate call" : class="st">"" |
| 37 | }`, () => { |
| 38 | const fixturePath = path.join( |
| 39 | __dirname, |
| 40 | class="st">"fixtures", |
| 41 | `temp-${changeTimeout}` |
| 42 | ); |
| 43 | const filePath = path.join(fixturePath, class="st">"file.js"); |
| 44 | const file2Path = path.join(fixturePath, class="st">"file2.js"); |
| 45 | const loaderPath = path.join(__dirname, class="st">"fixtures", class="st">"delay-loader.js"); |
| 46 | |
| 47 | beforeAll(() => { |
| 48 | try { |
| 49 | fs.mkdirSync(fixturePath); |
| 50 | } catch (_err) { |
| 51 | class="cm">// empty |
| 52 | } |
| 53 | fs.writeFileSync(filePath, class="st">"require('./file2')", class="st">"utf8"); |
| 54 | fs.writeFileSync(file2Path, class="st">"original", class="st">"utf8"); |
| 55 | }); |
| 56 | |
| 57 | afterAll((done) => { |
| 58 | setTimeout(() => { |
| 59 | try { |
| 60 | fs.unlinkSync(filePath); |
| 61 | } catch (_err) { |
| 62 | class="cm">// empty |
| 63 | } |
| 64 | try { |
| 65 | fs.unlinkSync(file2Path); |
| 66 | } catch (_err) { |
| 67 | class="cm">// empty |
| 68 | } |
| 69 | try { |
| 70 | fs.rmdirSync(fixturePath); |
| 71 | } catch (_err) { |
| 72 | class="cm">// empty |
| 73 | } |
| 74 | done(); |
| 75 | }, 100); class="cm">// cool down a bit |
| 76 | }); |
| 77 | |
| 78 | it(class="st">"should build the bundle correctly", (done) => { |
| 79 | const compiler = webpack({ |
| 80 | mode: class="st">"development", |
| 81 | entry: `${loaderPath}!${filePath}`, |
| 82 | output: { |
| 83 | path: class="st">"/directory", |
| 84 | filename: class="st">"bundle.js" |
| 85 | } |
| 86 | }); |
| 87 | const memfs = (compiler.outputFileSystem = |
| 88 | /** @type {import(class="st">"../").OutputFileSystem & import(class="st">"memfs").IFs} */ ( |
| 89 | /** @type {unknown} */ (createFsFromVolume(new Volume())) |
| 90 | )); |
| 91 | /** @type {(() => void) | null | undefined} */ |