@rstest/core 0.8.5 → 0.9.1

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~7882.js CHANGED
@@ -2,7 +2,7 @@ import "node:module";
2
2
  import { __webpack_require__ } from "./rslib-runtime.js";
3
3
  import { determineAgent, color } from "./3160.js";
4
4
  import { detect, resolveCommand } from "./9131.js";
5
- import { Ie, Me, ye, M, dist_Y, Se, ve, pD, xe } from "./0~9348.js";
5
+ import { Rt, dist_Wt, dist_Vt, R, Jt, be, Nt, Ct, Gt } from "./0~9744.js";
6
6
  import "./1157.js";
7
7
  const external_node_fs_ = __webpack_require__("node:fs");
8
8
  const external_node_path_ = __webpack_require__("path");
@@ -164,18 +164,19 @@ export default function Counter({ initial = 0 }) {
164
164
  function getReactTestTemplate(lang) {
165
165
  const componentExt = 'ts' === lang ? 'tsx' : 'jsx';
166
166
  return `import { expect, test } from '@rstest/core';
167
- import { render } from '@rstest/browser-react';
168
- import Counter from './Counter.${componentExt}';
169
-
170
- test('increments count on button click', async () => {
171
- const screen = await render(<Counter initial={5} />);
167
+ import { page } from '@rstest/browser';
168
+ import { render } from '@rstest/browser-react';
169
+ import Counter from './Counter.${componentExt}';
170
+
171
+ test('increments count on button click', async () => {
172
+ await render(<Counter initial={5} />);
172
173
 
173
- await expect.element(screen.getByText('Count: 5')).toBeInTheDocument();
174
+ await expect.element(page.getByText('Count: 5')).toBeVisible();
174
175
 
175
- await screen.getByRole('button', { name: 'Increment' }).click();
176
- await expect.element(screen.getByText('Count: 6')).toBeInTheDocument();
177
- });
178
- `;
176
+ await page.getByRole('button', { name: 'Increment' }).click();
177
+ await expect.element(page.getByText('Count: 6')).toBeVisible();
178
+ });
179
+ `;
179
180
  }
180
181
  function getVanillaComponentTemplate(lang) {
181
182
  if ('ts' === lang) return `export function createCounter(initial = 0): HTMLElement {
@@ -237,15 +238,15 @@ function getVanillaTestTemplate(lang) {
237
238
  import { page } from '@rstest/browser';
238
239
  import { createCounter } from './Counter.${ext}';
239
240
 
240
- test('increments count on button click', async () => {
241
- document.body.appendChild(createCounter(5));
242
-
243
- await expect.element(page.getByText('Count: 5')).toBeInTheDocument();
244
-
245
- await page.getByRole('button', { name: 'Increment' }).click();
246
- await expect.element(page.getByText('Count: 6')).toBeInTheDocument();
247
- });
248
- `;
241
+ test('increments count on button click', async () => {
242
+ document.body.appendChild(createCounter(5));
243
+
244
+ await expect.element(page.getByText('Count: 5')).toBeVisible();
245
+
246
+ await page.getByRole('button', { name: 'Increment' }).click();
247
+ await expect.element(page.getByText('Count: 6')).toBeVisible();
248
+ });
249
+ `;
249
250
  }
250
251
  function getDependenciesWithVersions(framework, provider, rstestVersion) {
251
252
  const deps = {
@@ -347,16 +348,16 @@ async function createNonInteractive(cwd, projectInfo) {
347
348
  async function createInteractive(cwd, projectInfo, isAgent) {
348
349
  const { agent, language, testDir, framework, reactVersion } = projectInfo;
349
350
  const effectiveFramework = 'react' === framework ? 'react' : 'vanilla';
350
- Ie(color.bgCyan(color.black(' rstest init browser ')));
351
+ dist_Wt(color.bgCyan(color.black(' rstest init browser ')));
351
352
  const detectionLines = [];
352
353
  if ('react' === framework && reactVersion) detectionLines.push(`${color.green('✓')} Found React ${reactVersion}`);
353
354
  else if ('react' === framework) detectionLines.push(`${color.green('✓')} Found React`);
354
355
  else detectionLines.push(`${color.yellow('⚠')} Framework not detected, will generate vanilla DOM example`);
355
356
  detectionLines.push(`${color.green('✓')} Found ${'ts' === language ? 'TypeScript' : 'JavaScript'}`);
356
357
  detectionLines.push(`${color.green('✓')} Test directory: ${testDir}/`);
357
- Me(detectionLines.join('\n'), 'Detecting project...');
358
- if (isAgent) M.info(`AI Agent detected. For non-interactive mode, run:\n ${color.cyan('npx rstest init browser --yes')}`);
359
- const providerSelection = await ve({
358
+ dist_Vt(detectionLines.join('\n'), 'Detecting project...');
359
+ if (isAgent) R.info(`AI Agent detected. For non-interactive mode, run:\n ${color.cyan('npx rstest init browser --yes')}`);
360
+ const providerSelection = await Jt({
360
361
  message: 'Choose a browser provider (so far, only Playwright)',
361
362
  options: [
362
363
  {
@@ -366,13 +367,13 @@ async function createInteractive(cwd, projectInfo, isAgent) {
366
367
  }
367
368
  ]
368
369
  });
369
- if (pD(providerSelection)) {
370
- xe('Operation cancelled.');
370
+ if (Ct(providerSelection)) {
371
+ Nt('Operation cancelled.');
371
372
  process.exit(0);
372
373
  }
373
374
  const provider = providerSelection;
374
375
  const preview = computeFilePreview(cwd, projectInfo);
375
- const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.8.5");
376
+ const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.9.1");
376
377
  const depsList = Object.entries(deps).map(([name, version])=>`${name}@${version}`).join(', ');
377
378
  const previewLines = [
378
379
  `${color.cyan('+')} Create ${preview.configFile}`,
@@ -382,22 +383,22 @@ async function createInteractive(cwd, projectInfo, isAgent) {
382
383
  ' - Add "test:browser" script',
383
384
  ` - Add devDependencies: ${color.dim(depsList)}`
384
385
  ];
385
- Me(previewLines.join('\n'), 'Changes to be made');
386
- const confirmed = await ye({
386
+ dist_Vt(previewLines.join('\n'), 'Changes to be made');
387
+ const confirmed = await Rt({
387
388
  message: 'Proceed with these changes?',
388
389
  initialValue: true
389
390
  });
390
- if (pD(confirmed) || !confirmed) {
391
- xe('Operation cancelled.');
391
+ if (Ct(confirmed) || !confirmed) {
392
+ Nt('Operation cancelled.');
392
393
  process.exit(0);
393
394
  }
394
- const s = dist_Y();
395
+ const s = be();
395
396
  s.start('Creating files...');
396
397
  const createdFiles = await generateFiles(cwd, projectInfo, provider);
397
398
  s.stop('Created files');
398
399
  const fileLines = createdFiles.map((f)=>`${color.green('✓')} Created ${f}`);
399
400
  fileLines.push(`${color.green('✓')} Updated package.json`);
400
- Me(fileLines.join('\n'), 'Files');
401
+ dist_Vt(fileLines.join('\n'), 'Files');
401
402
  const nextStepsLines = [
402
403
  `${color.bold('1.')} Install dependencies:`,
403
404
  ` ${color.cyan(getInstallCommand(agent))}`,
@@ -408,8 +409,8 @@ async function createInteractive(cwd, projectInfo, isAgent) {
408
409
  `${color.bold('3.')} Run your tests:`,
409
410
  ` ${color.cyan(getRunCommand(agent))}`
410
411
  ];
411
- Me(nextStepsLines.join('\n'), 'Next steps');
412
- Se(color.green('Done! Happy testing with Rstest!'));
412
+ dist_Vt(nextStepsLines.join('\n'), 'Next steps');
413
+ Gt(color.green('Done! Happy testing with Rstest!'));
413
414
  }
414
415
  async function generateFiles(cwd, projectInfo, provider) {
415
416
  const { language, testDir, framework } = projectInfo;
@@ -450,7 +451,7 @@ async function generateFiles(cwd, projectInfo, provider) {
450
451
  updatePackageJsonScripts(cwd, {
451
452
  'test:browser': 'rstest --config=rstest.browser.config.ts'
452
453
  });
453
- const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.8.5");
454
+ const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.9.1");
454
455
  updatePackageJsonDevDeps(cwd, deps);
455
456
  return createdFiles;
456
457
  }
package/dist/0~89.js CHANGED
@@ -3,9 +3,9 @@ import { __webpack_require__ } from "./rslib-runtime.js";
3
3
  import node_events from "node:events";
4
4
  import { Tinypool } from "tinypool";
5
5
  import node_inspector from "node:inspector";
6
- import { basename, needFlagExperimentalDetectModule, isDeno, dirname, castArray, resolve as pathe_M_eThtNZ_resolve, serializableConfig, node_process, isDebug, color, getForceColorEnv, ADDITIONAL_NODE_BUILTINS, bgColor, join } from "./3160.js";
6
+ import { basename, bgColor, isDeno, dirname, castArray, resolve as pathe_M_eThtNZ_resolve, node_process, isDebug, color, getForceColorEnv, ADDITIONAL_NODE_BUILTINS, join, needFlagExperimentalDetectModule } from "./3160.js";
7
7
  import { fileURLToPath } from "./6198.js";
8
- import { node_v8, parseWorkerMetaMessage, createBirpc } from "./5960.js";
8
+ import { parseWorkerMetaMessage, createBirpc } from "./4597.js";
9
9
  import { TEMP_RSTEST_OUTPUT_DIR, TEMP_RSTEST_OUTPUT_DIR_GLOB } from "./1157.js";
10
10
  import { posix } from "./7011.js";
11
11
  import { isBuiltin } from "./4881.js";
@@ -215,8 +215,6 @@ function createForksChannel(rpcMethods, onWorkerMeta, createBirpcImpl = createBi
215
215
  }
216
216
  };
217
217
  const rpc = createBirpcImpl(rpcMethods, {
218
- serialize: node_v8.serialize,
219
- deserialize: (v)=>node_v8.deserialize(Buffer.from(v)),
220
218
  timeout: -1,
221
219
  post (v) {
222
220
  emitter.emit(events.message, v);
@@ -244,7 +242,8 @@ const createForksPool = (poolOptions)=>{
244
242
  maxThreads,
245
243
  minThreads,
246
244
  concurrentTasksPerWorker: 1,
247
- isolateWorkers: isolate
245
+ isolateWorkers: isolate,
246
+ serialization: 'advanced'
248
247
  };
249
248
  const pool = new Tinypool(options);
250
249
  const stderrCapture = createWorkerStderrCapture(pool);
@@ -435,7 +434,7 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
435
434
  project: projectName,
436
435
  rootPath: context.rootPath,
437
436
  projectRoot: project.rootPath,
438
- runtimeConfig: serializableConfig(runtimeConfig)
437
+ runtimeConfig
439
438
  },
440
439
  type: 'run',
441
440
  setupEntries,
@@ -505,7 +504,7 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
505
504
  outputModule: project.outputModule,
506
505
  rootPath: context.rootPath,
507
506
  projectRoot: project.rootPath,
508
- runtimeConfig: serializableConfig(runtimeConfig)
507
+ runtimeConfig
509
508
  },
510
509
  type: 'collect',
511
510
  setupEntries,
@@ -538,7 +537,7 @@ function applyEnvChanges(changes) {
538
537
  }
539
538
  const globalSetup_filename = fileURLToPath(import.meta.url);
540
539
  const globalSetup_dirname = dirname(globalSetup_filename);
541
- async function createSetupPool() {
540
+ function createSetupPool() {
542
541
  const options = {
543
542
  runtime: 'child_process',
544
543
  filename: pathe_M_eThtNZ_resolve(globalSetup_dirname, './globalSetupWorker.js'),
@@ -552,6 +551,7 @@ async function createSetupPool() {
552
551
  minThreads: 1,
553
552
  concurrentTasksPerWorker: 1,
554
553
  isolateWorkers: false,
554
+ serialization: 'advanced',
555
555
  env: {
556
556
  NODE_ENV: 'test',
557
557
  ...getForceColorEnv(),
@@ -562,7 +562,7 @@ async function createSetupPool() {
562
562
  return pool;
563
563
  }
564
564
  async function runGlobalSetup({ globalSetupEntries, assetFiles, sourceMaps, interopDefault, outputModule }) {
565
- const pool = await createSetupPool();
565
+ const pool = createSetupPool();
566
566
  const result = await pool.run({
567
567
  type: 'setup',
568
568
  entries: globalSetupEntries,
@@ -614,12 +614,12 @@ const pluginBasic = (context)=>({
614
614
  chain.optimization.splitChunks({
615
615
  chunks: 'all'
616
616
  });
617
- chain.module.rule(CHAIN_ID.RULE.JS).delete('type');
617
+ chain.module.rule(CHAIN_ID.RULE.JS).oneOf(CHAIN_ID.ONE_OF.JS_MAIN).delete('type');
618
618
  });
619
- api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig, name })=>{
620
- const { normalizedConfig: { resolve, source, output, tools, performance, dev, testEnvironment }, outputModule, rootPath } = context.projects.find((p)=>p.environmentName === name);
619
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig, name })=>{
620
+ const { normalizedConfig: { resolve, source, output, tools, dev, testEnvironment }, outputModule, rootPath } = context.projects.find((p)=>p.environmentName === name);
621
+ const distRootDir = context.projects.length > 1 ? `${TEMP_RSTEST_OUTPUT_DIR}/${name}` : TEMP_RSTEST_OUTPUT_DIR;
621
622
  return mergeEnvironmentConfig(config, {
622
- performance,
623
623
  tools,
624
624
  resolve,
625
625
  source,
@@ -633,6 +633,7 @@ const pluginBasic = (context)=>({
633
633
  }
634
634
  },
635
635
  output: {
636
+ assetPrefix: '',
636
637
  manifest: `${name}-manifest.json`,
637
638
  sourceMap: {
638
639
  js: 'source-map'
@@ -642,7 +643,7 @@ const pluginBasic = (context)=>({
642
643
  js: '[name].mjs'
643
644
  } : void 0,
644
645
  distPath: {
645
- root: context.projects.length > 1 ? `${TEMP_RSTEST_OUTPUT_DIR}/${name}` : TEMP_RSTEST_OUTPUT_DIR
646
+ root: distRootDir
646
647
  }
647
648
  },
648
649
  tools: {
@@ -724,23 +725,41 @@ const pluginCSSFilter = ()=>({
724
725
  setup (api) {
725
726
  api.modifyBundlerChain({
726
727
  order: 'post',
727
- handler: async (chain, { target, CHAIN_ID, environment })=>{
728
+ handler: (chain, { target, CHAIN_ID, environment })=>{
728
729
  const emitCss = environment.config.output.emitCss ?? 'web' === target;
729
730
  if (!emitCss) {
730
731
  const ruleIds = [
731
- CHAIN_ID.RULE.CSS,
732
- CHAIN_ID.RULE.SASS,
733
- CHAIN_ID.RULE.LESS,
734
- CHAIN_ID.RULE.STYLUS
732
+ [
733
+ CHAIN_ID.RULE.CSS,
734
+ CHAIN_ID.ONE_OF.CSS_MAIN
735
+ ],
736
+ [
737
+ CHAIN_ID.RULE.SASS,
738
+ 'sass'
739
+ ],
740
+ [
741
+ CHAIN_ID.RULE.LESS,
742
+ 'less'
743
+ ],
744
+ [
745
+ CHAIN_ID.RULE.STYLUS,
746
+ 'stylus'
747
+ ]
735
748
  ];
736
- for (const ruleId of ruleIds){
749
+ for (const [ruleId, mainId] of ruleIds){
737
750
  if (!chain.module.rules.has(ruleId)) continue;
738
- const rule = chain.module.rule(ruleId);
751
+ const rule = chain.module.rule(ruleId).oneOf(mainId);
739
752
  if (!rule.uses.has(CHAIN_ID.USE.CSS)) continue;
740
753
  const cssLoaderOptions = rule.use(CHAIN_ID.USE.CSS).get('options');
741
- if (cssLoaderOptions.modules && ('object' != typeof cssLoaderOptions.modules || false !== cssLoaderOptions.modules.auto)) rule.use('rstest-css-pre-filter').loader(external_node_path_["default"].join(css_filter_dirname, 'cssFilterLoader.mjs')).options({
754
+ if (!cssLoaderOptions.modules || 'object' == typeof cssLoaderOptions.modules && false === cssLoaderOptions.modules.auto) continue;
755
+ const clonedOptions = {
756
+ ...cssLoaderOptions,
757
+ importLoaders: (cssLoaderOptions.importLoaders || 0) + 1
758
+ };
759
+ rule.use(CHAIN_ID.USE.CSS).options(clonedOptions);
760
+ rule.use('rstest-css-pre-filter').loader(external_node_path_["default"].join(css_filter_dirname, 'cssFilterLoader.mjs')).options({
742
761
  modules: cssLoaderOptions.modules
743
- }).after(ruleId);
762
+ }).after(mainId);
744
763
  }
745
764
  }
746
765
  }
@@ -821,7 +840,7 @@ function autoExternalNodeBuiltin({ request, dependencyType }, callback) {
821
840
  const pluginExternal = (context)=>({
822
841
  name: 'rstest:external',
823
842
  setup: (api)=>{
824
- api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig, name })=>{
843
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig, name })=>{
825
844
  const { normalizedConfig: { testEnvironment }, outputModule } = context.projects.find((p)=>p.environmentName === name);
826
845
  return mergeEnvironmentConfig(config, {
827
846
  output: {
@@ -854,7 +873,7 @@ class IgnoreModuleNotFoundErrorPlugin {
854
873
  const pluginIgnoreResolveError = {
855
874
  name: 'rstest:ignore-resolve-error',
856
875
  setup: (api)=>{
857
- api.modifyRspackConfig(async (config)=>{
876
+ api.modifyRspackConfig((config)=>{
858
877
  config.plugins.push(new IgnoreModuleNotFoundErrorPlugin());
859
878
  config.optimization ??= {};
860
879
  config.optimization.emitOnErrors = true;
@@ -869,7 +888,7 @@ const pluginInspect = (options)=>{
869
888
  return enable ? {
870
889
  name: 'rstest:inspect',
871
890
  setup: (api)=>{
872
- api.modifyRspackConfig(async (config)=>{
891
+ api.modifyRspackConfig((config)=>{
873
892
  config.devtool = 'inline-nosources-source-map';
874
893
  config.optimization ??= {};
875
894
  config.optimization.splitChunks = {
@@ -929,7 +948,7 @@ class MockRuntimeRspackPlugin {
929
948
  const pluginMockRuntime = {
930
949
  name: 'rstest:mock-runtime',
931
950
  setup: (api)=>{
932
- api.modifyRspackConfig(async (config)=>{
951
+ api.modifyRspackConfig((config)=>{
933
952
  config.plugins.push(new MockRuntimeRspackPlugin(Boolean(config.output.module)));
934
953
  });
935
954
  }
@@ -979,7 +998,7 @@ const pluginCacheControl = (setupFiles)=>({
979
998
  }
980
999
  `
981
1000
  }));
982
- api.modifyRspackConfig(async (config)=>{
1001
+ api.modifyRspackConfig((config)=>{
983
1002
  config.plugins.push(new RstestCacheControlPlugin());
984
1003
  });
985
1004
  }
@@ -1196,12 +1215,12 @@ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, globalSe
1196
1215
  return promise;
1197
1216
  };
1198
1217
  const buildData = {};
1199
- const getEntryFiles = async (manifest, outputPath)=>{
1218
+ const getEntryFiles = (manifest, outputPath)=>{
1200
1219
  const entryFiles = {};
1201
1220
  const entries = Object.keys(manifest.entries);
1202
1221
  for (const entry of entries){
1203
1222
  const data = manifest.entries[entry];
1204
- entryFiles[entry] = ((data?.initial?.js || []).concat(data?.async?.js || []) || []).map((file)=>posix.join(outputPath, file));
1223
+ entryFiles[entry] = ((data?.initial?.js || []).concat(data?.async?.js || []).concat(data?.assets?.filter((asset)=>!asset.endsWith('.map')) || []) || []).map((file)=>file.startsWith(outputPath) ? file : posix.join(outputPath, file));
1205
1224
  }
1206
1225
  return entryFiles;
1207
1226
  };
@@ -1220,7 +1239,7 @@ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, globalSe
1220
1239
  chunks: true,
1221
1240
  timings: true
1222
1241
  });
1223
- const entryFiles = await getEntryFiles(manifest, outputPath);
1242
+ const entryFiles = getEntryFiles(manifest, outputPath);
1224
1243
  const entries = [];
1225
1244
  const setupEntries = [];
1226
1245
  const globalSetupEntries = [];
package/dist/0~9634.js CHANGED
@@ -11,8 +11,8 @@ const collectNodeTests = async ({ context, nodeProjects, globTestSourceEntries }
11
11
  }));
12
12
  if (0 === nodeProjects.length) return {
13
13
  list: [],
14
- getSourceMap: async (_name)=>null,
15
- close: async ()=>{}
14
+ getSourceMap: async ()=>null,
15
+ close: async ()=>void 0
16
16
  };
17
17
  const setupFiles = Object.fromEntries(nodeProjects.map((project)=>{
18
18
  const { environmentName, rootPath, normalizedConfig: { setupFiles } } = project;
@@ -101,7 +101,7 @@ const collectNodeTests = async ({ context, nodeProjects, globTestSourceEntries }
101
101
  const collectBrowserTests = async ({ context, browserProjects, shardedEntries })=>{
102
102
  if (0 === browserProjects.length) return {
103
103
  list: [],
104
- close: async ()=>{}
104
+ close: async ()=>void 0
105
105
  };
106
106
  const { loadBrowserModule } = await import("./0~1472.js").then((mod)=>({
107
107
  loadBrowserModule: mod.loadBrowserModule
@@ -126,10 +126,10 @@ const collectTestFiles = async ({ context, globTestSourceEntries })=>{
126
126
  })));
127
127
  }
128
128
  return {
129
- close: async ()=>{},
129
+ close: async ()=>void 0,
130
130
  errors: [],
131
131
  list,
132
- getSourceMap: async (_name)=>null
132
+ getSourceMap: async ()=>null
133
133
  };
134
134
  };
135
135
  const collectAllTests = async ({ context, globTestSourceEntries, shardedEntries })=>{