@kubb/core 5.10.3 → 5.11.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/mocks.cjs DELETED
@@ -1,209 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_Hookable = require("./Hookable-pvEb-nN9.cjs");
3
- let node_path = require("node:path");
4
- node_path = require_Hookable.__toESM(node_path, 1);
5
- let _kubb_ast = require("@kubb/ast");
6
- let vitest = require("vitest");
7
- //#region src/mocks.ts
8
- /**
9
- * Creates a minimal `KubbDriver` mock for unit tests.
10
- */
11
- function createMockedPluginDriver(options = {}) {
12
- const fileManager = new require_Hookable.FileManager();
13
- return {
14
- config: options?.config ?? {
15
- root: ".",
16
- output: { path: "./path" }
17
- },
18
- getPlugin(_pluginName) {
19
- return options?.plugin;
20
- },
21
- getResolver: (_pluginName) => options?.plugin?.resolver,
22
- fileManager
23
- };
24
- }
25
- /** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */
26
- function createMockedSetupContext({ plugins = [], options = {} } = {}) {
27
- const registered = plugins.map((name) => ({ name }));
28
- return {
29
- config: { plugins: registered },
30
- options,
31
- addGenerator: vitest.vi.fn(),
32
- setResolver: vitest.vi.fn(),
33
- addMacro: vitest.vi.fn(),
34
- setMacros: vitest.vi.fn(),
35
- setOptions: vitest.vi.fn(),
36
- injectFile: vitest.vi.fn(),
37
- requirePlugin: vitest.vi.fn((pluginName) => {
38
- const plugin = registered.find((entry) => entry.name === pluginName);
39
- if (!plugin) throw require_Hookable.pluginNotFoundError({ pluginName });
40
- return plugin;
41
- })
42
- };
43
- }
44
- /**
45
- * Creates a minimal `Adapter` mock for unit tests.
46
- * `parse` returns an empty `InputNode` by default. Override via `options.parse`.
47
- */
48
- function createMockedAdapter(options = {}) {
49
- return {
50
- name: options.name ?? "oas",
51
- options: options.resolvedOptions ?? {},
52
- document: null,
53
- parse: options.parse ?? (async () => _kubb_ast.ast.factory.createInput()),
54
- validate: async () => {}
55
- };
56
- }
57
- /**
58
- * Creates a minimal plugin mock for unit tests.
59
- *
60
- * @example
61
- * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`
62
- */
63
- function createMockedPlugin(params) {
64
- return {
65
- name: params.name,
66
- options: params.options,
67
- resolver: params.resolver,
68
- macros: params.macros,
69
- dependencies: params.dependencies,
70
- hooks: {}
71
- };
72
- }
73
- function createMockedPluginContext(opts) {
74
- const root = (0, node_path.resolve)(opts.config.root, opts.config.output.path);
75
- return {
76
- config: opts.config,
77
- root,
78
- adapter: opts.adapter,
79
- resolver: opts.resolver,
80
- plugin: opts.plugin,
81
- driver: opts.driver,
82
- getResolver: (name) => opts.driver.getResolver(name),
83
- requirePlugin: (pluginName) => {
84
- const plugin = opts.driver.getPlugin(pluginName);
85
- if (!plugin) throw require_Hookable.pluginNotFoundError({
86
- pluginName,
87
- requiredBy: opts.plugin.name
88
- });
89
- return plugin;
90
- },
91
- meta: opts.meta ?? {
92
- circularNames: [],
93
- enumNames: []
94
- },
95
- cache: require_Hookable.createNodeCache(),
96
- addFile: async (...files) => opts.driver.fileManager.add(...files),
97
- upsertFile: async (...files) => opts.driver.fileManager.upsert(...files),
98
- hooks: opts.driver.hooks ?? new require_Hookable.Hookable(),
99
- warn: (msg) => console.warn(msg),
100
- error: (msg) => console.error(msg),
101
- info: (msg) => console.info(msg)
102
- };
103
- }
104
- async function renderNode({ generator, node, opts, generate }) {
105
- const ctx = {
106
- ...createMockedPluginContext(opts),
107
- options: opts.options
108
- };
109
- const transformedNode = opts.plugin.macros?.length ? (0, _kubb_ast.applyMacros)(node, opts.plugin.macros) : node;
110
- if (!(generator.match ? await generator.match(transformedNode, ctx) : true)) return;
111
- await opts.driver.fileManager.dispatch({
112
- result: await generate(transformedNode, ctx),
113
- renderer: generator.renderer
114
- });
115
- }
116
- /**
117
- * Renders a generator's `schema` method in a test context.
118
- *
119
- * @example
120
- * ```ts
121
- * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
122
- * await matchFiles(driver.fileManager.files)
123
- * ```
124
- */
125
- async function renderGeneratorSchema(generator, node, opts) {
126
- if (!generator.schema) return;
127
- await renderNode({
128
- generator,
129
- node,
130
- opts,
131
- generate: (transformedNode, ctx) => generator.schema(transformedNode, ctx)
132
- });
133
- }
134
- /**
135
- * Renders a generator's `operation` method in a test context.
136
- *
137
- * @example
138
- * ```ts
139
- * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
140
- * await matchFiles(driver.fileManager.files)
141
- * ```
142
- */
143
- async function renderGeneratorOperation(generator, node, opts) {
144
- if (!generator.operation) return;
145
- await renderNode({
146
- generator,
147
- node,
148
- opts,
149
- generate: (transformedNode, ctx) => generator.operation(transformedNode, ctx)
150
- });
151
- }
152
- /**
153
- * Renders a generator's `operations` method in a test context.
154
- *
155
- * @example
156
- * ```ts
157
- * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })
158
- * await matchFiles(driver.fileManager.files)
159
- * ```
160
- */
161
- async function renderGeneratorOperations(generator, nodes, opts) {
162
- if (!generator.operations) return;
163
- const context = createMockedPluginContext(opts);
164
- const transformedNodes = opts.plugin.macros?.length ? nodes.map((n) => (0, _kubb_ast.applyMacros)(n, opts.plugin.macros)) : nodes;
165
- const result = await generator.operations(transformedNodes, {
166
- ...context,
167
- options: opts.options
168
- });
169
- await opts.driver.fileManager.dispatch({
170
- result,
171
- renderer: generator.renderer
172
- });
173
- }
174
- /**
175
- * Renders the driver's collected `FileNode`s to source and asserts each against a file snapshot.
176
- * Pair it with the `renderGenerator*` helpers to snapshot a generator's output.
177
- *
178
- * @example
179
- * ```ts
180
- * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
181
- * await matchFiles(driver.fileManager.files, { parsers, format })
182
- * ```
183
- */
184
- async function matchFiles(files, options = {}) {
185
- if (!files?.length) return;
186
- const { parsers = /* @__PURE__ */ new Map(), format, pre } = options;
187
- const fileManager = new require_Hookable.FileManager();
188
- const processed = /* @__PURE__ */ new Map();
189
- for (const file of files) {
190
- if (!file?.path || processed.has(file.path)) continue;
191
- const parsed = await fileManager.parse(file, { parsers });
192
- const code = file.baseName.endsWith(".json") || !format ? parsed : await format(parsed);
193
- processed.set(file.path, code);
194
- const snapshotPath = node_path.default.join("__snapshots__", ...pre ? [require_Hookable.camelCase(pre)] : [], file.baseName);
195
- await (0, vitest.expect)(code).toMatchFileSnapshot(snapshotPath);
196
- }
197
- return processed;
198
- }
199
- //#endregion
200
- exports.createMockedAdapter = createMockedAdapter;
201
- exports.createMockedPlugin = createMockedPlugin;
202
- exports.createMockedPluginDriver = createMockedPluginDriver;
203
- exports.createMockedSetupContext = createMockedSetupContext;
204
- exports.matchFiles = matchFiles;
205
- exports.renderGeneratorOperation = renderGeneratorOperation;
206
- exports.renderGeneratorOperations = renderGeneratorOperations;
207
- exports.renderGeneratorSchema = renderGeneratorSchema;
208
-
209
- //# sourceMappingURL=mocks.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mocks.cjs","names":["FileManager","vi","pluginNotFoundError","ast","resolve","createNodeCache","Hookable","applyMacros","path","camelCase","expect"],"sources":["../src/mocks.ts"],"sourcesContent":["import path, { resolve } from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport type { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from '@kubb/ast'\nimport { applyMacros, ast } from '@kubb/ast'\nimport { expect, vi } from 'vitest'\nimport type { Parser } from './defineParser.ts'\nimport { FileManager } from './FileManager.ts'\nimport { Hookable } from './Hookable.ts'\nimport { createNodeCache } from './nodeCache.ts'\nimport { type KubbDriver, pluginNotFoundError } from './KubbDriver.ts'\nimport type { Config, KubbHooks } from './types.ts'\nimport type { Adapter, AdapterFactoryOptions } from './createAdapter.ts'\nimport type { Generator, GeneratorContext } from './defineGenerator.ts'\nimport type { KubbPluginSetupContext, NormalizedPlugin, Plugin, PluginType } from './definePlugin.ts'\n\n/**\n * Creates a minimal `KubbDriver` mock for unit tests.\n */\nexport function createMockedPluginDriver(options: { name?: string; plugin?: NormalizedPlugin; config?: Config } = {}): KubbDriver {\n const fileManager = new FileManager()\n\n return {\n config: options?.config ?? {\n root: '.',\n output: {\n path: './path',\n },\n },\n getPlugin(_pluginName: string): NormalizedPlugin | undefined {\n return options?.plugin\n },\n getResolver: (_pluginName: string) => options?.plugin?.resolver,\n fileManager,\n } as unknown as KubbDriver\n}\n\n/** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */\nexport function createMockedSetupContext<TFactory extends PluginType = PluginType>({\n plugins = [],\n options = {} as TFactory['options'],\n}: { plugins?: Array<string>; options?: TFactory['options'] } = {}): KubbPluginSetupContext<TFactory> {\n const registered = plugins.map((name) => ({ name }) as unknown as Plugin)\n\n return {\n config: { plugins: registered } as unknown as Config,\n options,\n addGenerator: vi.fn(),\n setResolver: vi.fn(),\n addMacro: vi.fn(),\n setMacros: vi.fn(),\n setOptions: vi.fn(),\n injectFile: vi.fn(),\n requirePlugin: vi.fn((pluginName: string) => {\n const plugin = registered.find((entry) => entry.name === pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName })\n return plugin\n }) as KubbPluginSetupContext<TFactory>['requirePlugin'],\n }\n}\n\n/**\n * Creates a minimal `Adapter` mock for unit tests.\n * `parse` returns an empty `InputNode` by default. Override via `options.parse`.\n */\nexport function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(\n options: {\n name?: TOptions['name']\n resolvedOptions?: TOptions['resolvedOptions']\n parse?: Adapter<TOptions>['parse']\n } = {},\n): Adapter<TOptions> {\n const adapter: Adapter<TOptions> = {\n name: (options.name ?? 'oas') as TOptions['name'],\n options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],\n document: null,\n parse: options.parse ?? (async () => ast.factory.createInput()),\n validate: async () => {},\n }\n return adapter\n}\n\n/**\n * Creates a minimal plugin mock for unit tests.\n *\n * @example\n * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`\n */\nexport function createMockedPlugin<TOptions extends PluginType = PluginType>(params: {\n name: TOptions['name']\n options: TOptions['resolvedOptions']\n resolver?: TOptions['resolver']\n macros?: Array<Macro>\n dependencies?: Array<string>\n}): NormalizedPlugin<TOptions> {\n return {\n name: params.name,\n options: params.options,\n resolver: params.resolver,\n macros: params.macros,\n dependencies: params.dependencies,\n hooks: {},\n } as unknown as NormalizedPlugin<TOptions>\n}\n\ntype RenderGeneratorOptions<TOptions extends PluginType> = {\n config: Config\n adapter: Adapter\n meta?: InputMeta\n driver: KubbDriver\n plugin: NormalizedPlugin<TOptions>\n options: TOptions['resolvedOptions']\n resolver: TOptions['resolver']\n}\n\nfunction createMockedPluginContext<TOptions extends PluginType>(opts: RenderGeneratorOptions<TOptions>): Omit<GeneratorContext<TOptions>, 'options'> {\n const root = resolve(opts.config.root, opts.config.output.path)\n\n return {\n config: opts.config,\n root,\n adapter: opts.adapter,\n resolver: opts.resolver,\n plugin: opts.plugin,\n driver: opts.driver,\n getResolver: (name: string) => opts.driver.getResolver(name),\n requirePlugin: (pluginName: string) => {\n const plugin = opts.driver.getPlugin(pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName, requiredBy: opts.plugin.name })\n return plugin\n },\n meta: opts.meta ?? { circularNames: [], enumNames: [] },\n cache: createNodeCache(),\n addFile: async (...files: Array<FileNode>) => opts.driver.fileManager.add(...files),\n upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),\n hooks: opts.driver.hooks ?? new Hookable<KubbHooks>(),\n warn: (msg: string) => console.warn(msg),\n error: (msg: string) => console.error(msg),\n info: (msg: string) => console.info(msg),\n } as unknown as Omit<GeneratorContext<TOptions>, 'options'>\n}\n\nasync function renderNode<TOptions extends PluginType, TNode extends SchemaNode | OperationNode>({\n generator,\n node,\n opts,\n generate,\n}: {\n generator: Generator<TOptions>\n node: TNode\n opts: RenderGeneratorOptions<TOptions>\n generate: (node: TNode, ctx: GeneratorContext<TOptions>) => ReturnType<NonNullable<Generator<TOptions>['schema']>>\n}): Promise<void> {\n const ctx = { ...createMockedPluginContext(opts), options: opts.options }\n const transformedNode = opts.plugin.macros?.length ? applyMacros(node, opts.plugin.macros) : node\n const matches = generator.match ? await generator.match(transformedNode, ctx) : true\n if (!matches) return\n await opts.driver.fileManager.dispatch({ result: await generate(transformedNode, ctx), renderer: generator.renderer })\n}\n\n/**\n * Renders a generator's `schema` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorSchema<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: SchemaNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.schema) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.schema!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operation` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperation<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: OperationNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operation) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.operation!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operations` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperations<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n nodes: Array<OperationNode>,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operations) return\n const context = createMockedPluginContext(opts)\n const transformedNodes = opts.plugin.macros?.length ? nodes.map((n) => applyMacros(n, opts.plugin.macros!)) : nodes\n const result = await generator.operations(transformedNodes, {\n ...context,\n options: opts.options,\n })\n await opts.driver.fileManager.dispatch({ result, renderer: generator.renderer })\n}\n\ntype MatchFilesOptions = {\n /**\n * Parsers indexed by file extension, used to render each `FileNode` to source.\n * Without a matching parser the file's raw content is used.\n */\n parsers?: Map<FileNode['extname'], Parser>\n /**\n * Formatter applied to non-JSON output before snapshotting, e.g. prettier. When\n * omitted the parsed source is snapshotted as-is.\n */\n format?: (source?: string) => string | Promise<string>\n /**\n * Subfolder under `__snapshots__`, camelCased. Useful to keep variant snapshots apart.\n */\n pre?: string\n}\n\n/**\n * Renders the driver's collected `FileNode`s to source and asserts each against a file snapshot.\n * Pair it with the `renderGenerator*` helpers to snapshot a generator's output.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files, { parsers, format })\n * ```\n */\nexport async function matchFiles(files: Array<FileNode> | undefined, options: MatchFilesOptions = {}): Promise<Map<string, string> | undefined> {\n if (!files?.length) return\n\n const { parsers = new Map(), format, pre } = options\n const fileManager = new FileManager()\n const processed = new Map<string, string>()\n\n for (const file of files) {\n if (!file?.path || processed.has(file.path)) {\n continue\n }\n\n const parsed = await fileManager.parse(file, { parsers })\n const code = file.baseName.endsWith('.json') || !format ? parsed : await format(parsed)\n\n processed.set(file.path, code)\n\n const snapshotPath = path.join('__snapshots__', ...(pre ? [camelCase(pre)] : []), file.baseName)\n await expect(code).toMatchFileSnapshot(snapshotPath)\n }\n\n return processed\n}\n"],"mappings":";;;;;;;;;;AAkBA,SAAgB,yBAAyB,UAAyE,CAAC,GAAe;CAChI,MAAM,cAAc,IAAIA,iBAAAA,YAAY;CAEpC,OAAO;EACL,QAAQ,SAAS,UAAU;GACzB,MAAM;GACN,QAAQ,EACN,MAAM,SACR;EACF;EACA,UAAU,aAAmD;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AAA,GAAMC,OAAAA,OAAAA,CAAO,IAAI,CAAC,CAAC,oBAAoB,YAAY;CACrD;CAEA,OAAO;AACT"}
package/dist/mocks.d.cts DELETED
@@ -1,107 +0,0 @@
1
- import { C as NormalizedPlugin, Ht as KubbDriver, M as PluginType, X as Generator, an as Parser, ft as Config, i as AdapterFactoryOptions, t as Adapter, x as KubbPluginSetupContext } from "./createAdapter-B5kKMsWV.cjs";
2
- import { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from "@kubb/ast";
3
- //#region src/mocks.d.ts
4
- /**
5
- * Creates a minimal `KubbDriver` mock for unit tests.
6
- */
7
- export declare function createMockedPluginDriver(options?: {
8
- name?: string;
9
- plugin?: NormalizedPlugin;
10
- config?: Config;
11
- }): KubbDriver;
12
- /** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */
13
- export declare function createMockedSetupContext<TFactory extends PluginType = PluginType>({ plugins, options }?: {
14
- plugins?: Array<string>;
15
- options?: TFactory['options'];
16
- }): KubbPluginSetupContext<TFactory>;
17
- /**
18
- * Creates a minimal `Adapter` mock for unit tests.
19
- * `parse` returns an empty `InputNode` by default. Override via `options.parse`.
20
- */
21
- export declare function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(options?: {
22
- name?: TOptions['name'];
23
- resolvedOptions?: TOptions['resolvedOptions'];
24
- parse?: Adapter<TOptions>['parse'];
25
- }): Adapter<TOptions>;
26
- /**
27
- * Creates a minimal plugin mock for unit tests.
28
- *
29
- * @example
30
- * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`
31
- */
32
- export declare function createMockedPlugin<TOptions extends PluginType = PluginType>(params: {
33
- name: TOptions['name'];
34
- options: TOptions['resolvedOptions'];
35
- resolver?: TOptions['resolver'];
36
- macros?: Array<Macro>;
37
- dependencies?: Array<string>;
38
- }): NormalizedPlugin<TOptions>;
39
- type RenderGeneratorOptions<TOptions extends PluginType> = {
40
- config: Config;
41
- adapter: Adapter;
42
- meta?: InputMeta;
43
- driver: KubbDriver;
44
- plugin: NormalizedPlugin<TOptions>;
45
- options: TOptions['resolvedOptions'];
46
- resolver: TOptions['resolver'];
47
- };
48
- /**
49
- * Renders a generator's `schema` method in a test context.
50
- *
51
- * @example
52
- * ```ts
53
- * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
54
- * await matchFiles(driver.fileManager.files)
55
- * ```
56
- */
57
- export declare function renderGeneratorSchema<TOptions extends PluginType>(generator: Generator<TOptions>, node: SchemaNode, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
58
- /**
59
- * Renders a generator's `operation` method in a test context.
60
- *
61
- * @example
62
- * ```ts
63
- * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
64
- * await matchFiles(driver.fileManager.files)
65
- * ```
66
- */
67
- export declare function renderGeneratorOperation<TOptions extends PluginType>(generator: Generator<TOptions>, node: OperationNode, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
68
- /**
69
- * Renders a generator's `operations` method in a test context.
70
- *
71
- * @example
72
- * ```ts
73
- * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })
74
- * await matchFiles(driver.fileManager.files)
75
- * ```
76
- */
77
- export declare function renderGeneratorOperations<TOptions extends PluginType>(generator: Generator<TOptions>, nodes: Array<OperationNode>, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
78
- type MatchFilesOptions = {
79
- /**
80
- * Parsers indexed by file extension, used to render each `FileNode` to source.
81
- * Without a matching parser the file's raw content is used.
82
- */
83
- parsers?: Map<FileNode['extname'], Parser>;
84
- /**
85
- * Formatter applied to non-JSON output before snapshotting, e.g. prettier. When
86
- * omitted the parsed source is snapshotted as-is.
87
- */
88
- format?: (source?: string) => string | Promise<string>;
89
- /**
90
- * Subfolder under `__snapshots__`, camelCased. Useful to keep variant snapshots apart.
91
- */
92
- pre?: string;
93
- };
94
- /**
95
- * Renders the driver's collected `FileNode`s to source and asserts each against a file snapshot.
96
- * Pair it with the `renderGenerator*` helpers to snapshot a generator's output.
97
- *
98
- * @example
99
- * ```ts
100
- * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
101
- * await matchFiles(driver.fileManager.files, { parsers, format })
102
- * ```
103
- */
104
- export declare function matchFiles(files: Array<FileNode> | undefined, options?: MatchFilesOptions): Promise<Map<string, string> | undefined>;
105
- //#endregion
106
- export {};
107
- //# sourceMappingURL=mocks.d.cts.map