@provino/dialect-vitest 0.0.0-stage → 0.1.0-rc.0

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/index.js ADDED
@@ -0,0 +1,389 @@
1
+ import { t as VITEST_EACH_TITLE_TRUNCATE } from "./title-truncate.js";
2
+ import { defineDialect, moduleRef } from "@provino/policy";
3
+
4
+ // src/hoist-policy.ts
5
+ /**
6
+ * Vitest 5.0's mock-hoisting policy.
7
+ * @public
8
+ */
9
+ const vitestHoistPolicy = {
10
+ id: "vitest-5.0",
11
+ objects: [{
12
+ kind: "name",
13
+ name: "vi"
14
+ }, {
15
+ kind: "name",
16
+ name: "vitest"
17
+ }],
18
+ hoistCalls: {
19
+ mock: "any",
20
+ unmock: "any"
21
+ },
22
+ hoistValues: ["hoisted"],
23
+ rewriteImportArg: [
24
+ "mock",
25
+ "unmock",
26
+ "doMock",
27
+ "doUnmock"
28
+ ],
29
+ chainable: false,
30
+ placement: "top-level-only",
31
+ topLevelGuards: ["import.meta.vitest"],
32
+ factoryReferences: "allow",
33
+ runnerModules: ["vitest", "vite-plus/test"],
34
+ reExports: "static",
35
+ rewrittenCalls: "member",
36
+ messages: {
37
+ HOIST_FACTORY_OUT_OF_SCOPE: "",
38
+ HOIST_FACTORY_NOT_FUNCTION: "",
39
+ HOIST_NOT_TOP_LEVEL: "{call} was defined outside of the module's top level scope. Although it appears nested, it will be hoisted and executed before anything in this file. Move it to the top level to reflect its actual execution order.\nSee: https://vitest.dev/guide/mocking/modules#how-it-works",
40
+ HOIST_NESTED: "Cannot call {call} inside {name}: both methods are hoisted to the top of the file and not actually called inside each other.",
41
+ HOIST_EXPORTED: "Cannot export the result of \"{call}\". Remove export declaration because \"{call}\" doesn't return anything.",
42
+ HOIST_EXPORTED_VALUE: "Cannot export hoisted variable. You can control hoisting behavior by placing the import from this file first."
43
+ }
44
+ };
45
+
46
+ // src/mock-policy.ts
47
+ /**
48
+ * Vitest 5.0's `mock` slice.
49
+ * @public
50
+ */
51
+ const vitestMockPolicy = {
52
+ resetTo: "original-impl",
53
+ defaultName: "vi.fn()",
54
+ between: {
55
+ order: [
56
+ "restore",
57
+ "reset",
58
+ "clear",
59
+ "unstubEnvs",
60
+ "unstubGlobals"
61
+ ],
62
+ clear: true,
63
+ reset: false,
64
+ restore: false,
65
+ unstubEnvs: false,
66
+ unstubGlobals: false
67
+ },
68
+ classMockPrototype: "chain-to-impl",
69
+ spyNameFromMethod: true,
70
+ functionName: "impl-or-Mock",
71
+ newCall: "construct",
72
+ valueShorthandsThrowOnNew: true,
73
+ fnOfMockReturnsSame: true,
74
+ copyStaticProps: true,
75
+ settledResults: true,
76
+ lastCallKey: "always",
77
+ clearReplacesStateObject: false,
78
+ mockPropertyWritable: false,
79
+ withImplementationReturnsMock: true,
80
+ getImplPrefersOnce: true,
81
+ spyReportsBridgeImpl: false,
82
+ isMockAcceptsObjects: false,
83
+ spyInstall: "define",
84
+ messages: {
85
+ "spy-nullish": "The vi.spyOn() function could not find an object to spy upon. The first argument must be defined.",
86
+ "spy-define-primitive": "Vitest cannot spy on a primitive value.",
87
+ "spy-define-missing": "The property \"{key}\" is not defined on the {type}.",
88
+ "spy-define-not-a-function": "vi.spyOn() can only spy on a function. Received {type}.",
89
+ "spy-namespace": "Cannot spy on export \"{key}\". Module namespace is not configurable in ESM. See: https://vitest.dev/guide/mocking/modules#mocking-a-module",
90
+ "new-shorthand": "Cannot use `{name}` when called with `new`. Use `mockImplementation` with a `class` keyword instead. See https://vitest.dev/api/mock#class-support for more information.",
91
+ "new-not-a-constructor": "[vitest] The {name} mock did not use 'function' or 'class' in its implementation, see https://vitest.dev/api/vi#vi-spyon for examples."
92
+ }
93
+ };
94
+ /**
95
+ * Vitest 5.0's `module` slice. The texts are copied from `.refs/vitest` (v5.0.5); the two with
96
+ * `{raw}` carry the specifier as written.
97
+ * @public
98
+ */
99
+ const vitestModulePolicy = {
100
+ factoryShape: "namespace",
101
+ rootMocksAutoApply: false,
102
+ automock: false,
103
+ actual: "async-import",
104
+ resetModulesBetween: false,
105
+ injectCjsGlobals: true,
106
+ interopDefault: "node",
107
+ resetModulesClearsMocks: false,
108
+ awaitFactory: true,
109
+ missingFactoryExport: "throw",
110
+ requireVirtualFlag: false,
111
+ virtualRelative: false,
112
+ mockValueOwner: "registration",
113
+ mockResolveKind: "import",
114
+ edgeResolveKind: "as-written",
115
+ moduleSyncCondition: "never",
116
+ mocksReachShared: false,
117
+ reevaluateHookingExternals: false,
118
+ reevaluatePatchingExternals: false,
119
+ stackFrameNames: "engine",
120
+ nativeLoadPatches: "apply",
121
+ automockShape: "deep",
122
+ unmockedPathPatterns: [],
123
+ messages: {
124
+ "factory-not-object": "[vitest] vi.mock(\"{raw}\", factory?: () => unknown) is not returning an object. Did you mean to return an object with a \"default\" key?",
125
+ "missing-factory-export": "[vitest] No \"{name}\" export is defined on the \"{raw}\" mock. Did you forget to return it from \"vi.mock\"?\nIf you need to partially mock a module, you can use \"importOriginal\" helper inside:\n",
126
+ "unresolved-relative-mock": "Cannot find module '{id}'",
127
+ "unresolved-mock-import": "{message} imported from {importer}",
128
+ "factory-error": "[vitest] There was an error when mocking a module. If you are using \"vi.mock\" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock"
129
+ },
130
+ mapperMiss: null
131
+ };
132
+
133
+ // src/dialect.ts
134
+ /**
135
+ * Vitest 5.0's policy (with `sequence.hooks: 'stack'`, its default), layered over the neutral
136
+ * policy by `resolvePolicy`. This is `vitestDialect.policy`, typed as the overrides it is.
137
+ * @public
138
+ */
139
+ const vitestPolicy = {
140
+ core: {
141
+ hookOrder: {
142
+ beforeAll: "declaration",
143
+ beforeEach: "declaration",
144
+ afterEach: "reverse",
145
+ afterAll: "reverse"
146
+ },
147
+ eachHooksForConcurrent: true,
148
+ firstArg: "context",
149
+ allowGeneratorFns: false,
150
+ timeouts: {
151
+ test: 5e3,
152
+ hook: 1e4,
153
+ teardown: 1e4,
154
+ catchSyncOverrun: true,
155
+ zero: "none"
156
+ },
157
+ nameSeparator: " > ",
158
+ testNamePatternFlags: "",
159
+ missingTestFn: "todo",
160
+ asyncDescribe: "await",
161
+ nonPromiseReturn: "ignore",
162
+ formatEachTitle: moduleRef(import.meta.resolve("@provino/dialect-vitest/runtime"), "formatEachTitle"),
163
+ eachTitleTruncate: 40,
164
+ retry: {
165
+ timing: "immediate",
166
+ keepEarlierErrors: true,
167
+ functionCondition: "ignore-warn",
168
+ functionConditionWarning: "Vitest 5.0 never calls a function condition and retries every failure, and so does this mode, so the outcome of a suite that passes there does not change. Pass a RegExp (tested against the error message) to limit the retries, or use the neutral mode, which calls the function."
169
+ },
170
+ allowOnly: "not-in-ci",
171
+ maxConcurrency: 5,
172
+ unawaitedAsyncAssertion: "fail",
173
+ hookReturnsCleanup: true,
174
+ injectGlobals: false,
175
+ globalsBeforeSetupFiles: "all",
176
+ doneDeprecatedMessage: "done() callback is deprecated, use promise instead",
177
+ collect: {
178
+ describeBody: "deferred",
179
+ describeReturnValue: "ignore",
180
+ lateRegistration: "warn-drop",
181
+ emptyDescribe: "fail-suite",
182
+ nestedInTest: "throw",
183
+ todoWithFn: "todo",
184
+ eachTableError: "lenient"
185
+ },
186
+ hooks: {
187
+ afterError: "abort-chain",
188
+ beforeAllError: "skip-subtree",
189
+ nestedHooksAfterBeforeAllError: "skip",
190
+ afterAllError: "fail-suite",
191
+ timeoutCountsTestTimeout: false,
192
+ skippedBlock: "none"
193
+ },
194
+ concurrency: {
195
+ grouping: "consecutive",
196
+ limitHooks: true
197
+ },
198
+ errors: {
199
+ lateErrors: "report-run",
200
+ processListeners: "alongside",
201
+ waitForUnhandledRejections: false,
202
+ hasAssertionsWhenFailed: "skip"
203
+ },
204
+ focus: {
205
+ scope: "suite",
206
+ insideSkip: "skipped"
207
+ },
208
+ status: {
209
+ todoUnderSkip: "todo",
210
+ expectFail: "attempt"
211
+ },
212
+ locationFrame: "test-file"
213
+ },
214
+ lazy: { readInBeforeAll: "error" },
215
+ mock: vitestMockPolicy,
216
+ timers: {
217
+ toFakeDefault: "all-but-microtasks",
218
+ loopLimit: 1e4,
219
+ fakeTemporal: true,
220
+ legacyAvailable: false,
221
+ enableGlobally: false,
222
+ optionNames: "to-fake",
223
+ notFaked: "throw",
224
+ setSystemTimeWithoutFakes: "fake-date-only",
225
+ advanceToNextTimerHonorsSteps: false,
226
+ facadeReturns: "all",
227
+ messages: { notFaked: "A function to advance timers was called but the timers APIs are not mocked. Call `vi.useFakeTimers()` in the test file first." }
228
+ },
229
+ module: vitestModulePolicy,
230
+ snapshot: {
231
+ header: "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html",
232
+ keyJoin: " > ",
233
+ hintJoin: " > ",
234
+ dirName: "__snapshots__",
235
+ extension: ".snap",
236
+ format: {
237
+ escapeString: false,
238
+ printBasicPrototype: false,
239
+ maxOutputLength: 2 ** 27,
240
+ extra: {}
241
+ },
242
+ obsolete: {
243
+ failLocal: false,
244
+ failCI: true
245
+ },
246
+ ciUpdate: "none",
247
+ updateEnvVar: "UPDATE_SNAPSHOT",
248
+ throwErrorBody: "error",
249
+ inline: {
250
+ indent: "call",
251
+ formatter: "none",
252
+ writer: null,
253
+ prettierPath: null
254
+ },
255
+ resolverFactory: null,
256
+ contextView: null,
257
+ printer: moduleRef(import.meta.resolve("@provino/dialect-vitest/runtime"), "vitestSnapshotPrinter")
258
+ },
259
+ expect: {
260
+ matcherNamespace: "vitest",
261
+ outsideTestCounts: "drop",
262
+ pollFailsOnTimeout: true,
263
+ diffContextLines: 5,
264
+ valueFormatter: "pretty-format",
265
+ errorShape: "assertion-error",
266
+ equality: {
267
+ errors: "assert",
268
+ invalidDate: "equal"
269
+ },
270
+ soft: true,
271
+ poll: {
272
+ enabled: true,
273
+ intervalMs: 50,
274
+ timeoutMs: 1e3
275
+ },
276
+ requireAssertions: false,
277
+ expand: false
278
+ },
279
+ orchestrator: {
280
+ include: ["**/*.{test,spec}.?(c|m)[jt]s?(x)"],
281
+ exclude: ["**/node_modules/**", "**/.git/**"],
282
+ bail: { checkAfter: "test" },
283
+ watchDefault: "tty-not-ci",
284
+ watch: { initialRun: "all" },
285
+ environmentConditions: moduleRef(import.meta.resolve("@provino/dialect-vitest/runtime"), "vitestEnvironmentConditions"),
286
+ globMatchesOn: "root-relative-path",
287
+ todoOnlyFile: "skip",
288
+ noTestsFile: "fail-unless-pass-with-no-tests",
289
+ consoleOrigin: "none",
290
+ processObject: "shared",
291
+ passWithNoTests: false,
292
+ exitCodes: {
293
+ failure: 1,
294
+ noTests: 1,
295
+ unhandled: 1,
296
+ usage: 1
297
+ },
298
+ unhandledErrors: "fail-run",
299
+ coverageProvider: "v8",
300
+ coverageReporters: [
301
+ "text",
302
+ "html",
303
+ "clover",
304
+ "json"
305
+ ],
306
+ slowTestThresholdMs: 300,
307
+ isolationDefault: { default: "registry" },
308
+ envDefault: "node",
309
+ environmentPragmas: ["vitest-environment", "jest-environment"],
310
+ pool: { default: "forks" },
311
+ inBand: {
312
+ single: false,
313
+ fastFileCount: 0,
314
+ slowMs: 0
315
+ },
316
+ shard: { fallback: "sha1-slice" },
317
+ sequence: { unknownFirst: true },
318
+ globalSetup: {
319
+ signature: "project-with-teardown",
320
+ teardownOrder: "reverse"
321
+ }
322
+ },
323
+ report: {
324
+ displaySeparator: " > ",
325
+ defaultReporters: ["default"],
326
+ failureTitleBullet: null,
327
+ listTestsForSingleFile: false,
328
+ resultStatusSkipped: "skipped"
329
+ },
330
+ coverage: {
331
+ thresholdGrouping: "all-files",
332
+ globThresholdScope: "aggregate",
333
+ includeUntestedByDefault: true,
334
+ reportsDirectory: "./coverage",
335
+ v8Conversion: "ast",
336
+ v8HitCounts: false,
337
+ v8Hashbang: "kept",
338
+ istanbulVariable: "__coverage__",
339
+ thresholdMessages: {
340
+ belowMinimum: "Coverage for {metric} ({actual}%) does not meet \"{name}\" threshold ({threshold}%)",
341
+ aboveMaximumUncovered: "Uncovered count for {metric} ({actual}) exceeds {name} threshold ({threshold})",
342
+ notFound: "Coverage data for {path} was not found."
343
+ }
344
+ }
345
+ };
346
+ /**
347
+ * The globals Vitest 5.0 injects with `globals: true` (`vitest/src/constants.ts`'s `globalApis`,
348
+ * which `integrations/globals.ts` installs), sorted. `core-globals-at-setup` records them.
349
+ */
350
+ const VITEST_GLOBAL_NAMES = [
351
+ "afterAll",
352
+ "afterEach",
353
+ "aroundAll",
354
+ "aroundEach",
355
+ "assert",
356
+ "assertType",
357
+ "beforeAll",
358
+ "beforeEach",
359
+ "chai",
360
+ "describe",
361
+ "expect",
362
+ "expectTypeOf",
363
+ "it",
364
+ "onTestFailed",
365
+ "onTestFinished",
366
+ "suite",
367
+ "test",
368
+ "vi",
369
+ "vitest"
370
+ ];
371
+ /**
372
+ * The Vitest 5.0 dialect: its policy values, the globals it injects and its type entries. The
373
+ * config reader, the CLI flags and the `vitest` facade come with T11.15 and T11.16 (Phase 2); until
374
+ * then the globals factory is a stub that throws.
375
+ * @public
376
+ */
377
+ const vitestDialect = defineDialect({
378
+ name: "vitest",
379
+ version: "5.0",
380
+ policy: vitestPolicy,
381
+ globals: {
382
+ factory: moduleRef(import.meta.resolve("@provino/dialect-vitest/runtime"), "vitestGlobals"),
383
+ names: VITEST_GLOBAL_NAMES
384
+ },
385
+ loader: { hoist: vitestHoistPolicy },
386
+ typeEntries: ["@provino/dialect-vitest/runtime"]
387
+ });
388
+
389
+ export { VITEST_EACH_TITLE_TRUNCATE, vitestDialect, vitestHoistPolicy, vitestMockPolicy, vitestModulePolicy, vitestPolicy };
@@ -0,0 +1,7 @@
1
+ import { Dialect } from "@provino/types";
2
+ /**
3
+ * The Vitest dialect as the coordinator sees it. Today it is `vitestDialect` itself: no config
4
+ * reader and no flags yet.
5
+ * @public
6
+ */
7
+ export declare const vitestNodeDialect: Dialect<"vitest">;
@@ -0,0 +1,11 @@
1
+ import { vitestDialect } from "@provino/dialect-vitest";
2
+
3
+ // src/node/index.ts
4
+ /**
5
+ * The Vitest dialect as the coordinator sees it. Today it is `vitestDialect` itself: no config
6
+ * reader and no flags yet.
7
+ * @public
8
+ */
9
+ const vitestNodeDialect = vitestDialect;
10
+
11
+ export { vitestNodeDialect };
@@ -0,0 +1,41 @@
1
+ import { EnvironmentConditions, FormatEachTitle, GlobalsHost, SnapshotPrinter } from "@provino/types";
2
+ /**
3
+ * Formats a `.each` or `.for` title as Vitest 5.0.5 does: `%s %d %i %f %j %o %O %c %%` through
4
+ * its `format`, `%#` and `%$` for the row's index and number, `$name`, `$a.b` and `$0` for an
5
+ * object row's keys or the row's items, and each value cut to 40 characters. `%p` is not a token.
6
+ * @public
7
+ */
8
+ export declare const formatEachTitle: FormatEachTitle;
9
+ /**
10
+ * The resolver export conditions of a Vitest environment (`orchestrator.environmentConditions`).
11
+ * Vitest resolves a test file's imports on the server side whatever the environment, so under
12
+ * `environment: 'jsdom'` a package's `browser` variant is not picked and its `node` one is
13
+ * (recorded: `env/conditions-vitest-jsdom`, Vitest 5.0.5). An environment's own list wins.
14
+ * @public
15
+ */
16
+ export declare const vitestEnvironmentConditions: EnvironmentConditions;
17
+ /**
18
+ * The Vitest dialect's snapshot printer: what `vitestPolicy.snapshot.printer` loads. The worker
19
+ * builds it once.
20
+ * @public
21
+ */
22
+ export declare function vitestSnapshotPrinter(): SnapshotPrinter;
23
+ /**
24
+ * The code a `VitestDialectError` carries.
25
+ * @public
26
+ */
27
+ export type VitestDialectErrorCode = "VITEST_DIALECT_NOT_BUILT";
28
+ /**
29
+ * An error from the Vitest dialect.
30
+ * @public
31
+ */
32
+ export declare class VitestDialectError extends Error {
33
+ override readonly name = "VitestDialectError";
34
+ readonly code: VitestDialectErrorCode;
35
+ constructor(code: VitestDialectErrorCode, message: string);
36
+ }
37
+ /**
38
+ * The Vitest dialect's globals factory. Not built yet: it throws `VITEST_DIALECT_NOT_BUILT`.
39
+ * @public
40
+ */
41
+ export declare function vitestGlobals(_host: GlobalsHost): Readonly<Record<string, unknown>>;