@rspack/test-tools 1.7.0-beta.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/case/builtin.d.ts +2 -2
  2. package/dist/case/builtin.js +58 -58
  3. package/dist/case/cache.d.ts +2 -2
  4. package/dist/case/cache.js +34 -34
  5. package/dist/case/common.d.ts +2 -2
  6. package/dist/case/common.js +45 -45
  7. package/dist/case/compiler.d.ts +3 -3
  8. package/dist/case/compiler.js +21 -21
  9. package/dist/case/config.d.ts +3 -3
  10. package/dist/case/config.js +19 -19
  11. package/dist/case/defaults.d.ts +2 -2
  12. package/dist/case/defaults.js +10 -10
  13. package/dist/case/diagnostic.js +29 -29
  14. package/dist/case/error.d.ts +2 -2
  15. package/dist/case/error.js +21 -21
  16. package/dist/case/esm-output.js +30 -26
  17. package/dist/case/example.js +7 -7
  18. package/dist/case/hash.d.ts +2 -2
  19. package/dist/case/hash.js +16 -16
  20. package/dist/case/hook.d.ts +3 -3
  21. package/dist/case/hook.js +42 -42
  22. package/dist/case/hot-step.d.ts +2 -2
  23. package/dist/case/hot-step.js +46 -46
  24. package/dist/case/hot.d.ts +5 -5
  25. package/dist/case/hot.js +43 -43
  26. package/dist/case/incremental.d.ts +2 -2
  27. package/dist/case/incremental.js +9 -9
  28. package/dist/case/index.d.ts +31 -31
  29. package/dist/case/multi-compiler.d.ts +3 -3
  30. package/dist/case/multi-compiler.js +15 -15
  31. package/dist/case/native-watcher.js +6 -6
  32. package/dist/case/normal.js +46 -46
  33. package/dist/case/runner.d.ts +2 -2
  34. package/dist/case/runner.js +22 -15
  35. package/dist/case/serial.d.ts +2 -2
  36. package/dist/case/serial.js +4 -4
  37. package/dist/case/stats-api.d.ts +2 -2
  38. package/dist/case/stats-api.js +7 -7
  39. package/dist/case/stats-output.d.ts +2 -2
  40. package/dist/case/stats-output.js +45 -45
  41. package/dist/case/treeshaking.js +6 -6
  42. package/dist/case/watch.d.ts +1 -1
  43. package/dist/case/watch.js +59 -59
  44. package/dist/compiler.d.ts +3 -3
  45. package/dist/compiler.js +31 -31
  46. package/dist/helper/directory.d.ts +1 -1
  47. package/dist/helper/directory.js +15 -15
  48. package/dist/helper/disable-iconv-lite-warning.js +3 -3
  49. package/dist/helper/expect/diff.js +8 -8
  50. package/dist/helper/expect/error.js +9 -9
  51. package/dist/helper/expect/placeholder.js +9 -9
  52. package/dist/helper/expect/rspack.js +5 -5
  53. package/dist/helper/expect/to-be-typeof.js +2 -2
  54. package/dist/helper/expect/to-end-with.js +3 -3
  55. package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -1
  56. package/dist/helper/expect/to-match-file-snapshot.js +23 -23
  57. package/dist/helper/hot-update/index.d.ts +1 -1
  58. package/dist/helper/hot-update/loader.js +1 -1
  59. package/dist/helper/hot-update/plugin.d.ts +1 -1
  60. package/dist/helper/hot-update/plugin.js +15 -15
  61. package/dist/helper/index.d.ts +8 -8
  62. package/dist/helper/is.js +2 -2
  63. package/dist/helper/legacy/EventSourceForNode.js +8 -8
  64. package/dist/helper/legacy/LogTestPlugin.js +18 -18
  65. package/dist/helper/legacy/asModule.js +6 -6
  66. package/dist/helper/legacy/captureStdio.js +6 -6
  67. package/dist/helper/legacy/checkArrayExpectation.js +26 -23
  68. package/dist/helper/legacy/copyDiff.js +5 -5
  69. package/dist/helper/legacy/createFakeWorker.js +13 -13
  70. package/dist/helper/legacy/createLazyTestEnv.js +11 -11
  71. package/dist/helper/legacy/currentScript.js +1 -1
  72. package/dist/helper/legacy/deprecationTracking.js +13 -19
  73. package/dist/helper/legacy/expectSource.js +5 -5
  74. package/dist/helper/legacy/fakeSystem.js +14 -14
  75. package/dist/helper/legacy/findOutputFiles.js +4 -4
  76. package/dist/helper/legacy/parseResource.js +4 -4
  77. package/dist/helper/legacy/regexEscape.js +2 -2
  78. package/dist/helper/legacy/supportDefaultAssignment.js +2 -2
  79. package/dist/helper/legacy/supportsTextDecoder.js +2 -2
  80. package/dist/helper/legacy/supportsUsing.js +1 -1
  81. package/dist/helper/legacy/urlToRelativePath.js +3 -3
  82. package/dist/helper/parse-modules.js +13 -13
  83. package/dist/helper/read-config-file.d.ts +2 -2
  84. package/dist/helper/read-config-file.js +3 -3
  85. package/dist/helper/serializers.d.ts +1 -1
  86. package/dist/helper/serializers.js +11 -11
  87. package/dist/helper/setup-env.js +17 -17
  88. package/dist/helper/setup-expect.js +1 -1
  89. package/dist/helper/setup-wasm.js +4 -4
  90. package/dist/helper/stringify-config.d.ts +1 -1
  91. package/dist/helper/stringify-config.js +3 -3
  92. package/dist/helper/update-snapshot.js +1 -1
  93. package/dist/helper/util/checkSourceMap.js +16 -17
  94. package/dist/helper/util/checkStats.js +3 -3
  95. package/dist/helper/util/expectWarningFactory.js +2 -2
  96. package/dist/helper/util/filterUtil.js +9 -9
  97. package/dist/index.d.ts +8 -8
  98. package/dist/index.js +1 -1
  99. package/dist/plugin/index.d.ts +1 -1
  100. package/dist/plugin/lazy-compilation-test-plugin.d.ts +1 -1
  101. package/dist/plugin/lazy-compilation-test-plugin.js +13 -13
  102. package/dist/runner/index.d.ts +2 -2
  103. package/dist/runner/node/index.d.ts +2 -2
  104. package/dist/runner/node/index.js +75 -74
  105. package/dist/runner/web/index.d.ts +2 -2
  106. package/dist/runner/web/index.js +45 -45
  107. package/dist/test/context.d.ts +2 -2
  108. package/dist/test/context.js +4 -4
  109. package/dist/test/creator.d.ts +1 -1
  110. package/dist/test/creator.js +28 -28
  111. package/dist/test/debug.d.ts +1 -1
  112. package/dist/test/debug.js +31 -31
  113. package/dist/test/tester.d.ts +1 -1
  114. package/dist/test/tester.js +11 -11
  115. package/dist/type.d.ts +3 -3
  116. package/package.json +7 -7
  117. package/rstest.d.ts +12 -12
@@ -21,7 +21,7 @@ async function loopFile(dir, callback) {
21
21
  }
22
22
  }));
23
23
  }
24
- const PLUGIN_NAME = "HotUpdatePlugin";
24
+ const PLUGIN_NAME = 'HotUpdatePlugin';
25
25
  const MAX_UPDATE_INDEX = 100;
26
26
  class HotUpdatePlugin {
27
27
  constructor(projectDir, tempDir) {
@@ -33,8 +33,8 @@ class HotUpdatePlugin {
33
33
  }
34
34
  getContent(filePath, index) {
35
35
  const contents = this.files[filePath] || [];
36
- let content = contents[index] === undefined ? contents.at(-1) || "" : contents[index];
37
- let command = "";
36
+ let content = contents[index] === undefined ? contents.at(-1) || '' : contents[index];
37
+ let command = '';
38
38
  const matchResult = content.match(/^<(.+?)>([\w\W]*)$/);
39
39
  if (matchResult) {
40
40
  command = matchResult[1];
@@ -42,18 +42,18 @@ class HotUpdatePlugin {
42
42
  }
43
43
  return {
44
44
  content,
45
- command
45
+ command,
46
46
  };
47
47
  }
48
48
  async updateFiles() {
49
49
  await Promise.all(this.getModifiedFiles().map(async (filePath) => {
50
50
  const { content, command } = this.getContent(filePath, this.updateIndex);
51
51
  // match command
52
- if (command === "delete") {
52
+ if (command === 'delete') {
53
53
  await fs_extra_1.default.remove(filePath);
54
54
  return;
55
55
  }
56
- if (command === "force_write") {
56
+ if (command === 'force_write') {
57
57
  await fs_extra_1.default.writeFile(filePath, content);
58
58
  return;
59
59
  }
@@ -93,15 +93,15 @@ class HotUpdatePlugin {
93
93
  }
94
94
  async goNext() {
95
95
  if (this.updateIndex > MAX_UPDATE_INDEX) {
96
- throw new Error("NEXT_* has been called more than the maximum times");
96
+ throw new Error('NEXT_* has been called more than the maximum times');
97
97
  }
98
98
  this.updateIndex++;
99
99
  await this.updateFiles();
100
100
  }
101
101
  async moveTempDir() {
102
102
  // generate next temp dir path.
103
- const nextTempDir = this.tempDir.replace(/(___[0-9]+)?[/\\]*$/, "") +
104
- "___" +
103
+ const nextTempDir = this.tempDir.replace(/(___[0-9]+)?[/\\]*$/, '') +
104
+ '___' +
105
105
  this.updateIndex;
106
106
  // update this.files.
107
107
  for (const key of Object.keys(this.files)) {
@@ -124,21 +124,21 @@ class HotUpdatePlugin {
124
124
  test: /\.(js|css|json)/,
125
125
  use: [
126
126
  {
127
- loader: node_path_1.default.resolve(__dirname, "./loader.js")
128
- }
129
- ]
127
+ loader: node_path_1.default.resolve(__dirname, './loader.js'),
128
+ },
129
+ ],
130
130
  });
131
131
  let isRebuild = false;
132
132
  compiler.hooks.beforeRun.tap(PLUGIN_NAME, () => {
133
133
  compiler.modifiedFiles = new Set(isRebuild ? this.getModifiedFiles() : []);
134
134
  isRebuild = true;
135
135
  });
136
- compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
136
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
137
137
  compilation.hooks.additionalTreeRuntimeRequirements.tap(PLUGIN_NAME, (_chunk, set) => {
138
138
  set.add(compiler.rspack.RuntimeGlobals.moduleCache);
139
139
  });
140
140
  compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module, _set) => {
141
- if (module.constructorName === "DefinePropertyGettersRuntimeModule") {
141
+ if (module.constructorName === 'DefinePropertyGettersRuntimeModule') {
142
142
  module.source.source = Buffer.from(`
143
143
  ${RuntimeGlobals.definePropertyGetters} = function (exports, definition) {
144
144
  for (var key in definition) {
@@ -147,7 +147,7 @@ class HotUpdatePlugin {
147
147
  }
148
148
  }
149
149
  };
150
- `, "utf-8");
150
+ `, 'utf-8');
151
151
  }
152
152
  });
153
153
  });
@@ -1,8 +1,8 @@
1
- export * from "./directory";
2
- export * from "./is";
3
- export * from "./parse-modules";
4
- export * from "./read-config-file";
5
- export * from "./stringify-config";
6
- export * from "./update-snapshot";
7
- export * from "./util/checkStats";
8
- export * from "./win";
1
+ export * from './directory';
2
+ export * from './is';
3
+ export * from './parse-modules';
4
+ export * from './read-config-file';
5
+ export * from './stringify-config';
6
+ export * from './update-snapshot';
7
+ export * from './util/checkStats';
8
+ export * from './win';
package/dist/helper/is.js CHANGED
@@ -8,8 +8,8 @@ exports.isCss = isCss;
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  function isJavaScript(filePath) {
10
10
  const ext = node_path_1.default.extname(filePath).toLowerCase();
11
- return ext === ".js" || ext === ".mjs";
11
+ return ext === '.js' || ext === '.mjs';
12
12
  }
13
13
  function isCss(filePath) {
14
- return node_path_1.default.extname(filePath).toLowerCase() === ".css";
14
+ return node_path_1.default.extname(filePath).toLowerCase() === '.css';
15
15
  }
@@ -8,21 +8,21 @@
8
8
  * Copyright (c) JS Foundation and other contributors
9
9
  * https://github.com/webpack/webpack/blob/main/LICENSE
10
10
  */
11
- "use strict";
11
+ 'use strict';
12
12
  module.exports = class EventSource {
13
13
  constructor(url) {
14
14
  this.response = undefined;
15
- const request = (url.startsWith("https:") ? require("node:https") : require("node:http")).request(url, {
15
+ const request = (url.startsWith('https:') ? require('node:https') : require('node:http')).request(url, {
16
16
  agent: false,
17
- headers: { accept: "text/event-stream" }
18
- }, res => {
17
+ headers: { accept: 'text/event-stream' },
18
+ }, (res) => {
19
19
  this.response = res;
20
- res.on("error", err => {
20
+ res.on('error', (err) => {
21
21
  if (this.onerror)
22
22
  this.onerror(err);
23
23
  });
24
24
  });
25
- request.on("error", err => {
25
+ request.on('error', (err) => {
26
26
  if (this.onerror)
27
27
  this.onerror({ message: err });
28
28
  });
@@ -32,9 +32,9 @@ module.exports = class EventSource {
32
32
  this.response.destroy();
33
33
  }
34
34
  set onopen(value) {
35
- throw new Error("not implemented");
35
+ throw new Error('not implemented');
36
36
  }
37
37
  set onmessage(value) {
38
- throw new Error("not implemented");
38
+ throw new Error('not implemented');
39
39
  }
40
40
  };
@@ -5,31 +5,31 @@ module.exports = class LogTestPlugin {
5
5
  this.noTraced = noTraced;
6
6
  }
7
7
  apply(compiler) {
8
- const logSome = logger => {
9
- logger.group("Group");
8
+ const logSome = (logger) => {
9
+ logger.group('Group');
10
10
  if (!this.noTraced) {
11
- logger.error("Error");
12
- logger.warn("Warning");
11
+ logger.error('Error');
12
+ logger.warn('Warning');
13
13
  }
14
- logger.info("Info");
15
- logger.log("Log");
16
- logger.debug("Debug");
17
- logger.groupCollapsed("Collapsed group");
18
- logger.log("Log inside collapsed group");
19
- logger.group("Inner group");
20
- logger.log("Inner inner message");
14
+ logger.info('Info');
15
+ logger.log('Log');
16
+ logger.debug('Debug');
17
+ logger.groupCollapsed('Collapsed group');
18
+ logger.log('Log inside collapsed group');
19
+ logger.group('Inner group');
20
+ logger.log('Inner inner message');
21
21
  logger.groupEnd();
22
22
  logger.groupEnd();
23
- logger.log("Log");
23
+ logger.log('Log');
24
24
  logger.groupEnd();
25
- logger.log("End");
25
+ logger.log('End');
26
26
  };
27
- logSome(compiler.getInfrastructureLogger("LogTestPlugin"));
28
- compiler.hooks.compilation.tap("LogTestPlugin", compilation => {
29
- const logger = compilation.getLogger("LogTestPlugin");
27
+ logSome(compiler.getInfrastructureLogger('LogTestPlugin'));
28
+ compiler.hooks.compilation.tap('LogTestPlugin', (compilation) => {
29
+ const logger = compilation.getLogger('LogTestPlugin');
30
30
  logSome(logger);
31
- const otherLogger = compilation.getLogger("LogOtherTestPlugin");
32
- otherLogger.debug("debug message only");
31
+ const otherLogger = compilation.getLogger('LogOtherTestPlugin');
32
+ otherLogger.debug('debug message only');
33
33
  });
34
34
  }
35
35
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
- const vm = require("node:vm");
4
- const SYNTHETIC_MODULES_STORE = "__SYNTHETIC_MODULES_STORE";
3
+ const vm = require('node:vm');
4
+ const SYNTHETIC_MODULES_STORE = '__SYNTHETIC_MODULES_STORE';
5
5
  module.exports = async (something, context, unlinked) => {
6
6
  if (something instanceof (vm.Module || /* node.js 10 */ vm.SourceTextModule)) {
7
7
  return something;
@@ -9,11 +9,11 @@ module.exports = async (something, context, unlinked) => {
9
9
  context[SYNTHETIC_MODULES_STORE] = context[SYNTHETIC_MODULES_STORE] || [];
10
10
  const i = context[SYNTHETIC_MODULES_STORE].length;
11
11
  context[SYNTHETIC_MODULES_STORE].push(something);
12
- const code = [...new Set(["default", ...Object.keys(something)])]
13
- .map(name => `const _${name} = ${SYNTHETIC_MODULES_STORE}[${i}]${name === "default" ? "" : `[${JSON.stringify(name)}]`}; export { _${name} as ${name}};`)
14
- .join("\n");
12
+ const code = [...new Set(['default', ...Object.keys(something)])]
13
+ .map((name) => `const _${name} = ${SYNTHETIC_MODULES_STORE}[${i}]${name === 'default' ? '' : `[${JSON.stringify(name)}]`}; export { _${name} as ${name}};`)
14
+ .join('\n');
15
15
  const m = new vm.SourceTextModule(code, {
16
- context
16
+ context,
17
17
  });
18
18
  if (unlinked)
19
19
  return m;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
- const { stripVTControlCharacters: stripAnsi } = require("node:util");
3
+ const { stripVTControlCharacters: stripAnsi } = require('node:util');
4
4
  module.exports = (stdio, tty) => {
5
5
  let logs = [];
6
6
  const write = stdio.write;
7
7
  const isTTY = stdio.isTTY;
8
- stdio.write = str => {
8
+ stdio.write = (str) => {
9
9
  logs.push(str);
10
10
  };
11
11
  if (tty !== undefined)
@@ -14,19 +14,19 @@ module.exports = (stdio, tty) => {
14
14
  data: logs,
15
15
  reset: () => (logs = []),
16
16
  toString: () => {
17
- return stripAnsi(logs.join("")).replace(/\([^)]+\) (\[[^\]]+\]\s*)?(Deprecation|Experimental)Warning.+(\n\(Use .node.+\))?(\n(\s|BREAKING CHANGE).*)*(\n\s+at .*)*\n?/g, "");
17
+ return stripAnsi(logs.join('')).replace(/\([^)]+\) (\[[^\]]+\]\s*)?(Deprecation|Experimental)Warning.+(\n\(Use .node.+\))?(\n(\s|BREAKING CHANGE).*)*(\n\s+at .*)*\n?/g, '');
18
18
  },
19
19
  toStringRaw: () => {
20
- return logs.join("");
20
+ return logs.join('');
21
21
  },
22
22
  restore() {
23
23
  stdio.write = write;
24
24
  stdio.isTTY = isTTY;
25
- delete require.cache[require.resolve("../../")];
25
+ delete require.cache[require.resolve('../../')];
26
26
  // delete require.cache[
27
27
  // require.resolve("../../lib/node/NodeEnvironmentPlugin")
28
28
  // ];
29
29
  // delete require.cache[require.resolve("../../lib/node/nodeConsole")];
30
- }
30
+ },
31
31
  };
32
32
  };
@@ -1,38 +1,38 @@
1
1
  // @ts-nocheck
2
- "use strict";
3
- const fs = require("fs-extra");
4
- const path = require("node:path");
2
+ 'use strict';
3
+ const fs = require('fs-extra');
4
+ const path = require('node:path');
5
5
  const check = (expected, actual) => {
6
6
  if (expected instanceof RegExp) {
7
7
  expected = { message: expected };
8
8
  }
9
9
  if (Array.isArray(expected)) {
10
- return expected.every(e => check(e, actual));
10
+ return expected.every((e) => check(e, actual));
11
11
  }
12
- return Object.keys(expected).every(key => {
12
+ return Object.keys(expected).every((key) => {
13
13
  let value = actual[key];
14
- if (typeof value === "object") {
14
+ if (typeof value === 'object') {
15
15
  value = JSON.stringify(value);
16
16
  }
17
17
  return expected[key].test(value);
18
18
  });
19
19
  };
20
- const explain = object => {
20
+ const explain = (object) => {
21
21
  if (object instanceof RegExp) {
22
22
  object = { message: object };
23
23
  }
24
24
  return Object.keys(object)
25
- .map(key => {
25
+ .map((key) => {
26
26
  let value = object[key];
27
- if (typeof value === "object" && !(value instanceof RegExp)) {
27
+ if (typeof value === 'object' && !(value instanceof RegExp)) {
28
28
  value = JSON.stringify(value);
29
29
  }
30
30
  let msg = `${key} = ${value}`;
31
- if (key !== "stack" && key !== "details" && msg.length > 600)
32
- msg = msg.slice(0, 597) + "...";
31
+ if (key !== 'stack' && key !== 'details' && msg.length > 600)
32
+ msg = msg.slice(0, 597) + '...';
33
33
  return msg;
34
34
  })
35
- .join("; ");
35
+ .join('; ');
36
36
  };
37
37
  const diffItems = (actual, expected, kind) => {
38
38
  const tooMuch = actual.slice();
@@ -51,21 +51,24 @@ const diffItems = (actual, expected, kind) => {
51
51
  const diff = [];
52
52
  if (missing.length > 0) {
53
53
  diff.push(`The following expected ${kind}s are missing:
54
- ${missing.map(item => `${explain(item)}`).join("\n\n")}`);
54
+ ${missing.map((item) => `${explain(item)}`).join('\n\n')}`);
55
55
  }
56
56
  if (tooMuch.length > 0) {
57
57
  diff.push(`The following ${kind}s are unexpected:
58
- ${tooMuch.map(item => `${explain(item)}`).join("\n\n")}`);
58
+ ${tooMuch.map((item) => `${explain(item)}`).join('\n\n')}`);
59
59
  }
60
- return diff.join("\n\n");
60
+ return diff.join('\n\n');
61
61
  };
62
62
  module.exports = async function checkArrayExpectation(testDirectory, object, kind, filename, upperCaseKind, options, done) {
63
- done = typeof done === "function" ? done : error => {
64
- throw error;
65
- };
63
+ done =
64
+ typeof done === 'function'
65
+ ? done
66
+ : (error) => {
67
+ throw error;
68
+ };
66
69
  let array = object[`${kind}s`];
67
- if (Array.isArray(array) && kind === "warning") {
68
- array = array.filter(item => !/from Terser/.test(item));
70
+ if (Array.isArray(array) && kind === 'warning') {
71
+ array = array.filter((item) => !/from Terser/.test(item));
69
72
  }
70
73
  if (fs.existsSync(path.join(testDirectory, `${filename}.js`))) {
71
74
  // CHANGE: added file for sorting messages in multi-thread environment
@@ -75,7 +78,7 @@ module.exports = async function checkArrayExpectation(testDirectory, object, kin
75
78
  }
76
79
  const expectedFilename = path.join(testDirectory, `${filename}.js`);
77
80
  let expected = require(expectedFilename);
78
- if (typeof expected === "function") {
81
+ if (typeof expected === 'function') {
79
82
  expected = expected(options);
80
83
  }
81
84
  const diff = diffItems(array, expected, kind);
@@ -127,7 +130,7 @@ module.exports = async function checkArrayExpectation(testDirectory, object, kin
127
130
  }
128
131
  if (unused.length > 0) {
129
132
  done(new Error(`The following expected ${kind}s were not matched:\n${unused
130
- .map(u => ` ${u}`)
133
+ .map((u) => ` ${u}`)
131
134
  .join('\n')}`));
132
135
  return true;
133
136
  }
@@ -135,7 +138,7 @@ module.exports = async function checkArrayExpectation(testDirectory, object, kin
135
138
  else if (array.length > 0) {
136
139
  done(new Error(`${upperCaseKind}s while compiling:\n\n${array
137
140
  .map(explain)
138
- .join("\n\n")}`));
141
+ .join('\n\n')}`));
139
142
  return true;
140
143
  }
141
144
  };
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
- const fs = require("node:fs");
4
- const path = require("node:path");
5
- const { rimrafSync } = require("rimraf");
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const { rimrafSync } = require('rimraf');
6
6
  module.exports = function copyDiff(src, dest, initial) {
7
7
  fs.mkdirSync(dest, { recursive: true });
8
8
  const files = fs.readdirSync(src);
@@ -15,10 +15,10 @@ module.exports = function copyDiff(src, dest, initial) {
15
15
  }
16
16
  else {
17
17
  const content = fs.readFileSync(srcFile);
18
- if (/^DELETE\s*$/.test(content.toString("utf-8"))) {
18
+ if (/^DELETE\s*$/.test(content.toString('utf-8'))) {
19
19
  fs.unlinkSync(destFile);
20
20
  }
21
- else if (/^DELETE_DIRECTORY\s*$/.test(content.toString("utf-8"))) {
21
+ else if (/^DELETE_DIRECTORY\s*$/.test(content.toString('utf-8'))) {
22
22
  rimrafSync(destFile);
23
23
  }
24
24
  else {
@@ -1,13 +1,13 @@
1
1
  // @ts-nocheck
2
- "use strict";
3
- const path = require("path");
2
+ 'use strict';
3
+ const path = require('path');
4
4
  module.exports = (env, { outputDirectory }) => class Worker {
5
5
  constructor(resource, options = {}) {
6
6
  const isFileURL = /^file:/i.test(resource);
7
7
  const isBlobURL = /^blob:/i.test(resource);
8
8
  if (!isFileURL && !isBlobURL) {
9
- env.expect(resource.origin).toBe("https://test.cases");
10
- env.expect(resource.pathname.startsWith("/path/")).toBe(true);
9
+ env.expect(resource.origin).toBe('https://test.cases');
10
+ env.expect(resource.pathname.startsWith('/path/')).toBe(true);
11
11
  }
12
12
  this.url = resource;
13
13
  const file = isFileURL
@@ -23,7 +23,7 @@ const fs = require("fs");
23
23
  global.self = global;
24
24
  self.URL = URL;
25
25
  self.location = new URL(${JSON.stringify(isBlobURL
26
- ? resource.toString().replace("nodedata:", "https://test.cases/path/")
26
+ ? resource.toString().replace('nodedata:', 'https://test.cases/path/')
27
27
  : resource.toString())});
28
28
  const urlToPath = url => {
29
29
  if (/^file:/i.test(url)) return fileURLToPath(url);
@@ -31,9 +31,9 @@ const urlToPath = url => {
31
31
  return path.resolve(${JSON.stringify(outputDirectory)}, \`./\${url}\`);
32
32
  };
33
33
  self.importScripts = url => {
34
- ${options.type === "module"
34
+ ${options.type === 'module'
35
35
  ? 'throw new Error("importScripts is not supported in module workers")'
36
- : "require(urlToPath(url))"};
36
+ : 'require(urlToPath(url))'};
37
37
  };
38
38
  self.fetch = async url => {
39
39
  if (typeof url === "string" ? url.endsWith(".wasm") : url.toString().endsWith(".wasm")) {
@@ -81,7 +81,7 @@ self.fetch = async url => {
81
81
  self.postMessage = data => {
82
82
  parentPort.postMessage(data);
83
83
  };
84
- if (${options.type === "module"}) {
84
+ if (${options.type === 'module'}) {
85
85
  import(${JSON.stringify(file)}).then(() => {
86
86
  parentPort.on("message", data => {
87
87
  if(self.onmessage) self.onmessage({
@@ -98,18 +98,18 @@ if (${options.type === "module"}) {
98
98
  require(${JSON.stringify(file)});
99
99
  }
100
100
  `;
101
- this.worker = new (require("worker_threads").Worker)(workerBootstrap, {
102
- eval: true
101
+ this.worker = new (require('worker_threads').Worker)(workerBootstrap, {
102
+ eval: true,
103
103
  });
104
104
  this._onmessage = undefined;
105
105
  }
106
106
  // eslint-disable-next-line accessor-pairs
107
107
  set onmessage(value) {
108
108
  if (this._onmessage)
109
- this.worker.off("message", this._onmessage);
110
- this.worker.on("message", (this._onmessage = (data) => {
109
+ this.worker.off('message', this._onmessage);
110
+ this.worker.on('message', (this._onmessage = (data) => {
111
111
  value({
112
- data
112
+ data,
113
113
  });
114
114
  }));
115
115
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
- module.exports = (globalTimeout = 2000, nameSuffix = "") => {
3
+ module.exports = (globalTimeout = 2000, nameSuffix = '') => {
4
4
  const state = global.JEST_STATE_SYMBOL;
5
5
  let currentDescribeBlock;
6
6
  let currentlyRunningTest;
@@ -13,7 +13,7 @@ module.exports = (globalTimeout = 2000, nameSuffix = "") => {
13
13
  return null;
14
14
  let rfn;
15
15
  if (fn.length >= 1) {
16
- rfn = done => {
16
+ rfn = (done) => {
17
17
  fn((...args) => {
18
18
  if (isTest)
19
19
  runTests++;
@@ -34,9 +34,9 @@ module.exports = (globalTimeout = 2000, nameSuffix = "") => {
34
34
  });
35
35
  return rfn;
36
36
  };
37
- describe(nameSuffix ? `exported tests ${nameSuffix}` : "exported tests", () => {
37
+ describe(nameSuffix ? `exported tests ${nameSuffix}` : 'exported tests', () => {
38
38
  // this must have a child to be handled correctly
39
- it("should run the exported tests", () => {
39
+ it('should run the exported tests', () => {
40
40
  runTests++;
41
41
  });
42
42
  afterAll(() => {
@@ -48,8 +48,8 @@ module.exports = (globalTimeout = 2000, nameSuffix = "") => {
48
48
  currentlyRunningTest = state.currentlyRunningTest;
49
49
  });
50
50
  let numberOfTests = 0;
51
- const inSuite = fn => {
52
- const { currentDescribeBlock: oldCurrentDescribeBlock, currentlyRunningTest: oldCurrentlyRunningTest, hasStarted: oldHasStarted } = state;
51
+ const inSuite = (fn) => {
52
+ const { currentDescribeBlock: oldCurrentDescribeBlock, currentlyRunningTest: oldCurrentlyRunningTest, hasStarted: oldHasStarted, } = state;
53
53
  state.currentDescribeBlock = currentDescribeBlock;
54
54
  state.currentlyRunningTest = currentlyRunningTest;
55
55
  state.hasStarted = false;
@@ -65,12 +65,12 @@ module.exports = (globalTimeout = 2000, nameSuffix = "") => {
65
65
  state.currentlyRunningTest = oldCurrentlyRunningTest;
66
66
  state.hasStarted = oldHasStarted;
67
67
  };
68
- const fixAsyncError = block => {
68
+ const fixAsyncError = (block) => {
69
69
  // By default jest leaks memory as it stores asyncError
70
70
  // for each "it" call to track the origin test suite
71
71
  // We want to evaluate this early here to avoid leaking memory
72
72
  block.asyncError = {
73
- stack: block.asyncError.stack
73
+ stack: block.asyncError.stack,
74
74
  };
75
75
  };
76
76
  return {
@@ -83,7 +83,7 @@ module.exports = (globalTimeout = 2000, nameSuffix = "") => {
83
83
  it(...args) {
84
84
  numberOfTests++;
85
85
  if (runTests >= numberOfTests)
86
- throw new Error("it called too late");
86
+ throw new Error('it called too late');
87
87
  args[1] = createDisposableFn(args[1], true);
88
88
  args[2] = args[2] || globalTimeout;
89
89
  inSuite(() => {
@@ -93,7 +93,7 @@ module.exports = (globalTimeout = 2000, nameSuffix = "") => {
93
93
  },
94
94
  beforeEach(...args) {
95
95
  if (runTests >= numberOfTests)
96
- throw new Error("beforeEach called too late");
96
+ throw new Error('beforeEach called too late');
97
97
  args[0] = createDisposableFn(args[0]);
98
98
  inSuite(() => {
99
99
  beforeEach(...args);
@@ -102,7 +102,7 @@ module.exports = (globalTimeout = 2000, nameSuffix = "") => {
102
102
  },
103
103
  afterEach(...args) {
104
104
  if (runTests >= numberOfTests)
105
- throw new Error("afterEach called too late");
105
+ throw new Error('afterEach called too late');
106
106
  args[0] = createDisposableFn(args[0]);
107
107
  inSuite(() => {
108
108
  afterEach(...args);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  class CurrentScript {
3
- constructor(path = "", type = "text/javascript") {
3
+ constructor(path = '', type = 'text/javascript') {
4
4
  this.src = `https://test.cases/path/${path}index.js`;
5
5
  this.type = type;
6
6
  }
@@ -3,27 +3,21 @@
3
3
  MIT License http://www.opensource.org/licenses/mit-license.php
4
4
  Author Tobias Koppers @sokra
5
5
  */
6
- "use strict";
7
- const util = require("util");
6
+ 'use strict';
8
7
  let interception = undefined;
9
- const originalDeprecate = util.deprecate;
10
- util.deprecate = (fn, message, code) => {
11
- const original = originalDeprecate(fn, message, code);
12
- return function (...args) {
13
- if (interception) {
14
- interception.set(`${code}: ${message}`, {
15
- code,
16
- message,
17
- stack: new Error(message).stack
18
- });
19
- return fn.apply(this, args);
20
- }
21
- else {
22
- return original.apply(this, args);
23
- }
24
- };
8
+ const originalWarn = console.warn;
9
+ console.warn = (message, ...args) => {
10
+ if (interception &&
11
+ typeof message === 'string' &&
12
+ message.includes('[Rspack Deprecation]')) {
13
+ interception.set(message, {
14
+ message,
15
+ stack: new Error(message).stack,
16
+ });
17
+ }
18
+ return originalWarn.apply(console, [message, ...args]);
25
19
  };
26
- exports.start = handler => {
20
+ exports.start = (handler) => {
27
21
  interception = new Map();
28
22
  return () => {
29
23
  const map = interception;
@@ -1,23 +1,23 @@
1
1
  // @ts-nocheck
2
- "use strict";
3
- const regexEscape = require("./regexEscape");
2
+ 'use strict';
3
+ const regexEscape = require('./regexEscape');
4
4
  // These expect* methods are necessary because 'source' contains the code for this test file, which will always contain the string
5
5
  // being tested for, so we have to use the "DO NOT MATCH BELOW..." technique to exclude the actual testing code from the test.
6
6
  // Place your jest 'expect' calls below a line containing the DO NOT MATCH BELOW... string constructed below. See other tests for examples.
7
7
  // Break up the match string so we don't match it in these expect* functions either.
8
- const doNotMatch = ["DO", "NOT", "MATCH", "BELOW", "THIS", "LINE"].join(" ");
8
+ const doNotMatch = ['DO', 'NOT', 'MATCH', 'BELOW', 'THIS', 'LINE'].join(' ');
9
9
  /**
10
10
  * @param {string} source value
11
11
  * @param {string} str string for searching
12
12
  */
13
13
  function expectSourceToContain(source, str) {
14
- expect(source).toMatch(new RegExp(`${regexEscape(str)}.*${doNotMatch}`, "s"));
14
+ expect(source).toMatch(new RegExp(`${regexEscape(str)}.*${doNotMatch}`, 's'));
15
15
  }
16
16
  /**
17
17
  * @param {string} source value
18
18
  * @param {RegExp} regexStr regexp
19
19
  */
20
20
  function expectSourceToMatch(source, regexStr) {
21
- expect(source).toMatch(new RegExp(`${regexStr}.*${doNotMatch}`, "s"));
21
+ expect(source).toMatch(new RegExp(`${regexStr}.*${doNotMatch}`, 's'));
22
22
  }
23
23
  module.exports = { expectSourceToContain, expectSourceToMatch };