@testforgejs/vue-test-core 1.0.0-beta.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.cjs ADDED
@@ -0,0 +1,864 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Types: () => Types,
24
+ captureInstance: () => captureInstance,
25
+ createPluginInstance: () => createPluginInstance,
26
+ createTestFramework: () => createTestFramework,
27
+ createVuePlugin: () => createVuePlugin,
28
+ validatePreset: () => validatePreset,
29
+ validatePresets: () => validatePresets
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // src/utils/mergeComponentData.ts
34
+ function mergeComponentData({
35
+ defaultMountData = {},
36
+ defaultData = {},
37
+ mountData = {},
38
+ directData = {},
39
+ skipDefault = false,
40
+ skipOptions = false
41
+ }) {
42
+ const level1 = skipDefault ? {} : {
43
+ ...!skipOptions ? defaultMountData : {},
44
+ ...defaultData
45
+ };
46
+ const level2 = {
47
+ ...mountData,
48
+ ...directData
49
+ };
50
+ return { ...level1, ...level2 };
51
+ }
52
+
53
+ // src/constants/constants.ts
54
+ var FRAMEWORK_NAME = "TestForge";
55
+ var ERROR_PREFIX = `[${FRAMEWORK_NAME}]`;
56
+ var DEFAULT_PRESET_NAME = "default";
57
+
58
+ // src/validators/validatePreset.ts
59
+ function validatePreset(name, preset) {
60
+ if (!preset) {
61
+ throw new Error(`${ERROR_PREFIX} Preset "${name}" is null or undefined.`);
62
+ }
63
+ if (!Array.isArray(preset.manifest)) {
64
+ throw new Error(`${ERROR_PREFIX} Preset "${name}" must have a "manifest" array.`);
65
+ }
66
+ const manifestPluginNames = /* @__PURE__ */ new Set();
67
+ preset.manifest.forEach((entry, index) => {
68
+ const { module: module2, enabled } = entry;
69
+ if (!module2 || typeof module2.getName !== "function") {
70
+ throw new Error(`${ERROR_PREFIX} Invalid module at manifest[${index}] in preset "${name}".`);
71
+ }
72
+ const pluginName = module2.getName();
73
+ if (manifestPluginNames.has(pluginName)) {
74
+ throw new Error(
75
+ `${ERROR_PREFIX} Duplicate plugin "${pluginName}" in manifest of preset "${name}".`
76
+ );
77
+ }
78
+ if (typeof enabled !== "boolean") {
79
+ throw new Error(
80
+ `${ERROR_PREFIX} Plugin "${pluginName}" in preset "${name}" must have a boolean "enabled" flag.`
81
+ );
82
+ }
83
+ manifestPluginNames.add(pluginName);
84
+ });
85
+ if (preset.defaults) {
86
+ const defaultKeys = Object.keys(preset.defaults);
87
+ defaultKeys.forEach((key) => {
88
+ if (!manifestPluginNames.has(key)) {
89
+ throw new Error(
90
+ `${ERROR_PREFIX} Preset "${name}" contains defaults for unknown plugin "${key}". This plugin is not present in the manifest.`
91
+ );
92
+ }
93
+ const value = preset.defaults[key];
94
+ const isObject = value !== null && typeof value === "object" && !Array.isArray(value);
95
+ if (!isObject) {
96
+ throw new Error(
97
+ `${ERROR_PREFIX} Invalid default configuration for plugin "${key}" in preset "${name}". Expected Object, but received ${typeof value}.`
98
+ );
99
+ }
100
+ });
101
+ }
102
+ }
103
+
104
+ // src/utils/getActivePreset.ts
105
+ function getActivePreset(presets = {}, extraOptions) {
106
+ const requestedPresetName = extraOptions?.preset?.trim();
107
+ const activeName = requestedPresetName || DEFAULT_PRESET_NAME;
108
+ const preset = presets[activeName];
109
+ if (requestedPresetName && !preset) {
110
+ throw new Error(
111
+ `[withPreset] Requested preset "${requestedPresetName}" not found in available presets.`
112
+ );
113
+ }
114
+ if (preset) {
115
+ validatePreset(activeName, preset);
116
+ }
117
+ return preset;
118
+ }
119
+
120
+ // src/utils/getPresetManifest.ts
121
+ function getPresetManifest(preset) {
122
+ return preset?.manifest ?? [];
123
+ }
124
+
125
+ // src/utils/createSupportedPluginsState.ts
126
+ function createSupportedPluginsState(preset) {
127
+ const map = {};
128
+ for (const { module: module2, enabled } of getPresetManifest(preset)) {
129
+ if (typeof enabled !== "boolean") {
130
+ throw new Error(
131
+ `[TestForge] Plugin "${module2.getName()}" has invalid "enabled" value: ${String(enabled)}. Expected boolean.`
132
+ );
133
+ }
134
+ map[module2.getName()] = enabled;
135
+ }
136
+ return map;
137
+ }
138
+
139
+ // src/pipeline/core/createPipelineContext.ts
140
+ function createPipelineContext(params) {
141
+ const { defaultMountOptions = {}, mountOptions = {}, extraOptions = {}, presets = {} } = params;
142
+ const activePreset = getActivePreset(presets, extraOptions);
143
+ const supportedPlugins = createSupportedPluginsState(activePreset);
144
+ return {
145
+ defaultMountOptions,
146
+ mountOptions,
147
+ extraOptions,
148
+ supportedPlugins,
149
+ preset: activePreset,
150
+ result: {
151
+ mountOptions: {},
152
+ global: {},
153
+ pluginDefaultsState: {},
154
+ plugins: {}
155
+ }
156
+ };
157
+ }
158
+
159
+ // src/pipeline/core/runPipeline.ts
160
+ function runPipeline(ctx, middlewares) {
161
+ let context = ctx;
162
+ for (const middleware of middlewares) {
163
+ const result = middleware(context);
164
+ if (result) {
165
+ context = result;
166
+ }
167
+ }
168
+ return context;
169
+ }
170
+
171
+ // src/pipeline/core/createPipeline.ts
172
+ function createPipeline(middlewares) {
173
+ return {
174
+ /*
175
+ * Runs the middleware chain sequentially.
176
+ */
177
+ run(ctx) {
178
+ return runPipeline(ctx, middlewares);
179
+ }
180
+ };
181
+ }
182
+
183
+ // src/pipeline/middleware/typeGuards/assertIsObject.ts
184
+ function assertIsObject(val, name) {
185
+ if (val !== null && typeof val === "object" && !Array.isArray(val)) return;
186
+ throw new Error(
187
+ `${ERROR_PREFIX} Critical error: "${name}" must be an Object. Received ${Array.isArray(val) ? "array" : typeof val} (${val}).`
188
+ );
189
+ }
190
+
191
+ // src/pipeline/middleware/validation/assertConfigurationShape.ts
192
+ var assertConfigurationShape = (ctx) => {
193
+ assertIsObject(ctx.defaultMountOptions, "defaultMountOptions");
194
+ assertIsObject(ctx.mountOptions, "mountOptions");
195
+ assertIsObject(ctx.extraOptions, "extraOptions");
196
+ return ctx;
197
+ };
198
+
199
+ // src/pipeline/plugins/logic/resolveExtraOptions.ts
200
+ function resolveExtraOptions(extraOptions) {
201
+ return extraOptions;
202
+ }
203
+
204
+ // src/pipeline/middleware/validation/validators/assertUnsupportedPlugins.ts
205
+ var assertUnsupportedPlugins = (plugins, supported) => {
206
+ for (const name of Object.keys(plugins)) {
207
+ if (!supported.has(name)) {
208
+ throw new Error(
209
+ `${ERROR_PREFIX} Plugin "${name}" is configured but not supported by the active preset.`
210
+ );
211
+ }
212
+ }
213
+ };
214
+
215
+ // src/pipeline/middleware/validation/validators/assertExtraOptionUnsupportedPlugins.ts
216
+ var assertExtraOptionUnsupportedPlugins = (extraOptions, supported) => {
217
+ assertUnsupportedPlugins(extraOptions.plugins ?? {}, supported);
218
+ };
219
+
220
+ // src/pipeline/middleware/typeGuards/assertPluginValue.ts
221
+ function assertPluginValue(val, name, source) {
222
+ const isObject = val !== null && typeof val === "object" && !Array.isArray(val);
223
+ const isValid = val === void 0 || val === false || isObject;
224
+ if (!isValid) {
225
+ throw new Error(
226
+ `${ERROR_PREFIX} Invalid configuration for plugin "${name}" in ${source}. Expected Object or Boolean (false), but received ${typeof val} (${val}).`
227
+ );
228
+ }
229
+ }
230
+
231
+ // src/pipeline/middleware/validation/validators/assertResolvedPluginValues.ts
232
+ var assertResolvedPluginValues = (plugins) => {
233
+ for (const [name, value] of Object.entries(plugins)) {
234
+ assertPluginValue(value, name, "plugins");
235
+ }
236
+ };
237
+
238
+ // src/pipeline/middleware/validation/validators/assertExtraOptionPluginValues.ts
239
+ var assertExtraOptionPluginValues = (extraOptions, supported) => {
240
+ const plugins = extraOptions.plugins ?? {};
241
+ for (const name of supported) {
242
+ if (Object.prototype.hasOwnProperty.call(plugins, name)) {
243
+ assertPluginValue(plugins[name], name, "extraOptions");
244
+ }
245
+ }
246
+ };
247
+
248
+ // src/pipeline/middleware/validation/assertPluginOptions.ts
249
+ var assertPluginOptions = (ctx) => {
250
+ const { supportedPlugins, extraOptions } = ctx;
251
+ const { plugins } = ctx.result;
252
+ const supported = new Set(Object.keys(supportedPlugins));
253
+ assertUnsupportedPlugins(plugins || {}, supported);
254
+ assertExtraOptionUnsupportedPlugins(resolveExtraOptions(extraOptions), supported);
255
+ assertResolvedPluginValues(plugins);
256
+ assertExtraOptionPluginValues(resolveExtraOptions(extraOptions), supported);
257
+ return ctx;
258
+ };
259
+
260
+ // src/pipeline/middleware/validation/assertResultShape.ts
261
+ function validateResult(ctx) {
262
+ const { result } = ctx;
263
+ assertIsObject(result, "result");
264
+ assertIsObject(result.mountOptions, "result.mountOptions");
265
+ assertIsObject(result.global, "result.global");
266
+ assertIsObject(result.plugins, "result.plugins");
267
+ }
268
+ var assertResultShape = (ctx) => {
269
+ validateResult(ctx);
270
+ return ctx;
271
+ };
272
+ var assertFinalResultShape = (ctx) => {
273
+ validateResult(ctx);
274
+ return ctx;
275
+ };
276
+
277
+ // src/pipeline/state/mergeRecord.ts
278
+ function mergeRecord(base, patch) {
279
+ if (!patch) return base;
280
+ const result = { ...base };
281
+ for (const key in patch) {
282
+ const value = patch[key];
283
+ if (value !== void 0) {
284
+ result[key] = value;
285
+ }
286
+ }
287
+ return result;
288
+ }
289
+
290
+ // src/pipeline/state/patchResultState.ts
291
+ function patchResultState(ctx, patch) {
292
+ if (patch.mountOptions) {
293
+ ctx.result.mountOptions = mergeRecord(ctx.result.mountOptions, patch.mountOptions);
294
+ }
295
+ if (patch.plugins) {
296
+ ctx.result.plugins = mergeRecord(ctx.result.plugins, patch.plugins);
297
+ }
298
+ if (patch.pluginDefaultsState) {
299
+ ctx.result.pluginDefaultsState = mergeRecord(
300
+ ctx.result.pluginDefaultsState,
301
+ patch.pluginDefaultsState
302
+ );
303
+ }
304
+ if (patch.global) {
305
+ ctx.result.global = mergeRecord(ctx.result.global, patch.global);
306
+ }
307
+ return ctx;
308
+ }
309
+
310
+ // src/pipeline/middleware/transformers/withBaseMountOptions.ts
311
+ var withBaseMountOptions = (ctx) => {
312
+ const { defaultMountOptions, mountOptions, extraOptions } = ctx;
313
+ const {
314
+ global: _dg,
315
+ plugins: _dp,
316
+ attrs: _da,
317
+ props: _dpr,
318
+ slots: _ds,
319
+ ...flatDefaults
320
+ } = defaultMountOptions;
321
+ const {
322
+ global: _mg,
323
+ plugins: _mp,
324
+ attrs: _ma,
325
+ props: _mpr,
326
+ slots: _ms,
327
+ ...flatOverrides
328
+ } = mountOptions;
329
+ return patchResultState(ctx, {
330
+ mountOptions: extraOptions.skipDefaultOptions ? mergeRecord(flatOverrides) : mergeRecord(flatDefaults, flatOverrides)
331
+ });
332
+ };
333
+
334
+ // src/guards/isPlainObject.ts
335
+ function isPlainObject(item) {
336
+ if (item === null || typeof item !== "object" || Array.isArray(item)) {
337
+ return false;
338
+ }
339
+ const prototype = Object.getPrototypeOf(item);
340
+ return prototype === Object.prototype || prototype === null;
341
+ }
342
+
343
+ // src/utils/mergeConfigs.ts
344
+ function mergeConfigs(target, source) {
345
+ const arrays = Array.isArray(target) && Array.isArray(source);
346
+ const objects = isPlainObject(target) && isPlainObject(source);
347
+ if (arrays) {
348
+ return [.../* @__PURE__ */ new Set([...target, ...source])];
349
+ }
350
+ if (objects) {
351
+ const output = { ...target };
352
+ for (const key of Object.keys(source)) {
353
+ const targetValue = target[key];
354
+ const sourceValue = source[key];
355
+ if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
356
+ output[key] = [.../* @__PURE__ */ new Set([...targetValue, ...sourceValue])];
357
+ } else if (isPlainObject(targetValue) && isPlainObject(sourceValue)) {
358
+ output[key] = mergeConfigs(targetValue, sourceValue);
359
+ } else {
360
+ output[key] = sourceValue;
361
+ }
362
+ }
363
+ return output;
364
+ }
365
+ throw new Error(`${ERROR_PREFIX} mergeConfigs() expects two plain objects or two arrays.`);
366
+ }
367
+
368
+ // src/pipeline/middleware/transformers/withGlobal.ts
369
+ var withGlobal = (ctx) => {
370
+ const { defaultMountOptions, mountOptions, extraOptions } = ctx;
371
+ return patchResultState(ctx, {
372
+ global: mergeConfigs(
373
+ extraOptions.skipDefaultOptions ? {} : defaultMountOptions.global || {},
374
+ mountOptions.global || {}
375
+ )
376
+ });
377
+ };
378
+
379
+ // src/pipeline/middleware/transformers/withAttrs.ts
380
+ var withAttrs = (ctx) => {
381
+ const { defaultMountOptions, mountOptions, extraOptions } = ctx;
382
+ const attrs = mergeRecord(
383
+ extraOptions.skipDefaultOptions ? {} : defaultMountOptions.attrs || {},
384
+ mountOptions.attrs || {}
385
+ );
386
+ return patchResultState(ctx, {
387
+ mountOptions: Object.keys(attrs).length > 0 ? { attrs } : {}
388
+ });
389
+ };
390
+
391
+ // src/pipeline/plugins/logic/filterSupportedPlugins.ts
392
+ function filterSupportedPlugins(plugins = {}, supported) {
393
+ return Object.fromEntries(
394
+ Object.entries(plugins).filter(([name]) => supported[name] !== void 0)
395
+ );
396
+ }
397
+
398
+ // src/pipeline/middleware/transformers/withPluginsBase.ts
399
+ var withPluginsBase = (ctx) => {
400
+ const { defaultMountOptions, mountOptions, extraOptions, supportedPlugins } = ctx;
401
+ return patchResultState(ctx, {
402
+ plugins: {
403
+ ...extraOptions.skipDefaultOptions ? {} : filterSupportedPlugins(defaultMountOptions.plugins ?? {}, supportedPlugins),
404
+ ...mountOptions.plugins || {}
405
+ }
406
+ });
407
+ };
408
+
409
+ // src/pipeline/middleware/transformers/withPluginsManifest.ts
410
+ var withPluginsManifest = (ctx) => {
411
+ const plugins = Object.fromEntries(
412
+ Object.entries(ctx.supportedPlugins).map(([name, enabled]) => [name, enabled ? {} : false])
413
+ );
414
+ return patchResultState(ctx, {
415
+ plugins
416
+ });
417
+ };
418
+
419
+ // src/pipeline/middleware/transformers/withPreset.ts
420
+ var withPreset = (ctx) => {
421
+ const { preset } = ctx;
422
+ if (!preset?.defaults) return ctx;
423
+ return patchResultState(ctx, {
424
+ pluginDefaultsState: { ...preset.defaults }
425
+ });
426
+ };
427
+
428
+ // src/pipeline/middleware/typeGuards/isPluginOverlayObject.ts
429
+ function isPluginOverlayObject(val) {
430
+ return typeof val === "object" && val !== null && !Array.isArray(val);
431
+ }
432
+
433
+ // src/pipeline/plugins/logic/getExtraPluginOptions.ts
434
+ var getExtraPluginOptions = (extraOptions, name) => {
435
+ return extraOptions.plugins?.[name];
436
+ };
437
+
438
+ // src/pipeline/plugins/logic/getPluginConfig.ts
439
+ function getPluginConfig(ctx, name) {
440
+ const base = ctx.result.plugins[name];
441
+ const extraOptions = resolveExtraOptions(ctx.extraOptions);
442
+ const overlay = getExtraPluginOptions(extraOptions, name);
443
+ const isEnabled = overlay !== void 0 ? overlay !== false : base !== false && base !== void 0;
444
+ if (!isEnabled) {
445
+ return false;
446
+ }
447
+ const current = isPluginOverlayObject(base) ? base : {};
448
+ const extra = isPluginOverlayObject(overlay) ? overlay : {};
449
+ return {
450
+ ...current,
451
+ ...extra
452
+ };
453
+ }
454
+
455
+ // src/pipeline/plugins/logic/patchPluginState.ts
456
+ function patchPluginState(ctx, name, config) {
457
+ const current = ctx.result.plugins[name];
458
+ const currentObj = isPluginOverlayObject(current) ? current : {};
459
+ return patchResultState(ctx, {
460
+ plugins: {
461
+ [name]: {
462
+ ...currentObj,
463
+ ...config
464
+ }
465
+ }
466
+ });
467
+ }
468
+
469
+ // src/pipeline/plugins/logic/resolveRuntimePluginState.ts
470
+ function resolveRuntimePluginState(config, overlay) {
471
+ const runtimeConfig = {
472
+ ...config
473
+ };
474
+ if (isPluginOverlayObject(overlay)) {
475
+ const meta = overlay.__meta;
476
+ if (meta?.instance) {
477
+ runtimeConfig.__sharedInstance = meta.instance;
478
+ }
479
+ }
480
+ delete runtimeConfig.__meta;
481
+ return runtimeConfig;
482
+ }
483
+
484
+ // src/pipeline/plugins/adapters/createPluginMiddleware.ts
485
+ function createPluginMiddleware(name) {
486
+ return (ctx) => {
487
+ const config = getPluginConfig(ctx, name);
488
+ if (!config) return ctx;
489
+ const extraOptions = resolveExtraOptions(ctx.extraOptions);
490
+ const runtimeConfig = resolveRuntimePluginState(
491
+ config,
492
+ getExtraPluginOptions(extraOptions, name)
493
+ );
494
+ return patchPluginState(ctx, name, runtimeConfig);
495
+ };
496
+ }
497
+
498
+ // src/pipeline/plugins/builders/createPluginsMiddlewares.ts
499
+ function createPluginsMiddlewares(supportedPlugins) {
500
+ return Object.keys(supportedPlugins).map(
501
+ (name) => createPluginMiddleware(name)
502
+ );
503
+ }
504
+
505
+ // src/pipeline/plugins/logic/mergePluginDefaults.ts
506
+ function mergePluginDefaults(ctx, name) {
507
+ const { result } = ctx;
508
+ const current = result.plugins[name];
509
+ if (current === false) {
510
+ return ctx;
511
+ }
512
+ result.plugins[name] = {
513
+ ...result.pluginDefaultsState[name] ?? {},
514
+ ...current ?? {}
515
+ };
516
+ return ctx;
517
+ }
518
+
519
+ // src/pipeline/plugins/adapters/createPluginMergeMiddleware.ts
520
+ function createPluginMergeMiddleware(name) {
521
+ return (ctx) => {
522
+ return mergePluginDefaults(ctx, name);
523
+ };
524
+ }
525
+
526
+ // src/pipeline/plugins/builders/createPluginsMergeMiddlewares.ts
527
+ function createPluginsMergeMiddlewares(supportedPlugins) {
528
+ return Object.keys(supportedPlugins).map(
529
+ (name) => createPluginMergeMiddleware(name)
530
+ );
531
+ }
532
+
533
+ // src/pipeline/mount/createMountPipeline.ts
534
+ function createMountPipeline(ctx) {
535
+ return [
536
+ assertConfigurationShape,
537
+ assertResultShape,
538
+ withPreset,
539
+ withPluginsManifest,
540
+ withBaseMountOptions,
541
+ withGlobal,
542
+ withAttrs,
543
+ withPluginsBase,
544
+ assertPluginOptions,
545
+ ...createPluginsMiddlewares(ctx.supportedPlugins),
546
+ ...createPluginsMergeMiddlewares(ctx.supportedPlugins),
547
+ assertFinalResultShape
548
+ ];
549
+ }
550
+
551
+ // src/core/mountWithPlugins.ts
552
+ var import_test_utils = require("@vue/test-utils");
553
+
554
+ // src/pluginsRegistry/createPluginRegistry.ts
555
+ function createPluginRegistry(manifest = []) {
556
+ const map = /* @__PURE__ */ new Map();
557
+ const register = (entry) => {
558
+ const { module: module2 } = entry;
559
+ if (!module2) return;
560
+ const name = module2.getName();
561
+ const definition = module2.getDefinition();
562
+ map.set(name, definition);
563
+ };
564
+ manifest.forEach(register);
565
+ return {
566
+ register,
567
+ get: (name) => map.get(name),
568
+ has: (name) => map.has(name),
569
+ entries: () => map.entries(),
570
+ getNames: () => Array.from(map.keys())
571
+ };
572
+ }
573
+
574
+ // src/pluginsRegistry/createPlugins.ts
575
+ function createPlugins(options = {}, ctx) {
576
+ const plugins = [];
577
+ const { preset } = ctx;
578
+ const registry = createPluginRegistry(preset?.manifest);
579
+ for (const [name, definition] of registry.entries()) {
580
+ let pluginOptions = options[name];
581
+ if (pluginOptions !== false && pluginOptions && typeof pluginOptions === "object") {
582
+ if (definition.beforeCreate) {
583
+ pluginOptions = definition.beforeCreate(ctx, pluginOptions);
584
+ }
585
+ const pluginInstance = definition.create(pluginOptions);
586
+ if (definition.afterCreate) {
587
+ definition.afterCreate(pluginInstance, ctx);
588
+ }
589
+ plugins.push(pluginInstance);
590
+ }
591
+ }
592
+ return plugins;
593
+ }
594
+
595
+ // src/core/mountWithPlugins.ts
596
+ function mountWithPlugins(component, ctx, overrides = {}, runtimeOptions = {
597
+ shallowByDefault: false
598
+ }) {
599
+ const { result } = ctx;
600
+ const mergedOptions = {
601
+ ...result.mountOptions,
602
+ ...overrides,
603
+ plugins: result.plugins
604
+ };
605
+ const {
606
+ shallow,
607
+ plugins = {},
608
+ skipManagedPlugins = false,
609
+ global: overrideGlobal,
610
+ ...restOptions
611
+ } = mergedOptions;
612
+ const shouldUseShallow = shallow ?? runtimeOptions.shallowByDefault;
613
+ const mountFunction = shouldUseShallow ? import_test_utils.shallowMount : import_test_utils.mount;
614
+ const globalPlugins = skipManagedPlugins ? [] : createPlugins(plugins, ctx);
615
+ const finalGlobal = {
616
+ ...result.global,
617
+ ...overrideGlobal
618
+ };
619
+ if (globalPlugins.length > 0) {
620
+ finalGlobal.plugins = [...finalGlobal.plugins || [], ...globalPlugins];
621
+ }
622
+ return mountFunction(component, {
623
+ ...restOptions,
624
+ global: finalGlobal
625
+ });
626
+ }
627
+
628
+ // src/validators/validatePresets.ts
629
+ function validatePresets(presets = {}) {
630
+ if (!isPlainObject(presets)) {
631
+ throw new Error(`${ERROR_PREFIX} Presets must be a plain object.`);
632
+ }
633
+ Object.entries(presets).forEach(([name, preset]) => {
634
+ validatePreset(name, preset);
635
+ });
636
+ }
637
+
638
+ // src/assertions/assertIsPlainObject.ts
639
+ function assertIsPlainObject(value, name = "value") {
640
+ if (!isPlainObject(value)) {
641
+ throw new Error(`${name} must be a plain object.`);
642
+ }
643
+ }
644
+
645
+ // src/validators/validateCreateTestFrameworkOptions.ts
646
+ function validateCreateTestFrameworkOptions(options = {}) {
647
+ assertIsPlainObject(options, "createTestFramework options");
648
+ const { shallowByDefault, presets } = options;
649
+ if (presets !== void 0) {
650
+ validatePresets(presets);
651
+ }
652
+ if (shallowByDefault !== void 0 && typeof shallowByDefault !== "boolean") {
653
+ throw new Error(`${ERROR_PREFIX} "shallowByDefault" must be a boolean.`);
654
+ }
655
+ }
656
+
657
+ // src/validators/validatePlainObjectArgument.ts
658
+ function validatePlainObjectArgument(value, name) {
659
+ if (!isPlainObject(value)) {
660
+ throw new Error(`${ERROR_PREFIX} "${name}" must be a plain object.`);
661
+ }
662
+ }
663
+
664
+ // src/validators/validateBooleanOption.ts
665
+ function validateBooleanOption(value, name) {
666
+ if (value !== void 0 && typeof value !== "boolean") {
667
+ throw new Error(`${ERROR_PREFIX} "${name}" must be a boolean.`);
668
+ }
669
+ }
670
+
671
+ // src/utils/getSupportedPluginNames.ts
672
+ function getSupportedPluginNames(presets = {}, extraOptions) {
673
+ const activePreset = getActivePreset(presets, extraOptions);
674
+ return getPresetManifest(activePreset).map((entry) => entry.module.getName());
675
+ }
676
+
677
+ // src/utils/warnRootPluginOption.ts
678
+ function warnRootPluginOption(pluginName, context) {
679
+ console.warn(
680
+ [
681
+ `${ERROR_PREFIX} Detected plugin option "${pluginName}" at the root of "${context}".`,
682
+ "",
683
+ "Plugin options must be placed under:",
684
+ "",
685
+ "{",
686
+ " plugins: {",
687
+ ` ${pluginName}: { ... }`,
688
+ " }",
689
+ "}",
690
+ "",
691
+ `Did you mean to use "${context}.plugins.${pluginName}"?`
692
+ ].join("\n")
693
+ );
694
+ }
695
+
696
+ // src/validators/warnRootPluginOptions.ts
697
+ function warnRootPluginOptions(options, context, presets = {}, extraOptions) {
698
+ const pluginNames = getSupportedPluginNames(presets, extraOptions);
699
+ pluginNames.forEach((pluginName) => {
700
+ const pluginAlreadyConfigured = options.plugins && pluginName in options.plugins;
701
+ if (Object.hasOwn(options, pluginName) && !pluginAlreadyConfigured) {
702
+ warnRootPluginOption(pluginName, context);
703
+ }
704
+ });
705
+ }
706
+
707
+ // src/validators/validateComponentFactoryOptions.ts
708
+ function validateComponentFactoryOptions(options, context, presets = {}, extraOptions) {
709
+ validatePlainObjectArgument(options, context);
710
+ validateBooleanOption(options.skipManagedPlugins, "skipManagedPlugins");
711
+ warnRootPluginOptions(options, context, presets, extraOptions);
712
+ }
713
+
714
+ // src/validators/validateTestComponentFactoryArguments.ts
715
+ function validateTestComponentFactoryArguments(component, defaultProps, defaultMountOptions, defaultSlots, presets) {
716
+ const isComponent = component !== null && (typeof component === "object" || typeof component === "function");
717
+ if (!isComponent) {
718
+ throw new Error(`${ERROR_PREFIX} testComponentFactory() requires a valid Vue component.`);
719
+ }
720
+ validatePlainObjectArgument(defaultProps, "defaultProps");
721
+ validateComponentFactoryOptions(
722
+ defaultMountOptions,
723
+ "defaultMountOptions",
724
+ presets
725
+ );
726
+ validatePlainObjectArgument(defaultSlots, "defaultSlots");
727
+ }
728
+
729
+ // src/validators/validateComponentFactoryExtraOptions.ts
730
+ function validateComponentFactoryExtraOptions(options, presets = {}) {
731
+ validatePlainObjectArgument(options, "extraOptions");
732
+ validateBooleanOption(options.skipDefaultProps, "skipDefaultProps");
733
+ validateBooleanOption(options.skipDefaultSlots, "skipDefaultSlots");
734
+ validateBooleanOption(options.skipDefaultOptions, "skipDefaultOptions");
735
+ warnRootPluginOptions(options, "extraOptions", presets, options);
736
+ }
737
+
738
+ // src/validators/validateComponentFactoryArguments.ts
739
+ function validateComponentFactoryArguments(props, mountOptions, slots, extraOptions, presets = {}) {
740
+ validatePlainObjectArgument(props, "props");
741
+ validateComponentFactoryOptions(
742
+ mountOptions,
743
+ "mountOptions",
744
+ presets,
745
+ extraOptions
746
+ );
747
+ validatePlainObjectArgument(slots, "slots");
748
+ validateComponentFactoryExtraOptions(extraOptions, presets);
749
+ }
750
+
751
+ // src/core/createTestFramework.ts
752
+ function createTestFramework(options = {}) {
753
+ validateCreateTestFrameworkOptions(options);
754
+ const { presets = {}, shallowByDefault = false } = options;
755
+ const testComponentFactory = (component, defaultProps = {}, defaultMountOptions = {}, defaultSlots = {}) => {
756
+ validateTestComponentFactoryArguments(
757
+ component,
758
+ defaultProps,
759
+ defaultMountOptions,
760
+ defaultSlots,
761
+ presets
762
+ );
763
+ return (props = {}, mountOptions = {}, slots = {}, extraOptions = {}) => {
764
+ validateComponentFactoryArguments(props, mountOptions, slots, extraOptions, presets);
765
+ const {
766
+ skipDefaultProps = false,
767
+ skipDefaultSlots = false,
768
+ skipDefaultOptions = false
769
+ } = extraOptions;
770
+ const finalProps = mergeComponentData({
771
+ defaultMountData: defaultMountOptions.props,
772
+ defaultData: defaultProps,
773
+ mountData: mountOptions.props,
774
+ directData: props,
775
+ skipDefault: skipDefaultProps,
776
+ skipOptions: skipDefaultOptions
777
+ });
778
+ const finalSlots = mergeComponentData({
779
+ defaultMountData: defaultMountOptions.slots,
780
+ defaultData: defaultSlots,
781
+ mountData: mountOptions.slots,
782
+ directData: slots,
783
+ skipDefault: skipDefaultSlots,
784
+ skipOptions: skipDefaultOptions
785
+ });
786
+ const ctx = createPipelineContext({
787
+ defaultMountOptions,
788
+ mountOptions,
789
+ extraOptions,
790
+ presets
791
+ });
792
+ const pipeline = createPipeline(createMountPipeline(ctx));
793
+ const readyCtx = pipeline.run(ctx);
794
+ const mountRuntimeOptions = {
795
+ shallowByDefault
796
+ };
797
+ return mountWithPlugins(
798
+ component,
799
+ readyCtx,
800
+ {
801
+ props: finalProps,
802
+ slots: finalSlots
803
+ },
804
+ mountRuntimeOptions
805
+ );
806
+ };
807
+ };
808
+ return { testComponentFactory };
809
+ }
810
+
811
+ // src/pluginsRegistry/helpers/exposeInstance.ts
812
+ function exposeInstance(instance, options) {
813
+ if (typeof options?.expose === "function") {
814
+ options.expose(instance);
815
+ }
816
+ }
817
+
818
+ // src/pluginsRegistry/factory/createPluginInstance.ts
819
+ function createPluginInstance(factory, options) {
820
+ const instance = options.__sharedInstance ?? factory(options);
821
+ exposeInstance(instance, options);
822
+ return instance;
823
+ }
824
+
825
+ // src/pluginsRegistry/factory/createVuePlugin.ts
826
+ function createVuePlugin(plugin, options) {
827
+ if (options.__sharedInstance) {
828
+ throw new Error(
829
+ `${ERROR_PREFIX} __sharedInstance is not supported for non-instance Vue plugins. Shared instances are only supported for stateful plugin factories such as Router, Pinia or vue-i18n.`
830
+ );
831
+ }
832
+ if (options.expose) {
833
+ throw new Error(
834
+ `${ERROR_PREFIX} expose() is not supported for non-instance Vue plugins because they do not produce a runtime instance. The expose callback is only available for stateful plugin factories such as Router, Pinia or vue-i18n.`
835
+ );
836
+ }
837
+ return [plugin, options];
838
+ }
839
+
840
+ // src/utils/captureInstance.ts
841
+ function captureInstance() {
842
+ let instance;
843
+ return {
844
+ expose(ins) {
845
+ instance = ins;
846
+ },
847
+ get instance() {
848
+ return instance;
849
+ }
850
+ };
851
+ }
852
+
853
+ // src/index.ts
854
+ var Types = {};
855
+ // Annotate the CommonJS export names for ESM import in node:
856
+ 0 && (module.exports = {
857
+ Types,
858
+ captureInstance,
859
+ createPluginInstance,
860
+ createTestFramework,
861
+ createVuePlugin,
862
+ validatePreset,
863
+ validatePresets
864
+ });