vitest 5.0.0-rc.1 → 5.0.0-rc.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.
Files changed (42) hide show
  1. package/dist/browser.d.ts +4 -4
  2. package/dist/browser.js +2 -2
  3. package/dist/chunks/{base.IQV3unVv.js → base.C1WTaPOM.js} +8 -7
  4. package/dist/chunks/{browser.d.Dp8LNQdx.d.ts → browser.d.C9OF2Et_.d.ts} +3 -3
  5. package/dist/chunks/{cac.CM6y_f_i.js → cac.D09XQ6pO.js} +5 -5
  6. package/dist/chunks/{cli-api.B4r6twmv.js → cli-api.te-1Pvjs.js} +27 -19
  7. package/dist/chunks/{config.d.BpALOMjL.d.ts → config.d.CU_b-wJj.d.ts} +14 -21
  8. package/dist/chunks/{creator.BW8mSwbG.js → creator.Cqwo9lsW.js} +3 -3
  9. package/dist/chunks/{doctor.oxixVMjH.js → doctor.CNpBUniZ.js} +1 -1
  10. package/dist/chunks/{environment.d.DCnG-EPE.d.ts → environment.d.C0fjmVGG.d.ts} +1 -1
  11. package/dist/chunks/{globals.Dfl9zyCz.js → globals.C5MA6F-b.js} +2 -2
  12. package/dist/chunks/{index.DRmbsPYf.js → index.BH4BaN4R.js} +23 -22
  13. package/dist/chunks/{index.CePpwRnE.js → index.C0qliBI-.js} +2 -2
  14. package/dist/chunks/{index.DiRpHFrd.js → index.DzzDnMj8.js} +308 -218
  15. package/dist/chunks/{init-forks.BpFQPK_m.js → init-forks.Bo2g6tWs.js} +7 -10
  16. package/dist/chunks/{init-threads.DspSJVVe.js → init-threads.BSTHIk3P.js} +1 -1
  17. package/dist/chunks/{plugin.d.xikpJNpD.d.ts → plugin.d.CNqvINDS.d.ts} +11 -5
  18. package/dist/chunks/{rpc.d.DWQfGdI1.d.ts → rpc.d.DA9Utv4e.d.ts} +1 -1
  19. package/dist/chunks/{run.DS9d28OG.js → run.COOMV-72.js} +3 -1
  20. package/dist/chunks/{setup-common.D_kw2djf.js → setup-common.AcXJaDWq.js} +1 -1
  21. package/dist/chunks/{setup.CXTsmSEE.js → setup.CBDqPUzi.js} +11 -4
  22. package/dist/chunks/{source-map.d.DRVw4m2c.d.ts → source-map.d.YqWNcp4e.d.ts} +1 -1
  23. package/dist/chunks/{task-utils.d.B0b4kWzC.d.ts → task-utils.d.BZm4GSQD.d.ts} +1 -1
  24. package/dist/chunks/{vm.QEFtWwx4.js → vm.FXMbMqlj.js} +4 -3
  25. package/dist/chunks/{worker.d.D7LKSMQN.d.ts → worker.d.XSpk7g5N.d.ts} +3 -3
  26. package/dist/cli.js +1 -1
  27. package/dist/config.d.ts +9 -9
  28. package/dist/index.d.ts +11 -10
  29. package/dist/index.js +2 -2
  30. package/dist/module-evaluator.d.ts +2 -2
  31. package/dist/node.d.ts +16 -10
  32. package/dist/node.js +5 -5
  33. package/dist/runtime.d.ts +4 -4
  34. package/dist/worker.d.ts +4 -4
  35. package/dist/worker.js +6 -6
  36. package/dist/workers/forks.js +7 -7
  37. package/dist/workers/runVmTests.js +4 -4
  38. package/dist/workers/threads.js +7 -7
  39. package/dist/workers/vmForks.js +4 -4
  40. package/dist/workers/vmThreads.js +4 -4
  41. package/package.json +13 -13
  42. package/dist/chunks/{init.BU4khizz.js → init.i_K8EJrW.js} +2 -2
package/dist/browser.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { F as FileSpecification, c as SerializedDiffOptions } from './chunks/config.d.BpALOMjL.js';
1
+ import { F as FileSpecification, c as SerializedDiffOptions } from './chunks/config.d.CU_b-wJj.js';
2
2
  import { SerializedCoverageConfig, RunnerTestFile as File, SerializedConfig, DiffOptions, TestError } from './index.js';
3
3
  import { VitestRunner } from './runtime.js';
4
- export { P as ParsedStack, _ as SpyModule, d as StringifyOptions, f as format, i as inspect, s as stringify } from './chunks/config.d.BpALOMjL.js';
5
- import { R as RuntimeCoverageModuleLoader } from './chunks/source-map.d.DRVw4m2c.js';
6
- export { D as DecodedMap, g as getOriginalPosition } from './chunks/source-map.d.DRVw4m2c.js';
4
+ export { P as ParsedStack, _ as SpyModule, d as StringifyOptions, f as format, i as inspect, s as stringify } from './chunks/config.d.CU_b-wJj.js';
5
+ import { R as RuntimeCoverageModuleLoader } from './chunks/source-map.d.YqWNcp4e.js';
6
+ export { D as DecodedMap, g as getOriginalPosition } from './chunks/source-map.d.YqWNcp4e.js';
7
7
  import 'vitest/optional-runtime-types.js';
8
8
  import 'tinybench';
9
9
 
package/dist/browser.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/coverage.VANpXofm.js';
2
- export { p as collectTests, a as processError, s as startTests } from './chunks/run.DS9d28OG.js';
3
- export { l as loadDiffConfig, a as loadSnapshotSerializers, s as setupCommonEnv, b as setupEnv } from './chunks/setup-common.D_kw2djf.js';
2
+ export { p as collectTests, a as processError, s as startTests } from './chunks/run.COOMV-72.js';
3
+ export { l as loadDiffConfig, a as loadSnapshotSerializers, s as setupCommonEnv, b as setupEnv } from './chunks/setup-common.AcXJaDWq.js';
4
4
  export { s as SpyModule } from './chunks/spy.DPpyuUIA.js';
5
5
  export { f as format, i as inspect, s as stringify } from './chunks/display.pkpxlVcY.js';
6
6
  export { g as getType } from './chunks/pathe.M-eThtNZ.k2RS39sQ.js';
@@ -1,21 +1,21 @@
1
1
  import { runInThisContext } from 'node:vm';
2
2
  import { s as spyModule } from './spy.DPpyuUIA.js';
3
- import { r as resolveTestRunner, a as resolveSnapshotEnvironment, d as detectAsyncLeaks, s as setupChaiConfig } from './index.CePpwRnE.js';
4
- import { l as loadEnvironment, e as emitModuleRunner, a as listenForErrors } from './init.BU4khizz.js';
3
+ import { r as resolveTestRunner, a as resolveSnapshotEnvironment, d as detectAsyncLeaks, s as setupChaiConfig } from './index.C0qliBI-.js';
4
+ import { l as loadEnvironment, e as emitModuleRunner, a as listenForErrors } from './init.i_K8EJrW.js';
5
5
  import { Traces } from '../traces.js';
6
6
  import { V as VitestEvaluatedModules } from './rpc.DaPTofpf.js';
7
7
  import { s as startVitestModuleRunner, c as createNodeImportMeta } from './index.BfU4rh_M.js';
8
8
  import { performance as performance$1 } from 'node:perf_hooks';
9
9
  import { s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './coverage.VANpXofm.js';
10
- import { i as index, g as globalExpect, v as vi } from './index.DRmbsPYf.js';
10
+ import { i as index, g as globalExpect, v as vi } from './index.BH4BaN4R.js';
11
11
  import { c as closeInspector } from './inspector.CvyFGlXm.js';
12
- import { s as startTests, p as publicCollect } from './run.DS9d28OG.js';
12
+ import { s as startTests, p as publicCollect } from './run.COOMV-72.js';
13
13
  import { createRequire } from 'node:module';
14
14
  import timers from 'node:timers';
15
15
  import timersPromises from 'node:timers/promises';
16
16
  import util from 'node:util';
17
17
  import { K as KNOWN_ASSET_TYPES } from './pathe.M-eThtNZ.k2RS39sQ.js';
18
- import { s as setupCommonEnv, b as setupEnv } from './setup-common.D_kw2djf.js';
18
+ import { s as setupCommonEnv, b as setupEnv } from './setup-common.AcXJaDWq.js';
19
19
  import { g as getWorkerState, r as resetModules, p as provideWorkerState, a as getSafeWorkerState } from './utils.DYj33du9.js';
20
20
 
21
21
  // this should only be used in Node
@@ -108,10 +108,11 @@ const evaluatedModules = new VitestEvaluatedModules();
108
108
  const moduleExecutionInfo = /* @__PURE__ */ new Map();
109
109
  async function startModuleRunner(options) {
110
110
  if (_moduleRunner) return _moduleRunner;
111
+ const state = () => getSafeWorkerState() || options.state;
111
112
  process.exit = (code = process.exitCode || 0) => {
112
- throw new Error(`process.exit unexpectedly called with "${code}"`);
113
+ const filepath = state().filepath;
114
+ throw new Error(`process.exit unexpectedly called with "${code}"${filepath ? ` (test file: ${filepath})` : ""}`);
113
115
  };
114
- const state = () => getSafeWorkerState() || options.state;
115
116
  listenForErrors(state);
116
117
  if (options.state.config.experimental.viteModuleRunner === false) {
117
118
  const root = options.state.config.root;
@@ -1,6 +1,6 @@
1
- import { F as FileSpecification } from './config.d.BpALOMjL.js';
2
- import { O as OTELCarrier } from './rpc.d.DWQfGdI1.js';
3
- import { T as TestExecutionMethod } from './worker.d.D7LKSMQN.js';
1
+ import { F as FileSpecification } from './config.d.CU_b-wJj.js';
2
+ import { O as OTELCarrier } from './rpc.d.DA9Utv4e.js';
3
+ import { T as TestExecutionMethod } from './worker.d.XSpk7g5N.js';
4
4
 
5
5
  interface ModuleDefinitionLocation {
6
6
  line: number;
@@ -620,7 +620,7 @@ class CAC extends EventEmitter {
620
620
 
621
621
  const cac = (name = "") => new CAC(name);
622
622
 
623
- var version = "5.0.0-rc.1";
623
+ var version = "5.0.0-rc.2";
624
624
 
625
625
  const apiConfig = (port) => ({
626
626
  port: {
@@ -2363,7 +2363,7 @@ function normalizeCliOptions(cliFilters, argv) {
2363
2363
  }
2364
2364
  async function start(cliFilters, options) {
2365
2365
  try {
2366
- const { startVitest } = await import('./cli-api.B4r6twmv.js').then(function (n) { return n.a; });
2366
+ const { startVitest } = await import('./cli-api.te-1Pvjs.js').then(function (n) { return n.a; });
2367
2367
  const ctx = await startVitest(cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
2368
2368
  if (!ctx.shouldKeepServer()) await ctx.exit();
2369
2369
  } catch (e) {
@@ -2377,7 +2377,7 @@ async function start(cliFilters, options) {
2377
2377
  }
2378
2378
  async function doctorCommand(cliFilters, options) {
2379
2379
  try {
2380
- const { doctor } = await import('./doctor.oxixVMjH.js');
2380
+ const { doctor } = await import('./doctor.CNpBUniZ.js');
2381
2381
  await doctor(cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
2382
2382
  process.exit();
2383
2383
  } catch (e) {
@@ -2394,12 +2394,12 @@ async function init(project) {
2394
2394
  console.error(/* @__PURE__ */ new Error("Only the \"browser\" project is supported. Use \"vitest init browser\" to create a new project."));
2395
2395
  process.exit(1);
2396
2396
  }
2397
- const { create } = await import('./creator.BW8mSwbG.js');
2397
+ const { create } = await import('./creator.Cqwo9lsW.js');
2398
2398
  await create();
2399
2399
  }
2400
2400
  async function collect(cliFilters, options) {
2401
2401
  try {
2402
- const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.B4r6twmv.js').then(function (n) { return n.a; });
2402
+ const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.te-1Pvjs.js').then(function (n) { return n.a; });
2403
2403
  const ctx = await prepareVitest({
2404
2404
  ...normalizeCliOptions(cliFilters, options),
2405
2405
  watch: false,
@@ -1,6 +1,6 @@
1
1
  import { mkdirSync, writeFileSync } from 'node:fs';
2
2
  import { C as CoverageProviderMap } from './coverage.CPiksdSj.js';
3
- import { L as Logger, j as VitestPackageInstaller, P as PluginHarness, u as resolveConfig, V as Vitest, y as stdout, w as prompt, f as FilesNotFoundError, G as GitNotFoundError, I as IncludeTaskLocationDisabledError, z as RangeLocationFilterProvidedError, A as LocationFilterFileNotFoundError } from './index.DiRpHFrd.js';
3
+ import { L as Logger, k as VitestPackageInstaller, P as PluginHarness, v as resolveConfig, V as Vitest, z as stdout, x as prompt, g as FilesNotFoundError, G as GitNotFoundError, I as IncludeTaskLocationDisabledError, A as RangeLocationFilterProvidedError, C as LocationFilterFileNotFoundError } from './index.DzzDnMj8.js';
4
4
  import readline from 'node:readline';
5
5
  import { y } from './tinyrainbow.Ht9iggcq.js';
6
6
  import { i as isWindows } from './env.DzFJjrmK.js';
@@ -352,9 +352,14 @@ async function startVitest(modeOrCliFilters, cliFiltersOrOptions, optionsOrViteO
352
352
  const stdout = vitestOptions?.stdout || process.stdout;
353
353
  let stdinCleanup;
354
354
  if (stdin.isTTY && ctx.config.watch) stdinCleanup = registerConsoleShortcuts(ctx, stdin, stdout);
355
- ctx.onAfterSetServer(() => {
356
- if (ctx.config.standalone) ctx.standalone();
357
- else ctx.start(cliFilters);
355
+ ctx.onAfterSetServer(async () => {
356
+ if (ctx.closingPromise) return;
357
+ try {
358
+ if (ctx.config.standalone) await ctx.standalone();
359
+ else await ctx.start(cliFilters);
360
+ } catch (error) {
361
+ reportStartError(ctx, error);
362
+ }
358
363
  });
359
364
  try {
360
365
  if (ctx.config.listTags) await ctx.listTags();
@@ -364,21 +369,7 @@ async function startVitest(modeOrCliFilters, cliFiltersOrOptions, optionsOrViteO
364
369
  else await ctx.start(cliFilters);
365
370
  return ctx;
366
371
  } catch (e) {
367
- if (e instanceof FilesNotFoundError) return ctx;
368
- if (e instanceof GitNotFoundError) {
369
- ctx.logger.error(e.message);
370
- return ctx;
371
- }
372
- if (e instanceof IncludeTaskLocationDisabledError || e instanceof RangeLocationFilterProvidedError || e instanceof LocationFilterFileNotFoundError) {
373
- ctx.logger.printError(e, { verbose: false });
374
- return ctx;
375
- }
376
- process.exitCode = 1;
377
- ctx.logger.printError(e, {
378
- fullStack: true,
379
- type: "Unhandled Error"
380
- });
381
- ctx.logger.error("\n\n");
372
+ reportStartError(ctx, e);
382
373
  return ctx;
383
374
  } finally {
384
375
  if (!ctx?.shouldKeepServer()) {
@@ -387,6 +378,23 @@ async function startVitest(modeOrCliFilters, cliFiltersOrOptions, optionsOrViteO
387
378
  }
388
379
  }
389
380
  }
381
+ function reportStartError(ctx, error) {
382
+ if (error instanceof FilesNotFoundError) return;
383
+ if (error instanceof GitNotFoundError) {
384
+ ctx.logger.error(error.message);
385
+ return;
386
+ }
387
+ if (error instanceof IncludeTaskLocationDisabledError || error instanceof RangeLocationFilterProvidedError || error instanceof LocationFilterFileNotFoundError) {
388
+ ctx.logger.printError(error, { verbose: false });
389
+ return;
390
+ }
391
+ process.exitCode = 1;
392
+ ctx.logger.printError(error, {
393
+ fullStack: true,
394
+ type: "Unhandled Error"
395
+ });
396
+ ctx.logger.error("\n\n");
397
+ }
390
398
  async function prepareVitest(modeOrOptions, optionsOrViteOverrides, viteOverridesOrVitestOptions, vitestOptionsOrCliFilters, maybeCliFilters) {
391
399
  let options;
392
400
  let viteOverrides;
@@ -323,20 +323,6 @@ interface TestError extends SerializedError {
323
323
  expected?: string;
324
324
  }
325
325
 
326
- interface SnapshotEnvironment {
327
- getVersion: () => string;
328
- getHeader: () => string;
329
- resolvePath: (filepath: string) => Promise<string>;
330
- resolveRawPath: (testPath: string, rawPath: string) => Promise<string>;
331
- saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>;
332
- readSnapshotFile: (filepath: string) => Promise<string | null>;
333
- removeSnapshotFile: (filepath: string) => Promise<void>;
334
- processStackTrace?: (stack: ParsedStack) => ParsedStack;
335
- }
336
- interface SnapshotEnvironmentOptions {
337
- snapshotsDirName?: string;
338
- }
339
-
340
326
  interface DomainMatchResult {
341
327
  pass: boolean;
342
328
  message?: string;
@@ -385,13 +371,20 @@ interface RawSnapshotInfo {
385
371
  content?: string;
386
372
  }
387
373
 
388
- /**
389
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
390
- *
391
- * This source code is licensed under the MIT license found in the
392
- * LICENSE file in the root directory of this source tree.
393
- */
394
-
374
+ interface SnapshotEnvironment {
375
+ getVersion: () => string;
376
+ getHeader: () => string;
377
+ resolvePath: (filepath: string) => Promise<string>;
378
+ resolveRawPath: (testPath: string, rawPath: string) => Promise<string>;
379
+ saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>;
380
+ readSnapshotFile: (filepath: string) => Promise<string | null>;
381
+ readSnapshotFileData?: (filepath: string) => Promise<Record<string, string> | null>;
382
+ removeSnapshotFile: (filepath: string) => Promise<void>;
383
+ processStackTrace?: (stack: ParsedStack) => ParsedStack;
384
+ }
385
+ interface SnapshotEnvironmentOptions {
386
+ snapshotsDirName?: string;
387
+ }
395
388
  declare class DefaultMap<
396
389
  K,
397
390
  V
@@ -2,14 +2,14 @@ import { existsSync, writeFileSync, readFileSync } from 'node:fs';
2
2
  import { mkdir, writeFile } from 'node:fs/promises';
3
3
  import { resolve, dirname, relative } from 'node:path';
4
4
  import { detectPackageManager, installPackage } from './index.DXQx-kDM.js';
5
- import { w as prompt, x as findConfigFile } from './index.DiRpHFrd.js';
5
+ import { x as prompt, y as findConfigFile } from './index.DzzDnMj8.js';
6
6
  import { x } from 'tinyexec';
7
7
  import { y } from './tinyrainbow.Ht9iggcq.js';
8
8
  import 'node:process';
9
9
  import 'node:os';
10
10
  import './pathe.M-eThtNZ.k2RS39sQ.js';
11
11
  import './source-map.CTObTzjj.js';
12
- import './cac.CM6y_f_i.js';
12
+ import './cac.D09XQ6pO.js';
13
13
  import 'events';
14
14
  import './env.DzFJjrmK.js';
15
15
  import 'std-env';
@@ -17,7 +17,7 @@ import './constants.-juJ8b_4.js';
17
17
  import 'node:assert';
18
18
  import '../path.js';
19
19
  import 'node:url';
20
- import './run.DS9d28OG.js';
20
+ import './run.COOMV-72.js';
21
21
  import './index.M2dsQ_UQ.js';
22
22
  import './display.pkpxlVcY.js';
23
23
  import '../task-utils.js';
@@ -99,7 +99,7 @@ function log(...args) {
99
99
  console.log(...args);
100
100
  }
101
101
  async function doctor(cliFilters, options) {
102
- const { prepareVitest } = await import('./cli-api.B4r6twmv.js').then(function (n) { return n.a; });
102
+ const { prepareVitest } = await import('./cli-api.te-1Pvjs.js').then(function (n) { return n.a; });
103
103
  log();
104
104
  log(y.inverse(y.bold(y.blue(" DOCTOR "))), "resolving the current configuration...");
105
105
  const ctx = await prepareVitest({
@@ -1,4 +1,4 @@
1
- import { A as Awaitable } from './config.d.BpALOMjL.js';
1
+ import { A as Awaitable } from './config.d.CU_b-wJj.js';
2
2
 
3
3
  interface EnvironmentReturn {
4
4
  teardown: (global: any) => Awaitable<void>;
@@ -1,6 +1,6 @@
1
1
  import { g as globalApis } from './constants.-juJ8b_4.js';
2
- import { i as index } from './index.DRmbsPYf.js';
3
- import './run.DS9d28OG.js';
2
+ import { i as index } from './index.BH4BaN4R.js';
3
+ import './run.COOMV-72.js';
4
4
  import './index.M2dsQ_UQ.js';
5
5
  import './tinyrainbow.Ht9iggcq.js';
6
6
  import './display.pkpxlVcY.js';
@@ -1,4 +1,4 @@
1
- import { b as printDiffOrStringify, d as diff, a as processError, T as TestSyntaxError, g as getCurrentTest, c as createTaskCollector, e as getCurrentSuite, f as createChainable, h as getHooks, i as getFn, m as matchesTags, j as afterAll, k as afterEach, l as aroundAll, n as aroundEach, o as beforeAll, q as beforeEach, r as describe, t as it, u as onTestFailed, v as onTestFinished, w as recordArtifact, x as suite, y as test } from './run.DS9d28OG.js';
1
+ import { b as printDiffOrStringify, d as diff, a as processError, T as TestSyntaxError, g as getCurrentTest, c as createTaskCollector, e as getCurrentSuite, f as createChainable, h as getHooks, i as getFn, m as matchesTags, j as afterAll, k as afterEach, l as aroundAll, n as aroundEach, o as beforeAll, q as beforeEach, r as describe, t as it, u as onTestFailed, v as onTestFinished, w as recordArtifact, x as suite, y as test } from './run.COOMV-72.js';
2
2
  import { i as isChildProcess, r as resetModules, g as getWorkerState } from './utils.DYj33du9.js';
3
3
  import { d as getDefaultExportFromCjs, h as parseErrorStacktrace, i as commonjsGlobal, a as getSafeTimers, f as parseSingleStack, j as delay } from './source-map.CTObTzjj.js';
4
4
  import { i as isMockFunction, f as fn, a as spyOn, r as restoreAllMocks, b as resetAllMocks, c as clearAllMocks } from './spy.DPpyuUIA.js';
@@ -90,22 +90,15 @@ function keyToTestName(key) {
90
90
  if (!/ \d+$/.test(key)) throw new Error("Snapshot keys must end with a number.");
91
91
  return key.replace(/ \d+$/, "");
92
92
  }
93
- function getSnapshotData(content, options) {
94
- const update = options.updateSnapshot;
93
+ // Evaluate a snapshot file's content into its snapshot key/value pairs.
94
+ function evaluateSnapshotFile(filepath, content) {
95
95
  const data = Object.create(null);
96
- let snapshotContents = "";
97
- let dirty = false;
98
- if (content != null) try {
99
- snapshotContents = content;
100
- new Function("exports", snapshotContents)(data);
101
- } catch {}
102
- // if (update === 'none' && isInvalid)
103
- // throw validationResult
104
- if ((update === "all" || update === "new") && snapshotContents) dirty = true;
105
- return {
106
- data,
107
- dirty
108
- };
96
+ try {
97
+ new Function("exports", content)(data);
98
+ } catch (cause) {
99
+ throw new Error(`Invalid snapshot file, please manually fix or delete it: ${filepath}`, { cause });
100
+ }
101
+ return data;
109
102
  }
110
103
  // Add extra line breaks at beginning and end of multiline snapshot
111
104
  // to make the content easier to read.
@@ -420,11 +413,13 @@ class SnapshotState {
420
413
  set updated(value) {
421
414
  this._updated._total = value;
422
415
  }
423
- constructor(testFilePath, snapshotPath, snapshotContent, options) {
416
+ constructor(testFilePath, snapshotPath, fileData, options) {
424
417
  this.testFilePath = testFilePath;
425
418
  this.snapshotPath = snapshotPath;
426
- const { data, dirty } = getSnapshotData(snapshotContent, options);
427
- this._fileExists = snapshotContent != null;
419
+ const data = fileData ?? Object.create(null);
420
+ this._fileExists = fileData != null;
421
+ const update = options.updateSnapshot;
422
+ const dirty = (update === "all" || update === "new") && fileData != null;
428
423
  this._initialData = { ...data };
429
424
  this._snapshotData = { ...data };
430
425
  this._dirty = dirty;
@@ -446,9 +441,15 @@ class SnapshotState {
446
441
  this._environment = options.snapshotEnvironment;
447
442
  }
448
443
  static async create(testFilePath, options) {
449
- const snapshotPath = await options.snapshotEnvironment.resolvePath(testFilePath);
450
- const content = await options.snapshotEnvironment.readSnapshotFile(snapshotPath);
451
- return new SnapshotState(testFilePath, snapshotPath, content, options);
444
+ const environment = options.snapshotEnvironment;
445
+ const snapshotPath = await environment.resolvePath(testFilePath);
446
+ let fileData;
447
+ if (environment.readSnapshotFileData) fileData = await environment.readSnapshotFileData(snapshotPath);
448
+ else {
449
+ const content = await environment.readSnapshotFile(snapshotPath);
450
+ fileData = content != null ? evaluateSnapshotFile(snapshotPath, content) : null;
451
+ }
452
+ return new SnapshotState(testFilePath, snapshotPath, fileData, options);
452
453
  }
453
454
  get snapshotUpdateState() {
454
455
  return this._updateSnapshot;
@@ -2,9 +2,9 @@ import * as chai from 'chai';
2
2
  import { createHook } from 'node:async_hooks';
3
3
  import { t as takeCoverageInsideWorker } from './coverage.VANpXofm.js';
4
4
  import { r as rpc } from './rpc.DaPTofpf.js';
5
- import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.D_kw2djf.js';
5
+ import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.AcXJaDWq.js';
6
6
  import { g as getWorkerState } from './utils.DYj33du9.js';
7
- import { T as TestRunner } from './index.DRmbsPYf.js';
7
+ import { T as TestRunner } from './index.BH4BaN4R.js';
8
8
 
9
9
  function setupChaiConfig(config) {
10
10
  Object.assign(chai.config, config);