@rstest/core 0.9.3 → 0.9.5

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 (42) hide show
  1. package/LICENSE.md +0 -228
  2. package/dist/0~8843.js +33 -17
  3. package/dist/0~browserLoader.js +1 -1
  4. package/dist/0~browser~1.js +4 -4
  5. package/dist/0~checkThresholds.js +1 -1
  6. package/dist/0~console.js +1 -1
  7. package/dist/0~fake-timers.js +1483 -0
  8. package/dist/0~generate.js +4 -3
  9. package/dist/0~happyDom.js +1 -1
  10. package/dist/0~jsdom.js +1 -1
  11. package/dist/0~listTests.js +14 -10
  12. package/dist/0~loadEsModule.js +3 -1
  13. package/dist/0~loadModule.js +1 -1
  14. package/dist/0~runTests.js +17 -6
  15. package/dist/0~snapshot.js +2140 -0
  16. package/dist/0~snapshot.js.LICENSE.txt +7 -0
  17. package/dist/0~utils.js +1 -1
  18. package/dist/1949.js +2919 -9808
  19. package/dist/1949.js.LICENSE.txt +1 -49
  20. package/dist/3145.js +363 -63
  21. package/dist/4411.js +232 -47
  22. package/dist/6830.js +61 -9
  23. package/dist/7552.js +22 -4918
  24. package/dist/7704.js +1 -2
  25. package/dist/9743.js +1982 -0
  26. package/dist/9784.js +1343 -0
  27. package/dist/{7552.js.LICENSE.txt → 9784.js.LICENSE.txt} +19 -8
  28. package/dist/browser-runtime/2~fake-timers.js +1653 -0
  29. package/dist/browser-runtime/2~snapshot.js +2138 -0
  30. package/dist/browser-runtime/2~snapshot.js.LICENSE.txt +7 -0
  31. package/dist/browser-runtime/723.js +2055 -10605
  32. package/dist/browser-runtime/723.js.LICENSE.txt +0 -17
  33. package/dist/browser-runtime/index.d.ts +189 -11
  34. package/dist/browser-runtime/rslib-runtime.js +0 -7
  35. package/dist/browser.d.ts +39 -5
  36. package/dist/browser.js +2 -2
  37. package/dist/globalSetupWorker.js +1 -1
  38. package/dist/index.d.ts +39 -5
  39. package/dist/mockRuntimeCode.js +2 -0
  40. package/dist/worker.d.ts +31 -5
  41. package/dist/worker.js +32 -11
  42. package/package.json +21 -22
@@ -27,7 +27,7 @@ async function generateCoverage(context, results, coverageProvider) {
27
27
  return normalizedFile.startsWith(normalize(rootPath));
28
28
  });
29
29
  if (coverage.include?.length) {
30
- const coveredFiles = finalCoverageMap.files().map(normalize);
30
+ const coveredFilesSet = new Set(finalCoverageMap.files().map(normalize));
31
31
  let isTimeout = false;
32
32
  const timeoutId = setTimeout(()=>{
33
33
  isTimeout = true;
@@ -35,13 +35,14 @@ async function generateCoverage(context, results, coverageProvider) {
35
35
  }, 1000);
36
36
  const allFiles = (await Promise.all(projects.map(async (p)=>{
37
37
  const includedFiles = await getIncludedFiles(coverage, p.rootPath);
38
- const uncoveredFiles = includedFiles.filter((file)=>!coveredFiles.includes(normalize(file)));
38
+ const uncoveredFiles = includedFiles.filter((file)=>!coveredFilesSet.has(normalize(file)));
39
39
  if (uncoveredFiles.length) await generateCoverageForUntestedFiles(p.environmentName, uncoveredFiles, finalCoverageMap, coverageProvider);
40
40
  return includedFiles;
41
41
  }))).flat();
42
42
  clearTimeout(timeoutId);
43
43
  if (isTimeout) logger_logger.info('Coverage for untested files generated.');
44
- finalCoverageMap.filter((file)=>allFiles.includes(normalize(file)));
44
+ const allFilesSet = new Set(allFiles.map(normalize));
45
+ finalCoverageMap.filter((file)=>allFilesSet.has(normalize(file)));
45
46
  }
46
47
  await coverageProvider.generateReports(finalCoverageMap, coverage);
47
48
  if (coverage.thresholds) {
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
- import { checkPkgInstalled } from "./7552.js";
3
2
  import { installGlobal, addDefaultErrorHandler } from "./0~utils.js";
3
+ import { checkPkgInstalled } from "./7552.js";
4
4
  const environment = {
5
5
  name: 'happy-dom',
6
6
  setup: async (global, options = {})=>{
package/dist/0~jsdom.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
- import { checkPkgInstalled } from "./7552.js";
3
2
  import { installGlobal, addDefaultErrorHandler } from "./0~utils.js";
3
+ import { checkPkgInstalled } from "./7552.js";
4
4
  const environment = {
5
5
  name: 'jsdom',
6
6
  setup: async (global, options)=>{
@@ -2,8 +2,8 @@ import "node:module";
2
2
  import { mkdirSync, writeFileSync } from "node:fs";
3
3
  import { dirname, isAbsolute, join, relative } from "node:path";
4
4
  import { prepareRsbuild, createPool, createRsbuildServer, runGlobalTeardown, runGlobalSetup } from "./0~8843.js";
5
- import { getTestEntries, resolveShardedEntries, prettyTestPath, ROOT_SUITE_NAME } from "./4411.js";
6
- import { logger as logger_logger, getTaskNameWithPrefix, color as logger_color, bgColor } from "./6830.js";
5
+ import { resolveShardedEntries, getTestEntries, prettyTestPath } from "./4411.js";
6
+ import { getTaskNameWithPrefix, logger as logger_logger, color as logger_color, ROOT_SUITE_NAME, bgColor } from "./6830.js";
7
7
  const collectNodeTests = async ({ context, nodeProjects, globTestSourceEntries })=>{
8
8
  const { getSetupFiles } = await import("./255.js");
9
9
  if (0 === nodeProjects.length) return {
@@ -25,7 +25,7 @@ const collectNodeTests = async ({ context, nodeProjects, globTestSourceEntries }
25
25
  getSetupFiles(globalSetup, rootPath)
26
26
  ];
27
27
  }));
28
- const rsbuildInstance = await prepareRsbuild(context, globTestSourceEntries, setupFiles, globalSetupFiles);
28
+ const rsbuildInstance = await prepareRsbuild(context, globTestSourceEntries, setupFiles, globalSetupFiles, nodeProjects);
29
29
  const { getRsbuildStats, closeServer } = await createRsbuildServer({
30
30
  globTestSourceEntries,
31
31
  globalSetupFiles,
@@ -49,8 +49,12 @@ const collectNodeTests = async ({ context, nodeProjects, globTestSourceEntries }
49
49
  if (entries.length && globalSetupEntries.length && !project._globalSetups) {
50
50
  project._globalSetups = true;
51
51
  const files = globalSetupEntries.flatMap((e)=>e.files);
52
- const assetFiles = await getAssetFiles(files);
53
- const sourceMaps = await getSourceMaps(files);
52
+ const assetFilesPromise = getAssetFiles(files);
53
+ const sourceMapsPromise = getSourceMaps(files);
54
+ const [assetFiles, sourceMaps] = await Promise.all([
55
+ assetFilesPromise,
56
+ sourceMapsPromise
57
+ ]);
54
58
  const { success, errors } = await runGlobalSetup({
55
59
  globalSetupEntries,
56
60
  assetFiles,
@@ -111,15 +115,15 @@ const collectBrowserTests = async ({ context, browserProjects, shardedEntries })
111
115
  });
112
116
  };
113
117
  const collectTestFiles = async ({ context, globTestSourceEntries })=>{
114
- const list = [];
115
- for (const project of context.projects){
118
+ const projectLists = await Promise.all(context.projects.map(async (project)=>{
116
119
  const files = await globTestSourceEntries(project.environmentName);
117
- list.push(...Object.values(files).map((testPath)=>({
120
+ return Object.values(files).map((testPath)=>({
118
121
  testPath,
119
122
  project: project.name,
120
123
  tests: []
121
- })));
122
- }
124
+ }));
125
+ }));
126
+ const list = projectLists.flat();
123
127
  return {
124
128
  close: async ()=>void 0,
125
129
  errors: [],
@@ -1,4 +1,5 @@
1
1
  import "node:module";
2
+ import { builtinModules } from "node:module";
2
3
  import { isAbsolute } from "node:path";
3
4
  import { fileURLToPath, pathToFileURL } from "node:url";
4
5
  import node_vm from "node:vm";
@@ -12,6 +13,7 @@ var loadEsModule_EsmMode = /*#__PURE__*/ function(EsmMode) {
12
13
  return EsmMode;
13
14
  }({});
14
15
  const isRelativePath = (p)=>/^\.\.?\//.test(p);
16
+ const isBuiltinSpecifier = (specifier)=>specifier.startsWith('node:') || builtinModules.includes(specifier);
15
17
  const defineRstestDynamicImport = ({ distPath, testPath, assetFiles, interopDefault, returnModule, esmMode })=>async (specifier, importAttributes)=>{
16
18
  const currentDirectory = posix.dirname(distPath);
17
19
  const joinedPath = isRelativePath(specifier) ? posix.join(currentDirectory, specifier) : specifier;
@@ -37,7 +39,7 @@ const defineRstestDynamicImport = ({ distPath, testPath, assetFiles, interopDefa
37
39
  } catch (err) {
38
40
  logger_logger.error(`load file ${joinedPath} failed:\n`, err instanceof Error ? err.message : err);
39
41
  }
40
- const resolvedPath = isAbsolute(specifier) ? pathToFileURL(specifier) : import.meta.resolve(specifier, pathToFileURL(testPath));
42
+ const resolvedPath = isAbsolute(specifier) ? pathToFileURL(specifier) : isBuiltinSpecifier(specifier) ? specifier : import.meta.resolve(specifier, pathToFileURL(testPath));
41
43
  const modulePath = 'string' == typeof resolvedPath ? resolvedPath : resolvedPath.pathname;
42
44
  if (importAttributes?.with?.rstest) delete importAttributes.with.rstest;
43
45
  if (modulePath.endsWith('.json')) {
@@ -11,7 +11,7 @@ const loadModule_createRequire = (filename, distPath, rstestContext, assetFiles,
11
11
  const _require = (()=>{
12
12
  try {
13
13
  return createRequire(filename);
14
- } catch (_err) {
14
+ } catch {
15
15
  return createRequire(distPath);
16
16
  }
17
17
  })();
@@ -212,9 +212,16 @@ async function runTests(context) {
212
212
  };
213
213
  let browserProjectsToRun = browserProjects;
214
214
  let nodeProjectsToRun = nodeProjects;
215
- if (shard) {
216
- browserProjectsToRun = browserProjects.filter((p)=>Object.keys(entriesCache.get(p.environmentName)?.entries || {}).length > 0);
217
- nodeProjectsToRun = nodeProjects.filter((p)=>Object.keys(entriesCache.get(p.environmentName)?.entries || {}).length > 0);
215
+ if (isWatchMode) {
216
+ if (shard) {
217
+ browserProjectsToRun = browserProjects.filter((p)=>Object.keys(entriesCache.get(p.environmentName)?.entries || {}).length > 0);
218
+ nodeProjectsToRun = nodeProjects.filter((p)=>Object.keys(entriesCache.get(p.environmentName)?.entries || {}).length > 0);
219
+ }
220
+ } else {
221
+ await Promise.all(allProjects.map((p)=>globTestSourceEntries(p.environmentName)));
222
+ const hasEntries = (env)=>Object.keys(entriesCache.get(env)?.entries || {}).length > 0;
223
+ browserProjectsToRun = browserProjects.filter((p)=>hasEntries(p.environmentName));
224
+ nodeProjectsToRun = nodeProjects.filter((p)=>hasEntries(p.environmentName));
218
225
  }
219
226
  const hasBrowserTestsToRun = browserProjectsToRun.length > 0;
220
227
  const hasNodeTestsToRun = nodeProjectsToRun.length > 0;
@@ -248,7 +255,7 @@ async function runTests(context) {
248
255
  getSetupFiles(globalSetup, rootPath)
249
256
  ];
250
257
  }));
251
- const rsbuildInstance = await prepareRsbuild(context, globTestSourceEntries, setupFiles, globalSetupFiles);
258
+ const rsbuildInstance = await prepareRsbuild(context, globTestSourceEntries, setupFiles, globalSetupFiles, projects);
252
259
  const { getRsbuildStats, closeServer } = await createRsbuildServer({
253
260
  inspectedConfig: {
254
261
  ...context.normalizedConfig,
@@ -292,8 +299,12 @@ async function runTests(context) {
292
299
  if (entries.length && globalSetupEntries.length && !p._globalSetups) {
293
300
  p._globalSetups = true;
294
301
  const files = globalSetupEntries.flatMap((e)=>e.files);
295
- const assetFiles = await getAssetFiles(files);
296
- const sourceMaps = await getSourceMaps(files);
302
+ const assetFilesPromise = getAssetFiles(files);
303
+ const sourceMapsPromise = getSourceMaps(files);
304
+ const [assetFiles, sourceMaps] = await Promise.all([
305
+ assetFilesPromise,
306
+ sourceMapsPromise
307
+ ]);
297
308
  const { success, errors } = await runGlobalSetup({
298
309
  globalSetupEntries,
299
310
  assetFiles,