vitest 0.0.138 → 0.0.142

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
@@ -1,4 +1,4 @@
1
- import { CommonServerOptions, ViteDevServer, UserConfig as UserConfig$1 } from 'vite';
1
+ import { ViteDevServer, TransformResult, CommonServerOptions, UserConfig as UserConfig$1, Plugin as Plugin$1 } from 'vite';
2
2
 
3
3
  interface StartOfSourceMap {
4
4
  file?: string;
@@ -13,6 +13,124 @@ interface RawSourceMap extends StartOfSourceMap {
13
13
  mappings: string;
14
14
  }
15
15
 
16
+ interface ExternalizeOptions {
17
+ external?: (string | RegExp)[];
18
+ inline?: (string | RegExp)[];
19
+ fallbackCJS?: boolean;
20
+ }
21
+ interface ViteNodeServerOptions {
22
+ deps?: ExternalizeOptions;
23
+ transformMode?: {
24
+ ssr?: RegExp[];
25
+ web?: RegExp[];
26
+ };
27
+ }
28
+
29
+ declare class ViteNodeServer {
30
+ server: ViteDevServer;
31
+ options: ViteNodeServerOptions;
32
+ promiseMap: Map<string, Promise<TransformResult | null | undefined>>;
33
+ constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
34
+ shouldExternalize(id: string): Promise<string | false>;
35
+ fetchModule(id: string): Promise<{
36
+ externalize: string;
37
+ code?: undefined;
38
+ } | {
39
+ code: string | undefined;
40
+ externalize?: undefined;
41
+ }>;
42
+ transformRequest(id: string): Promise<TransformResult | null | undefined>;
43
+ private getTransformMode;
44
+ private _transformRequest;
45
+ }
46
+
47
+ /**
48
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
49
+ *
50
+ * This source code is licensed under the MIT license found in the
51
+ * LICENSE file in the root directory of this source tree.
52
+ */
53
+ declare type Colors = {
54
+ comment: {
55
+ close: string;
56
+ open: string;
57
+ };
58
+ content: {
59
+ close: string;
60
+ open: string;
61
+ };
62
+ prop: {
63
+ close: string;
64
+ open: string;
65
+ };
66
+ tag: {
67
+ close: string;
68
+ open: string;
69
+ };
70
+ value: {
71
+ close: string;
72
+ open: string;
73
+ };
74
+ };
75
+ declare type Indent = (arg0: string) => string;
76
+ declare type Refs = Array<unknown>;
77
+ declare type Print = (arg0: unknown) => string;
78
+ declare type ThemeReceived = {
79
+ comment?: string;
80
+ content?: string;
81
+ prop?: string;
82
+ tag?: string;
83
+ value?: string;
84
+ };
85
+ declare type CompareKeys = ((a: string, b: string) => number) | undefined;
86
+ interface PrettyFormatOptions {
87
+ callToJSON?: boolean;
88
+ compareKeys?: CompareKeys;
89
+ escapeRegex?: boolean;
90
+ escapeString?: boolean;
91
+ highlight?: boolean;
92
+ indent?: number;
93
+ maxDepth?: number;
94
+ min?: boolean;
95
+ plugins?: Plugins;
96
+ printBasicPrototype?: boolean;
97
+ printFunctionName?: boolean;
98
+ theme?: ThemeReceived;
99
+ }
100
+ declare type OptionsReceived = PrettyFormatOptions;
101
+ declare type Config = {
102
+ callToJSON: boolean;
103
+ compareKeys: CompareKeys;
104
+ colors: Colors;
105
+ escapeRegex: boolean;
106
+ escapeString: boolean;
107
+ indent: string;
108
+ maxDepth: number;
109
+ min: boolean;
110
+ plugins: Plugins;
111
+ printBasicPrototype: boolean;
112
+ printFunctionName: boolean;
113
+ spacingInner: string;
114
+ spacingOuter: string;
115
+ };
116
+ declare type Printer = (val: unknown, config: Config, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
117
+ declare type Test$1 = (arg0: any) => boolean;
118
+ declare type NewPlugin = {
119
+ serialize: (val: any, config: Config, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
120
+ test: Test$1;
121
+ };
122
+ declare type PluginOptions = {
123
+ edgeSpacing: string;
124
+ min: boolean;
125
+ spacing: string;
126
+ };
127
+ declare type OldPlugin = {
128
+ print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
129
+ test: Test$1;
130
+ };
131
+ declare type Plugin = NewPlugin | OldPlugin;
132
+ declare type Plugins = Array<Plugin>;
133
+
16
134
  declare abstract class BaseReporter implements Reporter {
17
135
  start: number;
18
136
  end: number;
@@ -64,6 +182,14 @@ declare class DotReporter extends BaseReporter {
64
182
  onUserConsoleLog(log: UserConsoleLog): void;
65
183
  }
66
184
 
185
+ declare class JsonReporter implements Reporter {
186
+ start: number;
187
+ ctx: Vitest;
188
+ onInit(ctx: Vitest): void;
189
+ protected logTasks(files: File[]): void;
190
+ onFinished(files?: File[]): Promise<void>;
191
+ }
192
+
67
193
  declare class VerboseReporter extends DefaultReporter {
68
194
  constructor();
69
195
  }
@@ -84,6 +210,7 @@ declare const ReportersMap: {
84
210
  default: typeof DefaultReporter;
85
211
  verbose: typeof VerboseReporter;
86
212
  dot: typeof DotReporter;
213
+ json: typeof JsonReporter;
87
214
  tap: typeof TapReporter;
88
215
  'tap-flat': typeof TapFlatReporter;
89
216
  };
@@ -226,6 +353,7 @@ interface UserConsoleLog {
226
353
  content: string;
227
354
  type: 'stdout' | 'stderr';
228
355
  taskId?: string;
356
+ time: number;
229
357
  }
230
358
  interface Position {
231
359
  line: number;
@@ -260,6 +388,7 @@ interface TaskBase {
260
388
  suite?: Suite;
261
389
  file?: File;
262
390
  result?: TaskResult;
391
+ logs?: UserConsoleLog[];
263
392
  }
264
393
  interface TaskResult {
265
394
  state: TaskState;
@@ -275,13 +404,13 @@ interface File extends Suite {
275
404
  filepath: string;
276
405
  collectDuration?: number;
277
406
  }
278
- interface Test$1 extends TaskBase {
407
+ interface Test extends TaskBase {
279
408
  type: 'test';
280
409
  suite: Suite;
281
410
  result?: TaskResult;
282
411
  fails?: boolean;
283
412
  }
284
- declare type Task = Test$1 | Suite | File;
413
+ declare type Task = Test | Suite | File;
285
414
 
286
415
  interface Reporter {
287
416
  onInit?(ctx: Vitest): void;
@@ -294,99 +423,12 @@ interface Reporter {
294
423
  onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
295
424
  }
296
425
 
297
- /**
298
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
299
- *
300
- * This source code is licensed under the MIT license found in the
301
- * LICENSE file in the root directory of this source tree.
302
- */
303
- declare type Colors = {
304
- comment: {
305
- close: string;
306
- open: string;
307
- };
308
- content: {
309
- close: string;
310
- open: string;
311
- };
312
- prop: {
313
- close: string;
314
- open: string;
315
- };
316
- tag: {
317
- close: string;
318
- open: string;
319
- };
320
- value: {
321
- close: string;
322
- open: string;
323
- };
324
- };
325
- declare type Indent = (arg0: string) => string;
326
- declare type Refs = Array<unknown>;
327
- declare type Print = (arg0: unknown) => string;
328
- declare type ThemeReceived = {
329
- comment?: string;
330
- content?: string;
331
- prop?: string;
332
- tag?: string;
333
- value?: string;
334
- };
335
- declare type CompareKeys = ((a: string, b: string) => number) | undefined;
336
- interface PrettyFormatOptions {
337
- callToJSON?: boolean;
338
- compareKeys?: CompareKeys;
339
- escapeRegex?: boolean;
340
- escapeString?: boolean;
341
- highlight?: boolean;
342
- indent?: number;
343
- maxDepth?: number;
344
- min?: boolean;
345
- plugins?: Plugins;
346
- printBasicPrototype?: boolean;
347
- printFunctionName?: boolean;
348
- theme?: ThemeReceived;
349
- }
350
- declare type OptionsReceived = PrettyFormatOptions;
351
- declare type Config = {
352
- callToJSON: boolean;
353
- compareKeys: CompareKeys;
354
- colors: Colors;
355
- escapeRegex: boolean;
356
- escapeString: boolean;
357
- indent: string;
358
- maxDepth: number;
359
- min: boolean;
360
- plugins: Plugins;
361
- printBasicPrototype: boolean;
362
- printFunctionName: boolean;
363
- spacingInner: string;
364
- spacingOuter: string;
365
- };
366
- declare type Printer = (val: unknown, config: Config, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
367
- declare type Test = (arg0: any) => boolean;
368
- declare type NewPlugin = {
369
- serialize: (val: any, config: Config, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
370
- test: Test;
371
- };
372
- declare type PluginOptions = {
373
- edgeSpacing: string;
374
- min: boolean;
375
- spacing: string;
376
- };
377
- declare type OldPlugin = {
378
- print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
379
- test: Test;
380
- };
381
- declare type Plugin = NewPlugin | OldPlugin;
382
- declare type Plugins = Array<Plugin>;
383
-
384
426
  declare type SnapshotUpdateState = 'all' | 'new' | 'none';
385
- declare type SnapshotStateOptions = {
427
+ interface SnapshotStateOptions {
386
428
  updateSnapshot: SnapshotUpdateState;
387
429
  expand?: boolean;
388
430
  snapshotFormat?: OptionsReceived;
389
- };
431
+ }
390
432
  interface SnapshotResult {
391
433
  filepath: string;
392
434
  added: number;
@@ -553,6 +595,10 @@ interface InlineConfig {
553
595
  * Path to setup files
554
596
  */
555
597
  setupFiles?: string | string[];
598
+ /**
599
+ * Path to global setup files
600
+ */
601
+ globalSetup?: string | string[];
556
602
  /**
557
603
  * Pattern of file paths to be ignore from triggering watch rerun
558
604
  *
@@ -607,6 +653,30 @@ interface InlineConfig {
607
653
  * @default '/__vitest__/'
608
654
  */
609
655
  uiBase?: string;
656
+ /**
657
+ * Determine the transform method of modules
658
+ */
659
+ transformMode?: {
660
+ /**
661
+ * Use SSR transform pipeline for the specified files.
662
+ * Vite plugins will receive `ssr: true` flag when processing those files.
663
+ *
664
+ * @default [/\.([cm]?[jt]sx?|json)$/]
665
+ */
666
+ ssr?: RegExp[];
667
+ /**
668
+ * First do a normal transform pipeline (targeting browser),
669
+ * then then do a SSR rewrite to run the code in Node.
670
+ * Vite plugins will receive `ssr: false` flag when processing those files.
671
+ *
672
+ * @default other than `ssr`
673
+ */
674
+ web?: RegExp[];
675
+ };
676
+ /**
677
+ * Format options for snapshot testing.
678
+ */
679
+ snapshotFormat?: PrettyFormatOptions;
610
680
  }
611
681
  interface UserConfig extends InlineConfig {
612
682
  /**
@@ -642,10 +712,6 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
642
712
  filters?: string[];
643
713
  testNamePattern?: RegExp;
644
714
  related?: string[];
645
- depsInline: (string | RegExp)[];
646
- depsExternal: (string | RegExp)[];
647
- fallbackCJS: boolean;
648
- interpretDefault: boolean;
649
715
  coverage: ResolvedC8Options;
650
716
  snapshotOptions: SnapshotStateOptions;
651
717
  api?: ApiConfig;
@@ -674,6 +740,7 @@ declare class StateManager {
674
740
  collectFiles(files?: File[]): void;
675
741
  updateId(task: Task): void;
676
742
  updateTasks(packs: TaskResultPack[]): void;
743
+ updateUserLog(log: UserConsoleLog): void;
677
744
  }
678
745
 
679
746
  declare class Vitest {
@@ -690,12 +757,12 @@ declare class Vitest {
690
757
  errorStream: NodeJS.WriteStream & {
691
758
  fd: 2;
692
759
  };
760
+ vitenode: ViteNodeServer;
693
761
  invalidates: Set<string>;
694
762
  changedTests: Set<string>;
695
763
  visitedFilesMap: Map<string, RawSourceMap>;
696
764
  runningPromise?: Promise<void>;
697
765
  closingPromise?: Promise<void>;
698
- externalizeCache: Map<string, Promise<string | false>>;
699
766
  isFirstRun: boolean;
700
767
  restartsCount: number;
701
768
  private _onRestartListeners;
@@ -716,10 +783,10 @@ declare class Vitest {
716
783
  report<T extends keyof Reporter>(name: T, ...args: ArgumentsType<Reporter[T]>): Promise<void>;
717
784
  globTestFiles(filters?: string[]): Promise<string[]>;
718
785
  isTargetFile(id: string): boolean;
719
- shouldExternalize(id: string): Promise<string | false>;
720
786
  onServerRestarted(fn: () => void): void;
721
787
  }
722
788
 
789
+ declare function VitestPlugin(options?: UserConfig, viteOverrides?: UserConfig$1, ctx?: Vitest): Promise<Plugin$1[]>;
723
790
  declare function createVitest(options: UserConfig, viteOverrides?: UserConfig$1): Promise<Vitest>;
724
791
 
725
- export { Vitest, createVitest };
792
+ export { Vitest, VitestPlugin, createVitest };
package/dist/node.js CHANGED
@@ -1,9 +1,6 @@
1
- export { c as createVitest } from './index-a6ee95c8.js';
1
+ export { V as VitestPlugin, c as createVitest } from './index-fdf40e86.js';
2
2
  import 'fs';
3
- import './index-64aafe4b.js';
4
- import 'url';
5
- import 'tty';
6
- import 'local-pkg';
3
+ import './index-1b2eb03b.js';
7
4
  import 'path';
8
5
  import 'vite';
9
6
  import 'process';
@@ -11,15 +8,19 @@ import 'os';
11
8
  import 'util';
12
9
  import 'stream';
13
10
  import 'events';
14
- import './constants-d24b670d.js';
11
+ import './index-1bb8e174.js';
12
+ import 'tty';
13
+ import 'local-pkg';
14
+ import './index-163994a5.js';
15
+ import 'module';
16
+ import 'url';
17
+ import 'assert';
18
+ import './constants-124522a1.js';
15
19
  import './magic-string.es-94000aea.js';
16
20
  import 'perf_hooks';
17
- import './diff-5dfc7eb4.js';
21
+ import './diff-f7af3876.js';
18
22
  import './index-648e7ab2.js';
19
23
  import './_commonjsHelpers-c9e3b764.js';
20
- import 'assert';
21
- import 'module';
22
- import './index-5d6a5929.js';
23
24
  import 'worker_threads';
24
25
  import 'tinypool';
25
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZS5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
26
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZS5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==