@vitest/runner 5.0.0-beta.1 → 5.0.0-beta.2

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.
@@ -1074,17 +1074,17 @@ function calculateSuiteHash(parent) {
1074
1074
  }
1075
1075
  });
1076
1076
  }
1077
- function createFileTask(filepath, root, projectName, pool, viteEnvironment) {
1077
+ function createFileTask(filepath, root, projectName, pool, viteEnvironment, meta) {
1078
1078
  const path = relative(root, filepath);
1079
1079
  const file = {
1080
- id: generateFileHash(path, projectName),
1080
+ id: generateFileHash(path, projectName, meta),
1081
1081
  name: path,
1082
1082
  fullName: path,
1083
1083
  type: "suite",
1084
1084
  mode: "queued",
1085
1085
  filepath,
1086
1086
  tasks: [],
1087
- meta: Object.create(null),
1087
+ meta: Object.assign(Object.create(null), meta),
1088
1088
  projectName,
1089
1089
  file: undefined,
1090
1090
  pool,
@@ -1099,8 +1099,14 @@ function createFileTask(filepath, root, projectName, pool, viteEnvironment) {
1099
1099
  * @param projectName The name of the test project
1100
1100
  */
1101
1101
  /* @__NO_SIDE_EFFECTS__ */
1102
- function generateFileHash(file, projectName) {
1103
- return /* @__PURE__ */ generateHash(`${file}${projectName || ""}`);
1102
+ function generateFileHash(file, projectName, meta) {
1103
+ const seed = [
1104
+ file,
1105
+ projectName || "",
1106
+ meta?.typecheck ? "__typecheck__" : "",
1107
+ meta?.__vitest_label__ || ""
1108
+ ].join("\0");
1109
+ return generateHash(seed);
1104
1110
  }
1105
1111
  function findTestFileStackTrace(testFilePath, error) {
1106
1112
  // first line is the error message
@@ -1741,11 +1747,25 @@ function createSuiteCollector(name, factory = () => {}, mode, each, suiteOptions
1741
1747
  return acc;
1742
1748
  }, {});
1743
1749
  const testOwnMeta = options.meta;
1750
+ const parentOptions = collectorContext.currentSuite?.options;
1744
1751
  options = {
1752
+ ...parentOptions,
1745
1753
  ...tagsOptions,
1746
1754
  ...options
1747
1755
  };
1748
1756
  const timeout = options.timeout ?? runner.config.testTimeout;
1757
+ // TODO: should this be `parentTask.meta`?
1758
+ // currently we don't inherit
1759
+ // file.meta -> task.meta
1760
+ // file.meta -> suite.meta (see initSuite)
1761
+ // but we do inherit
1762
+ // suite.meta -> task.meta
1763
+ // suite.meta -> suite.meta
1764
+ // and also
1765
+ // file.tags -> task.tags
1766
+ // file.tags -> suite.tags
1767
+ // suite.tags -> suite.tags
1768
+ // suite.tags -> task.tags
1749
1769
  const parentMeta = currentSuite?.meta;
1750
1770
  const tagMeta = tagsOptions.meta;
1751
1771
  const testMeta = Object.create(null);
@@ -1782,7 +1802,7 @@ function createSuiteCollector(name, factory = () => {}, mode, each, suiteOptions
1782
1802
  if (task.mode === "run" && !handler) {
1783
1803
  task.mode = "todo";
1784
1804
  }
1785
- if (options.concurrent || !options.sequential && runner.config.sequence.concurrent) {
1805
+ if (options.concurrent ?? runner.config.sequence.concurrent) {
1786
1806
  task.concurrent = true;
1787
1807
  }
1788
1808
  task.shuffle = suiteOptions?.shuffle;
@@ -1814,20 +1834,11 @@ function createSuiteCollector(name, factory = () => {}, mode, each, suiteOptions
1814
1834
  return task;
1815
1835
  };
1816
1836
  const test = createTest(function(name, optionsOrFn, timeoutOrTest) {
1817
- let { options, handler } = parseArguments(optionsOrFn, timeoutOrTest);
1818
- // inherit repeats, retry, timeout from suite
1819
- if (typeof suiteOptions === "object") {
1820
- options = Object.assign({}, suiteOptions, options);
1821
- }
1822
- // inherit concurrent / sequential from suite
1823
- const concurrent = this.concurrent ?? (!this.sequential && options?.concurrent);
1824
- if (options.concurrent != null && concurrent != null) {
1837
+ const { options, handler } = parseArguments(optionsOrFn, timeoutOrTest);
1838
+ const concurrent = this.concurrent ?? options?.concurrent;
1839
+ if (concurrent != null) {
1825
1840
  options.concurrent = concurrent;
1826
1841
  }
1827
- const sequential = this.sequential ?? (!this.concurrent && options?.sequential);
1828
- if (options.sequential != null && sequential != null) {
1829
- options.sequential = sequential;
1830
- }
1831
1842
  const test = task(formatName(name), {
1832
1843
  ...this,
1833
1844
  ...options,
@@ -1933,8 +1944,6 @@ function createSuite() {
1933
1944
  }
1934
1945
  const currentSuite = collectorContext.currentSuite || defaultSuite;
1935
1946
  let { options, handler: factory } = parseArguments(factoryOrOptions, optionsOrFactory);
1936
- const isConcurrentSpecified = options.concurrent || this.concurrent || options.sequential === false;
1937
- const isSequentialSpecified = options.sequential || this.sequential || options.concurrent === false;
1938
1947
  const { meta: parentMeta, ...parentOptions } = currentSuite?.options || {};
1939
1948
  // inherit options from current suite
1940
1949
  options = {
@@ -1950,14 +1959,9 @@ function createSuite() {
1950
1959
  if (mode === "run" && !factory) {
1951
1960
  mode = "todo";
1952
1961
  }
1953
- // inherit concurrent / sequential from suite
1954
- const isConcurrent = isConcurrentSpecified || options.concurrent && !isSequentialSpecified;
1955
- const isSequential = isSequentialSpecified || options.sequential && !isConcurrentSpecified;
1956
- if (isConcurrent != null) {
1957
- options.concurrent = isConcurrent && !isSequential;
1958
- }
1959
- if (isSequential != null) {
1960
- options.sequential = isSequential && !isConcurrent;
1962
+ const concurrent = this.concurrent ?? options.concurrent;
1963
+ if (concurrent != null) {
1964
+ options.concurrent = concurrent;
1961
1965
  }
1962
1966
  if (parentMeta) {
1963
1967
  options.meta = Object.assign(Object.create(null), parentMeta, options.meta);
@@ -1996,6 +2000,8 @@ function createSuite() {
1996
2000
  };
1997
2001
  };
1998
2002
  suiteFn.for = function(cases, ...args) {
2003
+ const context = getChainableContext(this);
2004
+ const suite = context.withContext();
1999
2005
  if (Array.isArray(cases) && args.length) {
2000
2006
  cases = formatTemplateString(cases, args);
2001
2007
  }
@@ -2011,7 +2017,6 @@ function createSuite() {
2011
2017
  suiteFn.runIf = (condition) => condition ? suite : suite.skip;
2012
2018
  return createChainable([
2013
2019
  "concurrent",
2014
- "sequential",
2015
2020
  "shuffle",
2016
2021
  "skip",
2017
2022
  "only",
@@ -2166,7 +2171,6 @@ function createTaskCollector(fn) {
2166
2171
  taskFn.aroundAll = aroundAll;
2167
2172
  const _test = createChainable([
2168
2173
  "concurrent",
2169
- "sequential",
2170
2174
  "skip",
2171
2175
  "only",
2172
2176
  "todo",
@@ -2282,7 +2286,7 @@ function withTimeout(fn, timeout, isHook = false, stackTraceError, onTimeout) {
2282
2286
  return fn;
2283
2287
  }
2284
2288
  const { setTimeout, clearTimeout } = getSafeTimers();
2285
- // this function name is used to filter error in test/cli/test/fails.test.ts
2289
+ // this function name is used to filter error in test/e2e/test/fails.test.ts
2286
2290
  return (function runWithTimeout(...args) {
2287
2291
  const startTime = now$2();
2288
2292
  const runner = getRunner();
@@ -2456,7 +2460,7 @@ async function collectTests(specs, runner) {
2456
2460
  const testIds = typeof spec === "string" ? undefined : spec.testIds;
2457
2461
  const testTagsFilter = typeof spec === "object" && spec.testTagsFilter ? createTagsFilter(spec.testTagsFilter, config.tags) : undefined;
2458
2462
  const fileTags = typeof spec === "string" ? [] : spec.fileTags || [];
2459
- const file = createFileTask(filepath, config.root, config.name, runner.pool, runner.viteEnvironment);
2463
+ const file = createFileTask(filepath, config.root, config.name, runner.pool, runner.viteEnvironment, { __vitest_label__: config.mergeReportsLabel });
2460
2464
  file.tags = fileTags;
2461
2465
  file.shuffle = config.sequence.shuffle;
2462
2466
  try {
@@ -3163,7 +3167,8 @@ async function runSuite(suite, runner) {
3163
3167
  } else {
3164
3168
  for (let tasksGroup of partitionSuiteChildren(suite)) {
3165
3169
  if (tasksGroup[0].concurrent === true) {
3166
- await Promise.all(tasksGroup.map((c) => runSuiteChild(c, runner)));
3170
+ const groupLimiter = limitConcurrency(runner.config.maxConcurrency);
3171
+ await Promise.all(tasksGroup.map((c) => groupLimiter(() => runSuiteChild(c, runner))));
3167
3172
  } else {
3168
3173
  const { sequence } = runner.config;
3169
3174
  if (suite.shuffle) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { d as TestArtifact, b as Test, S as Suite, e as SuiteHooks, f as FileSpecification, g as VitestRunner, F as File, h as TaskUpdateEvent, T as Task, i as TestAPI, j as SuiteAPI, k as SuiteCollector } from './tasks.d-Br8qsHTh.js';
2
- export { A as AfterAllListener, l as AfterEachListener, m as AroundAllListener, n as AroundEachListener, B as BeforeAllListener, o as BeforeEachListener, p as BrowserTraceArtifact, q as CancelReason, r as FailureScreenshotArtifact, s as Fixture, t as FixtureFn, u as FixtureOptions, v as Fixtures, I as ImportDuration, w as InferFixturesTypes, O as OnTestFailedHandler, x as OnTestFinishedHandler, R as Retry, y as RunMode, z as RuntimeContext, D as SequenceHooks, E as SequenceSetupFiles, G as SerializableRetry, H as SuiteFactory, J as SuiteOptions, K as TaskBase, L as TaskCustomOptions, M as TaskEventPack, N as TaskHook, P as TaskMeta, Q as TaskPopulated, U as TaskResult, W as TaskResultPack, X as TaskState, Y as TestAnnotation, Z as TestAnnotationArtifact, _ as TestAnnotationLocation, $ as TestArtifactBase, a0 as TestArtifactLocation, a1 as TestArtifactRegistry, a2 as TestAttachment, a3 as TestContext, a4 as TestFunction, a5 as TestOptions, a as TestTagDefinition, a6 as TestTags, a7 as Use, a8 as VisualRegressionArtifact, V as VitestRunnerConfig, a9 as VitestRunnerConstructor, aa as VitestRunnerImportSource, ab as afterAll, ac as afterEach, ad as aroundAll, ae as aroundEach, af as beforeAll, ag as beforeEach, ah as onTestFailed, ai as onTestFinished } from './tasks.d-Br8qsHTh.js';
1
+ import { d as TestArtifact, b as Test, S as Suite, e as SuiteHooks, f as FileSpecification, g as VitestRunner, F as File, h as TaskUpdateEvent, T as Task, i as TestAPI, j as SuiteAPI, k as SuiteCollector } from './tasks.d-B4a0-8OW.js';
2
+ export { A as AfterAllListener, l as AfterEachListener, m as AroundAllListener, n as AroundEachListener, B as BeforeAllListener, o as BeforeEachListener, p as BrowserTraceArtifact, q as CancelReason, r as FailureScreenshotArtifact, s as Fixture, t as FixtureFn, u as FixtureOptions, v as Fixtures, I as ImportDuration, w as InferFixturesTypes, O as OnTestFailedHandler, x as OnTestFinishedHandler, R as Retry, y as RunMode, z as RuntimeContext, D as SequenceHooks, E as SequenceSetupFiles, G as SerializableRetry, H as SuiteFactory, J as SuiteOptions, K as TaskBase, L as TaskCustomOptions, M as TaskEventPack, N as TaskHook, P as TaskMeta, Q as TaskPopulated, U as TaskResult, W as TaskResultPack, X as TaskState, Y as TestAnnotation, Z as TestAnnotationArtifact, _ as TestAnnotationLocation, $ as TestArtifactBase, a0 as TestArtifactLocation, a1 as TestArtifactRegistry, a2 as TestAttachment, a3 as TestContext, a4 as TestFunction, a5 as TestOptions, a as TestTagDefinition, a6 as TestTags, a7 as Use, a8 as VisualRegressionArtifact, V as VitestRunnerConfig, a9 as VitestRunnerConstructor, aa as VitestRunnerImportSource, ab as afterAll, ac as afterEach, ad as aroundAll, ae as aroundEach, af as beforeAll, ag as beforeEach, ah as onTestFailed, ai as onTestFinished } from './tasks.d-B4a0-8OW.js';
3
3
  import { Awaitable } from '@vitest/utils';
4
4
  import '@vitest/utils/diff';
5
5
 
@@ -31,6 +31,7 @@ interface VitestRunnerConfig {
31
31
  tags: TestTagDefinition[];
32
32
  tagsFilter: string[] | undefined;
33
33
  strictTags: boolean;
34
+ mergeReportsLabel: string | undefined;
34
35
  }
35
36
  /**
36
37
  * Possible options to run a single file in a test.
@@ -402,6 +403,13 @@ type ChainableFunction<
402
403
  > = F & { [x in T] : ChainableFunction<T, F, C> } & {
403
404
  fn: (this: Record<T, any>, ...args: Parameters<F>) => ReturnType<F>;
404
405
  } & C;
406
+ type TypedChainableFunction<
407
+ T,
408
+ F extends (...args: any) => any,
409
+ C = object
410
+ > = F & { [x in keyof T] : TypedChainableFunction<T, F, C> } & {
411
+ fn: (this: Record<keyof T, any>, ...args: Parameters<F>) => ReturnType<F>;
412
+ } & C;
405
413
  declare function createChainable<
406
414
  T extends string,
407
415
  Args extends any[],
@@ -711,7 +719,8 @@ interface TestCollectorCallable<C = object> {
711
719
  <ExtraContext extends C>(name: string | Function, fn?: TestFunction<ExtraContext>, options?: number): void;
712
720
  <ExtraContext extends C>(name: string | Function, options?: TestCollectorOptions, fn?: TestFunction<ExtraContext>): void;
713
721
  }
714
- type ChainableTestAPI<ExtraContext = object> = ChainableFunction<"concurrent" | "sequential" | "only" | "skip" | "todo" | "fails", TestCollectorCallable<ExtraContext>, {
722
+ type ChainableTestContextMap = Pick<Required<TestOptions>, "concurrent" | "only" | "skip" | "todo" | "fails">;
723
+ type ChainableTestAPI<ExtraContext = object> = TypedChainableFunction<ChainableTestContextMap, TestCollectorCallable<ExtraContext>, {
715
724
  each: TestEachFunction;
716
725
  for: TestForFunction<ExtraContext>;
717
726
  }>;
@@ -791,11 +800,6 @@ interface TestOptions {
791
800
  */
792
801
  concurrent?: boolean;
793
802
  /**
794
- * Whether tests run sequentially.
795
- * Tests inherit `sequential` from `describe()` and nested `describe()` will inherit from parent's `sequential`.
796
- */
797
- sequential?: boolean;
798
- /**
799
803
  * Whether the test should be skipped.
800
804
  */
801
805
  skip?: boolean;
@@ -1191,7 +1195,8 @@ interface SuiteCollectorCallable<ExtraContext = object> {
1191
1195
  <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn?: SuiteFactory<OverrideExtraContext>, options?: number): SuiteCollector<OverrideExtraContext>;
1192
1196
  <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, options: SuiteOptions, fn?: SuiteFactory<OverrideExtraContext>): SuiteCollector<OverrideExtraContext>;
1193
1197
  }
1194
- type ChainableSuiteAPI<ExtraContext = object> = ChainableFunction<"concurrent" | "sequential" | "only" | "skip" | "todo" | "shuffle", SuiteCollectorCallable<ExtraContext>, {
1198
+ type ChainableSuiteContextMap = Pick<Required<SuiteOptions>, "concurrent" | "only" | "skip" | "todo" | "shuffle">;
1199
+ type ChainableSuiteAPI<ExtraContext = object> = TypedChainableFunction<ChainableSuiteContextMap, SuiteCollectorCallable<ExtraContext>, {
1195
1200
  each: TestEachFunction;
1196
1201
  for: SuiteForFunction;
1197
1202
  }>;
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { A as AfterAllListener, l as AfterEachListener, m as AroundAllListener, n as AroundEachListener, B as BeforeAllListener, o as BeforeEachListener, p as BrowserTraceArtifact, q as CancelReason, r as FailureScreenshotArtifact, F as File, f as FileSpecification, s as Fixture, t as FixtureFn, u as FixtureOptions, v as Fixtures, I as ImportDuration, w as InferFixturesTypes, O as OnTestFailedHandler, x as OnTestFinishedHandler, R as Retry, y as RunMode, z as RuntimeContext, D as SequenceHooks, E as SequenceSetupFiles, G as SerializableRetry, S as Suite, j as SuiteAPI, k as SuiteCollector, H as SuiteFactory, e as SuiteHooks, J as SuiteOptions, T as Task, K as TaskBase, L as TaskCustomOptions, M as TaskEventPack, N as TaskHook, P as TaskMeta, Q as TaskPopulated, U as TaskResult, W as TaskResultPack, X as TaskState, h as TaskUpdateEvent, b as Test, i as TestAPI, Y as TestAnnotation, Z as TestAnnotationArtifact, _ as TestAnnotationLocation, d as TestArtifact, $ as TestArtifactBase, a0 as TestArtifactLocation, a1 as TestArtifactRegistry, a2 as TestAttachment, a3 as TestContext, a4 as TestFunction, a5 as TestOptions, a as TestTagDefinition, a6 as TestTags, a7 as Use, a8 as VisualRegressionArtifact, g as VitestRunner, V as VitestRunnerConfig, a9 as VitestRunnerConstructor, aa as VitestRunnerImportSource } from './tasks.d-Br8qsHTh.js';
1
+ export { A as AfterAllListener, l as AfterEachListener, m as AroundAllListener, n as AroundEachListener, B as BeforeAllListener, o as BeforeEachListener, p as BrowserTraceArtifact, q as CancelReason, r as FailureScreenshotArtifact, F as File, f as FileSpecification, s as Fixture, t as FixtureFn, u as FixtureOptions, v as Fixtures, I as ImportDuration, w as InferFixturesTypes, O as OnTestFailedHandler, x as OnTestFinishedHandler, R as Retry, y as RunMode, z as RuntimeContext, D as SequenceHooks, E as SequenceSetupFiles, G as SerializableRetry, S as Suite, j as SuiteAPI, k as SuiteCollector, H as SuiteFactory, e as SuiteHooks, J as SuiteOptions, T as Task, K as TaskBase, L as TaskCustomOptions, M as TaskEventPack, N as TaskHook, P as TaskMeta, Q as TaskPopulated, U as TaskResult, W as TaskResultPack, X as TaskState, h as TaskUpdateEvent, b as Test, i as TestAPI, Y as TestAnnotation, Z as TestAnnotationArtifact, _ as TestAnnotationLocation, d as TestArtifact, $ as TestArtifactBase, a0 as TestArtifactLocation, a1 as TestArtifactRegistry, a2 as TestAttachment, a3 as TestContext, a4 as TestFunction, a5 as TestOptions, a as TestTagDefinition, a6 as TestTags, a7 as Use, a8 as VisualRegressionArtifact, g as VitestRunner, V as VitestRunnerConfig, a9 as VitestRunnerConstructor, aa as VitestRunnerImportSource } from './tasks.d-B4a0-8OW.js';
2
2
  import '@vitest/utils';
3
3
  import '@vitest/utils/diff';
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Suite, F as File, T as Task, a as TestTagDefinition, V as VitestRunnerConfig, b as Test } from './tasks.d-Br8qsHTh.js';
2
- export { C as ChainableFunction, c as createChainable } from './tasks.d-Br8qsHTh.js';
1
+ import { S as Suite, F as File, T as Task, a as TestTagDefinition, V as VitestRunnerConfig, b as Test } from './tasks.d-B4a0-8OW.js';
2
+ export { C as ChainableFunction, c as createChainable } from './tasks.d-B4a0-8OW.js';
3
3
  import { ParsedStack, Arrayable } from '@vitest/utils';
4
4
  import '@vitest/utils/diff';
5
5
 
@@ -10,13 +10,17 @@ declare function interpretTaskModes(file: Suite, namePattern?: string | RegExp,
10
10
  declare function someTasksAreOnly(suite: Suite): boolean;
11
11
  declare function generateHash(str: string): string;
12
12
  declare function calculateSuiteHash(parent: Suite): void;
13
- declare function createFileTask(filepath: string, root: string, projectName: string | undefined, pool?: string, viteEnvironment?: string): File;
13
+ interface HashMeta {
14
+ typecheck?: boolean;
15
+ __vitest_label__?: string;
16
+ }
17
+ declare function createFileTask(filepath: string, root: string, projectName: string | undefined, pool?: string, viteEnvironment?: string, meta?: HashMeta): File;
14
18
  /**
15
19
  * Generate a unique ID for a file based on its path and project name
16
20
  * @param file File relative to the root of the project to keep ID the same between different machines
17
21
  * @param projectName The name of the test project
18
22
  */
19
- declare function generateFileHash(file: string, projectName: string | undefined): string;
23
+ declare function generateFileHash(file: string, projectName: string | undefined, meta?: HashMeta): string;
20
24
  declare function findTestFileStackTrace(testFilePath: string, error: string): ParsedStack | undefined;
21
25
 
22
26
  interface ConcurrencyLimiter extends ConcurrencyLimiterFn {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "5.0.0-beta.1",
4
+ "version": "5.0.0-beta.2",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -44,7 +44,7 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "pathe": "^2.0.3",
47
- "@vitest/utils": "5.0.0-beta.1"
47
+ "@vitest/utils": "5.0.0-beta.2"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "premove dist && rollup -c",