MCPcopy
hub / github.com/webpack/webpack / createTestCase

Function createTestCase

test/WatchDetection.test.js:34–196  ·  view source on GitHub ↗

* @param {number} changeTimeout change timeout * @param {boolean=} invalidate need invalidate?

(changeTimeout, invalidate)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 6

beforeAllFunction · 0.85
afterAllFunction · 0.85
step1Function · 0.85
tapMethod · 0.80
itFunction · 0.50
webpackFunction · 0.50

Tested by

no test coverage detected