@rstest/core 0.6.4 → 0.6.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.
package/dist/0~971.js CHANGED
@@ -7,23 +7,7 @@ const external_node_fs_ = __webpack_require__("node:fs");
7
7
  const external_node_path_ = __webpack_require__("node:path");
8
8
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
9
9
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
10
- async function listTests(context, { filesOnly, json }) {
11
- const { rootPath } = context;
12
- const testEntries = {};
13
- const globTestSourceEntries = async (name)=>{
14
- if (testEntries[name]) return testEntries[name];
15
- const { include, exclude, includeSource, root } = context.projects.find((p)=>p.environmentName === name).normalizedConfig;
16
- const entries = await getTestEntries({
17
- include,
18
- exclude: exclude.patterns,
19
- rootPath,
20
- projectRoot: root,
21
- fileFilters: context.fileFilters || [],
22
- includeSource
23
- });
24
- testEntries[name] = entries;
25
- return entries;
26
- };
10
+ const collectTests = async ({ context, globTestSourceEntries })=>{
27
11
  const setupFiles = Object.fromEntries(context.projects.map((project)=>{
28
12
  const { environmentName, rootPath, normalizedConfig: { setupFiles } } = project;
29
13
  return [
@@ -40,7 +24,7 @@ async function listTests(context, { filesOnly, json }) {
40
24
  },
41
25
  setupFiles,
42
26
  rsbuildInstance,
43
- rootPath
27
+ rootPath: context.rootPath
44
28
  });
45
29
  const pool = await createPool({
46
30
  context
@@ -64,7 +48,60 @@ async function listTests(context, { filesOnly, json }) {
64
48
  assetNames
65
49
  };
66
50
  }));
67
- const list = returns.flatMap((r)=>r.list);
51
+ return {
52
+ list: returns.flatMap((r)=>r.list),
53
+ getSourceMap: async (name)=>{
54
+ const resource = returns.find((r)=>r.assetNames.includes(name));
55
+ return (await resource?.getSourceMaps([
56
+ name
57
+ ]))?.[name];
58
+ },
59
+ close: async ()=>{
60
+ await closeServer();
61
+ await pool.close();
62
+ }
63
+ };
64
+ };
65
+ const collectTestFiles = async ({ context, globTestSourceEntries })=>{
66
+ const list = [];
67
+ for (const project of context.projects){
68
+ const files = await globTestSourceEntries(project.environmentName);
69
+ list.push(...Object.values(files).map((testPath)=>({
70
+ testPath,
71
+ project: project.name,
72
+ tests: []
73
+ })));
74
+ }
75
+ return {
76
+ close: async ()=>{},
77
+ list,
78
+ getSourceMap: async (_name)=>null
79
+ };
80
+ };
81
+ async function listTests(context, { filesOnly, json }) {
82
+ const { rootPath } = context;
83
+ const testEntries = {};
84
+ const globTestSourceEntries = async (name)=>{
85
+ if (testEntries[name]) return testEntries[name];
86
+ const { include, exclude, includeSource, root } = context.projects.find((p)=>p.environmentName === name).normalizedConfig;
87
+ const entries = await getTestEntries({
88
+ include,
89
+ exclude: exclude.patterns,
90
+ rootPath,
91
+ projectRoot: root,
92
+ fileFilters: context.fileFilters || [],
93
+ includeSource
94
+ });
95
+ testEntries[name] = entries;
96
+ return entries;
97
+ };
98
+ const { list, close, getSourceMap } = filesOnly ? await collectTestFiles({
99
+ context,
100
+ globTestSourceEntries
101
+ }) : await collectTests({
102
+ context,
103
+ globTestSourceEntries
104
+ });
68
105
  const tests = [];
69
106
  const traverseTests = (test)=>{
70
107
  if ([
@@ -94,16 +131,12 @@ async function listTests(context, { filesOnly, json }) {
94
131
  if (file.errors?.length) {
95
132
  src_logger.log(`${picocolors_default().bgRed(' FAIL ')} ${relativePath}`);
96
133
  for (const error of file.errors)await printError(error, async (name)=>{
97
- const resource = returns.find((r)=>r.assetNames.includes(name));
98
- const sourceMap = (await resource?.getSourceMaps([
99
- name
100
- ]))?.[name];
134
+ const sourceMap = await getSourceMap(name);
101
135
  return sourceMap ? JSON.parse(sourceMap) : null;
102
136
  }, rootPath);
103
137
  }
104
138
  }
105
- await closeServer();
106
- await pool.close();
139
+ await close();
107
140
  return;
108
141
  }
109
142
  for (const file of list){
@@ -132,7 +165,6 @@ async function listTests(context, { filesOnly, json }) {
132
165
  const shortPath = (0, external_node_path_.relative)(rootPath, test.file);
133
166
  src_logger.log(test.name ? `${picocolors_default().dim(`${shortPath} > `)}${test.name}` : prettyTestPath(shortPath));
134
167
  }
135
- await closeServer();
136
- await pool.close();
168
+ await close();
137
169
  }
138
170
  export { listTests };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import 'module';
3
3
  import { __webpack_require__ } from "./rslib-runtime.js";
4
4
  import { EventEmitter } from "events";
5
5
  import { createRsbuild, loadConfig, logger, mergeRsbuildConfig } from "@rsbuild/core";
6
- import { basename, DEFAULT_CONFIG_EXTENSIONS, TS_CONFIG_FILE, DEFAULT_CONFIG_NAME, dirname, posix, resolve as pathe_M_eThtNZ_resolve, pathe_M_eThtNZ_relative, globalApis, formatTestPath, getAbsolutePath, filterProjects, formatRootStr, join, isDynamicPattern, glob, writeFile, castArray, src_logger, prettyTestPath, prettyTime, isDebug, isAbsolute, getTaskNameWithPrefix, formatError, normalize, TEMP_RSTEST_OUTPUT_DIR_GLOB } from "./857.js";
6
+ import { basename, DEFAULT_CONFIG_EXTENSIONS, TS_CONFIG_FILE, isTTY, dirname, posix, resolve as pathe_M_eThtNZ_resolve, pathe_M_eThtNZ_relative, DEFAULT_CONFIG_NAME, globalApis, formatTestPath, getAbsolutePath, filterProjects, join, formatRootStr, isDynamicPattern, glob, writeFile, castArray, src_logger, prettyTestPath, prettyTime, isDebug, isAbsolute, getTaskNameWithPrefix, formatError, normalize, TEMP_RSTEST_OUTPUT_DIR_GLOB } from "./857.js";
7
7
  import { decode } from "./597.js";
8
8
  function toArr(any) {
9
9
  return null == any ? [] : Array.isArray(any) ? any : [
@@ -500,7 +500,7 @@ function prepareCli() {
500
500
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
501
501
  }
502
502
  function showRstest() {
503
- src_logger.greet(" Rstest v0.6.4");
503
+ src_logger.greet(" Rstest v0.6.5");
504
504
  src_logger.log('');
505
505
  }
506
506
  const applyCommonOptions = (cli)=>{
@@ -544,7 +544,7 @@ const runRest = async ({ options, filters, command })=>{
544
544
  function setupCommands() {
545
545
  const cli = dist('rstest');
546
546
  cli.help();
547
- cli.version("0.6.4");
547
+ cli.version("0.6.5");
548
548
  applyCommonOptions(cli);
549
549
  cli.command('[...filters]', 'run tests').option('-w, --watch', 'Run tests in watch mode').action(async (filters, options)=>{
550
550
  showRstest();
@@ -708,9 +708,9 @@ const createDefaultConfig = ()=>({
708
708
  '**/__mocks__/**',
709
709
  '**/*.d.ts',
710
710
  '**/*.{test,spec}.[jt]s',
711
- '**/*.{test,spec}.[c|m][jt]s',
711
+ '**/*.{test,spec}.[cm][jt]s',
712
712
  '**/*.{test,spec}.[jt]sx',
713
- '**/*.{test,spec}.[c|m][jt]sx'
713
+ '**/*.{test,spec}.[cm][jt]sx'
714
714
  ],
715
715
  enabled: false,
716
716
  provider: 'istanbul',
@@ -1652,7 +1652,7 @@ class DefaultReporter {
1652
1652
  this.rootPath = rootPath;
1653
1653
  this.config = config;
1654
1654
  this.options = options;
1655
- if (!T) this.statusRenderer = new StatusRenderer(rootPath);
1655
+ if (isTTY()) this.statusRenderer = new StatusRenderer(rootPath);
1656
1656
  }
1657
1657
  onTestFileStart(test) {
1658
1658
  this.statusRenderer?.onTestFileStart(test.testPath);
@@ -2374,7 +2374,7 @@ class Rstest {
2374
2374
  });
2375
2375
  this.reporters = reporters;
2376
2376
  this.snapshotManager = snapshotManager;
2377
- this.version = "0.6.4";
2377
+ this.version = "0.6.5";
2378
2378
  this.rootPath = rootPath;
2379
2379
  this.originalConfig = userConfig;
2380
2380
  this.normalizedConfig = rstestConfig;
@@ -2385,7 +2385,8 @@ class Rstest {
2385
2385
  config.coverage = rstestConfig.coverage;
2386
2386
  config.bail = rstestConfig.bail;
2387
2387
  config.source ??= {};
2388
- if (!config.source.tsconfigPath) {
2388
+ if (config.source.tsconfigPath) config.source.tsconfigPath = getAbsolutePath(config.root, config.source.tsconfigPath);
2389
+ else {
2389
2390
  const tsconfigPath = join(config.root, TS_CONFIG_FILE);
2390
2391
  if ((0, external_node_fs_.existsSync)(tsconfigPath)) config.source.tsconfigPath = tsconfigPath;
2391
2392
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"