vitest 0.0.121 → 0.0.125

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/node.d.ts CHANGED
@@ -122,24 +122,44 @@ interface UserConsoleLog {
122
122
  type: 'stdout' | 'stderr';
123
123
  taskId?: string;
124
124
  }
125
+ interface Position {
126
+ line: number;
127
+ column: number;
128
+ }
129
+ interface ParsedStack {
130
+ method: string;
131
+ file: string;
132
+ line: number;
133
+ column: number;
134
+ sourcePos?: Position;
135
+ }
136
+ interface ErrorWithDiff extends Error {
137
+ name: string;
138
+ nameStr?: string;
139
+ stack?: string;
140
+ stackStr?: string;
141
+ stacks?: ParsedStack[];
142
+ showDiff?: boolean;
143
+ actual?: any;
144
+ expected?: any;
145
+ operator?: string;
146
+ }
125
147
 
126
148
  declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
127
149
  declare type TaskState = RunMode | 'pass' | 'fail';
128
- declare type ComputeMode = 'serial' | 'concurrent';
129
150
  interface TaskBase {
130
151
  id: string;
131
152
  name: string;
132
153
  mode: RunMode;
133
- computeMode: ComputeMode;
154
+ concurrent?: boolean;
134
155
  suite?: Suite;
135
156
  file?: File;
136
157
  result?: TaskResult;
137
158
  }
138
159
  interface TaskResult {
139
160
  state: TaskState;
140
- start: number;
141
- end?: number;
142
- error?: unknown;
161
+ duration?: number;
162
+ error?: ErrorWithDiff;
143
163
  }
144
164
  declare type TaskResultPack = [id: string, result: TaskResult | undefined];
145
165
  interface Suite extends TaskBase {
@@ -148,6 +168,7 @@ interface Suite extends TaskBase {
148
168
  }
149
169
  interface File extends Suite {
150
170
  filepath: string;
171
+ collectDuration?: number;
151
172
  }
152
173
  interface Test extends TaskBase {
153
174
  type: 'test';
@@ -237,6 +258,20 @@ interface InlineConfig {
237
258
  * This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
238
259
  */
239
260
  inline?: (string | RegExp)[];
261
+ /**
262
+ * Interpret CJS module's default as named exports
263
+ *
264
+ * @default true
265
+ */
266
+ interpretDefault?: boolean;
267
+ /**
268
+ * When a dependency is a valid ESM package, try to guess the cjs version based on the path.
269
+ * This will significantly improve the performance in huge repo, but might potentially
270
+ * cause some misalignment if a package have different logic in ESM and CJS mode.
271
+ *
272
+ * @default true
273
+ */
274
+ fallbackCJS?: boolean;
240
275
  };
241
276
  /**
242
277
  * Register apis globally
@@ -290,7 +325,6 @@ interface InlineConfig {
290
325
  * @default available CPUs
291
326
  */
292
327
  minThreads?: number;
293
- interpretDefault?: boolean;
294
328
  /**
295
329
  * Default timeout of a test in milliseconds
296
330
  *
@@ -389,15 +423,17 @@ interface UserConfig extends InlineConfig {
389
423
  /**
390
424
  * Run tests that cover a list of source files
391
425
  */
392
- findRelatedTests?: string[] | string;
426
+ related?: string[] | string;
393
427
  }
394
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'findRelatedTests'> {
428
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related'> {
395
429
  config?: string;
396
430
  filters?: string[];
397
431
  testNamePattern?: RegExp;
398
- findRelatedTests?: string[];
432
+ related?: string[];
399
433
  depsInline: (string | RegExp)[];
400
434
  depsExternal: (string | RegExp)[];
435
+ fallbackCJS: boolean;
436
+ interpretDefault: boolean;
401
437
  coverage: ResolvedC8Options;
402
438
  snapshotOptions: SnapshotStateOptions;
403
439
  }
@@ -452,6 +488,8 @@ declare class Vitest {
452
488
  constructor();
453
489
  setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
454
490
  start(filters?: string[]): Promise<void>;
491
+ private getTestDependencies;
492
+ filterTestsBySource(tests: string[]): Promise<string[]>;
455
493
  runFiles(files: string[]): Promise<void>;
456
494
  log(...args: any[]): void;
457
495
  error(...args: any[]): void;
package/dist/node.js CHANGED
@@ -1,20 +1,20 @@
1
- export { c as createVitest } from './index-123a18df.js';
2
- import './index-090545ef.js';
1
+ export { c as createVitest } from './index-37193236.js';
2
+ import 'fs';
3
+ import './index-9fdde2e8.js';
3
4
  import 'url';
4
5
  import 'tty';
5
6
  import 'local-pkg';
6
7
  import 'path';
7
8
  import 'vite';
8
9
  import 'process';
9
- import 'fs';
10
10
  import 'os';
11
11
  import 'util';
12
12
  import 'stream';
13
13
  import 'events';
14
- import './constants-22bbd600.js';
14
+ import './constants-8b3a9b31.js';
15
15
  import './magic-string.es-94000aea.js';
16
16
  import 'perf_hooks';
17
- import './diff-a295cb37.js';
17
+ import './diff-3adb959a.js';
18
18
  import './index-648e7ab2.js';
19
19
  import './_commonjsHelpers-c9e3b764.js';
20
20
  import 'assert';
@@ -9,11 +9,16 @@ import require$$2 from 'events';
9
9
  import require$$1 from 'https';
10
10
  import require$$2$1 from 'http';
11
11
  import require$$7 from 'url';
12
- import { A as API_PATH } from './constants-22bbd600.js';
13
- import './index-090545ef.js';
12
+ import { A as API_PATH } from './constants-8b3a9b31.js';
13
+ import { s as shouldExternalize } from './externalize-2f63779d.js';
14
+ import { o as interpretSourcePos, n as parseStacktrace } from './diff-3adb959a.js';
15
+ import './index-9fdde2e8.js';
14
16
  import 'tty';
15
17
  import 'local-pkg';
16
18
  import 'path';
19
+ import 'module';
20
+ import 'assert';
21
+ import 'util';
17
22
 
18
23
  /*! (c) 2020 Andrea Giammarchi */
19
24
 
@@ -4266,9 +4271,12 @@ function setup(ctx) {
4266
4271
  getFiles() {
4267
4272
  return ctx.state.getFiles();
4268
4273
  },
4269
- getSourceCode(id) {
4274
+ readFile(id) {
4270
4275
  return promises.readFile(id, "utf-8");
4271
4276
  },
4277
+ writeFile(id, content) {
4278
+ return promises.writeFile(id, content, "utf-8");
4279
+ },
4272
4280
  async rerun(files) {
4273
4281
  await ctx.report("onWatcherRerun", files);
4274
4282
  await ctx.runFiles(files);
@@ -4276,6 +4284,35 @@ function setup(ctx) {
4276
4284
  },
4277
4285
  getConfig() {
4278
4286
  return ctx.config;
4287
+ },
4288
+ async getModuleGraph(id) {
4289
+ const graph = {};
4290
+ function clearId(id2) {
4291
+ return (id2 == null ? void 0 : id2.replace(/\?v=\w+$/, "")) || "";
4292
+ }
4293
+ function get(mod, seen = new Set()) {
4294
+ if (!mod || !mod.id || seen.has(mod))
4295
+ return;
4296
+ seen.add(mod);
4297
+ const mods = Array.from(mod.importedModules).filter((i) => i.id && !i.id.includes("/vitest/dist/"));
4298
+ graph[clearId(mod.id)] = mods.map((i) => clearId(i.id));
4299
+ mods.forEach((m) => get(m, seen));
4300
+ }
4301
+ get(ctx.server.moduleGraph.getModuleById(id));
4302
+ const externalized = [];
4303
+ const inlined = [];
4304
+ await Promise.all(Object.keys(graph).map(async (i) => {
4305
+ const rewrote = await shouldExternalize(i, ctx.config);
4306
+ if (rewrote)
4307
+ externalized.push(rewrote);
4308
+ else
4309
+ inlined.push(i);
4310
+ }));
4311
+ return {
4312
+ graph,
4313
+ externalized,
4314
+ inlined
4315
+ };
4279
4316
  }
4280
4317
  },
4281
4318
  post(msg) {
@@ -4302,12 +4339,21 @@ class WebSocketReporter {
4302
4339
  this.clients = clients;
4303
4340
  }
4304
4341
  onCollected(files) {
4342
+ if (this.clients.size === 0)
4343
+ return;
4305
4344
  this.clients.forEach((client) => {
4306
4345
  var _a;
4307
4346
  (_a = client.onCollected) == null ? void 0 : _a.call(client, files);
4308
4347
  });
4309
4348
  }
4310
- onTaskUpdate(packs) {
4349
+ async onTaskUpdate(packs) {
4350
+ if (this.clients.size === 0)
4351
+ return;
4352
+ await Promise.all(packs.map(async (i) => {
4353
+ var _a;
4354
+ if ((_a = i[1]) == null ? void 0 : _a.error)
4355
+ await interpretSourcePos(parseStacktrace(i[1].error), this.ctx);
4356
+ }));
4311
4357
  this.clients.forEach((client) => {
4312
4358
  var _a;
4313
4359
  (_a = client.onTaskUpdate) == null ? void 0 : _a.call(client, packs);