[{"data":1,"prerenderedAt":688},["ShallowReactive",2],{"page:\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftesting":3},{"id":4,"title":5,"body":6,"description":669,"extension":670,"frontmatter":671,"heading":5,"meta":678,"navigation":680,"order":675,"path":681,"seo":682,"sitemap":683,"source":684,"stem":685,"__hash__":686,"hasPopups":687},"docs\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftesting.md","Testing",{"type":7,"value":8,"toc":663},"minimark",[9,21,79,82,223,228,247],[10,11,12,16,17,20],"p",{},[13,14,15],"code",{},"kubb\u002Fkit\u002Ftesting"," is a separate subpath for the Vitest-backed helpers used to test plugins, generators, and adapters. It stays separate from ",[13,18,19],{},"kubb\u002Fkit"," so importing the authoring toolkit never pulls Vitest into a plugin's runtime dependencies.",[22,23,29],"pre",{"language":24,"meta":25,"code":26,"filename":27,"class":28},"typescript","twoslash","import { createMockedPlugin, renderGeneratorOperation, matchFiles } from 'kubb\u002Fkit\u002Ftesting'","plugin.test.ts","shiki shiki-themes github-light github-dark twoslash lsp dark:github-dark",[13,30,32],{"class":31},"language-typescript",[33,34,37,41,45,52,55,61,63,69,72,75],"span",{"class":35,"style":36},"line","display: inline",[33,38,40],{"style":39},"color:#D73A49;--shiki-dark:#F97583","import",[33,42,44],{"style":43},"color:#24292E;--shiki-dark:#E1E4E8"," { ",[33,46,47],{"style":43},[33,48,51],{"class":49,"data-popup":50},"twoslash-hover","0","createMockedPlugin",[33,53,54],{"style":43},", ",[33,56,57],{"style":43},[33,58,60],{"class":49,"data-popup":59},"1","renderGeneratorOperation",[33,62,54],{"style":43},[33,64,65],{"style":43},[33,66,68],{"class":49,"data-popup":67},"2","matchFiles",[33,70,71],{"style":43}," } ",[33,73,74],{"style":39},"from",[33,76,78],{"style":77},"color:#032F62;--shiki-dark:#9ECBFF"," 'kubb\u002Fkit\u002Ftesting'",[10,80,81],{},"The subpath exports mocking builders, generator runners, and a snapshot matcher:",[83,84,85,98],"table",{},[86,87,88],"thead",{},[89,90,91,95],"tr",{},[92,93,94],"th",{},"Export",[92,96,97],{},"What it does",[99,100,101,111,129,139,161,179,194,210],"tbody",{},[89,102,103,108],{},[104,105,106],"td",{},[13,107,51],{},[104,109,110],{},"Builds a minimal plugin for a test without wiring a full config.",[89,112,113,118],{},[104,114,115],{},[13,116,117],{},"createMockedAdapter",[104,119,120,121,124,125,128],{},"Builds a minimal adapter for a test without wiring a full config. ",[13,122,123],{},"parse"," returns an empty ",[13,126,127],{},"InputNode"," by default.",[89,130,131,136],{},[104,132,133],{},[13,134,135],{},"createMockedPluginDriver",[104,137,138],{},"Builds a driver around a set of plugins so a generator runs through its real lifecycle in isolation.",[89,140,141,146],{},[104,142,143],{},[13,144,145],{},"createMockedSetupContext",[104,147,148,149,152,153,156,157,160],{},"Builds the ",[13,150,151],{},"kubb:plugin:setup"," context with spy methods. Its ",[13,154,155],{},"requirePlugin"," fails for plugins not listed in ",[13,158,159],{},"plugins",".",[89,162,163,168],{},[104,164,165],{},[13,166,167],{},"renderGeneratorSchema",[104,169,170,171,174,175,178],{},"Calls a generator's ",[13,172,173],{},"schema()"," method against a ",[13,176,177],{},"SchemaNode"," fixture and collects the files it emits.",[89,180,181,185],{},[104,182,183],{},[13,184,60],{},[104,186,170,187,190,191,178],{},[13,188,189],{},"operation()"," method against an ",[13,192,193],{},"OperationNode",[89,195,196,201],{},[104,197,198],{},[13,199,200],{},"renderGeneratorOperations",[104,202,170,203,206,207,209],{},[13,204,205],{},"operations()"," method against an array of ",[13,208,193],{}," fixtures and collects the files it emits.",[89,211,212,216],{},[104,213,214],{},[13,215,68],{},[104,217,218,219,222],{},"Asserts the generated ",[13,220,221],{},"FileNode","s match expected paths and contents through file snapshots, the assertion most generator tests end on.",[224,225,227],"h2",{"id":226},"plugin-setup","Test a plugin's setup",[10,229,230,231,233,234,239,240,243,244,160],{},"Pass a mocked setup context to the plugin's ",[13,232,151],{}," handler, then assert on its spies. When setup uses ",[235,236,238],"a",{"href":237},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Fplugins#setup-context","composables",", run it inside ",[13,241,242],{},"kubbContext.run(ctx, …)",". Without it, the composables throw ",[13,245,246],{},"KUBB_NO_CONTEXT",[22,248,250],{"language":24,"meta":25,"code":249,"filename":27,"class":28},"import { addGenerator, defineExtension, kubbContext } from 'kubb\u002Fkit'\nimport { createMockedSetupContext } from 'kubb\u002Fkit\u002Ftesting'\nimport { expect, test } from 'vitest'\n\nconst pluginExample = defineExtension({\n  kind: 'plugin',\n  meta: { name: 'plugin-example' },\n  hooks: {\n    'kubb:plugin:setup'() {\n      addGenerator({ name: 'example', operation: () => [] })\n    },\n  },\n})\n\ntest('registers one generator', () => {\n  const plugin = pluginExample()\n  const ctx = createMockedSetupContext()\n\n  kubbContext.run(ctx, () => plugin.hooks['kubb:plugin:setup']?.(ctx))\n\n  expect(ctx.addGenerator).toHaveBeenCalledTimes(1)\n})",[13,251,252,287,288,287,305,287,332,287,334,287,363,287,383,287,410,287,423,287,431,287,471,287,476,287,481,287,486,287,488,287,509,287,534,287,557,287,559,287,618,287,620,287,659],{"class":31},[33,253,254,256,258,264,266,272,274,280,282,284],{"class":35,"style":36},[33,255,40],{"style":39},[33,257,44],{"style":43},[33,259,260],{"style":43},[33,261,263],{"class":49,"data-popup":262},"3","addGenerator",[33,265,54],{"style":43},[33,267,268],{"style":43},[33,269,271],{"class":49,"data-popup":270},"4","defineExtension",[33,273,54],{"style":43},[33,275,276],{"style":43},[33,277,279],{"class":49,"data-popup":278},"5","kubbContext",[33,281,71],{"style":43},[33,283,74],{"style":39},[33,285,286],{"style":77}," 'kubb\u002Fkit'","\n",[33,289,290,292,294,299,301,303],{"class":35,"style":36},[33,291,40],{"style":39},[33,293,44],{"style":43},[33,295,296],{"style":43},[33,297,145],{"class":49,"data-popup":298},"6",[33,300,71],{"style":43},[33,302,74],{"style":39},[33,304,78],{"style":77},[33,306,307,309,311,317,319,325,327,329],{"class":35,"style":36},[33,308,40],{"style":39},[33,310,44],{"style":43},[33,312,313],{"style":43},[33,314,316],{"class":49,"data-popup":315},"7","expect",[33,318,54],{"style":43},[33,320,321],{"style":43},[33,322,324],{"class":49,"data-popup":323},"8","test",[33,326,71],{"style":43},[33,328,74],{"style":39},[33,330,331],{"style":77}," 'vitest'",[33,333],{"class":35,"style":36},[33,335,336,339,343,349,352,355,360],{"class":35,"style":36},[33,337,338],{"style":39},"const",[33,340,342],{"style":341},"color:#005CC5;--shiki-dark:#79B8FF"," ",[33,344,345],{"style":341},[33,346,348],{"class":49,"data-popup":347},"9","pluginExample",[33,350,351],{"style":39}," =",[33,353,342],{"style":354},"color:#6F42C1;--shiki-dark:#B392F0",[33,356,357],{"style":354},[33,358,271],{"class":49,"data-popup":359},"10",[33,361,362],{"style":43},"({",[33,364,365,368,374,377,380],{"class":35,"style":36},[33,366,367],{"style":43},"  ",[33,369,370],{"style":43},[33,371,373],{"class":49,"data-popup":372},"11","kind",[33,375,376],{"style":43},": ",[33,378,379],{"style":77},"'plugin'",[33,381,382],{"style":43},",",[33,384,385,387,393,396,402,404,407],{"class":35,"style":36},[33,386,367],{"style":43},[33,388,389],{"style":43},[33,390,392],{"class":49,"data-popup":391},"12","meta",[33,394,395],{"style":43},": { ",[33,397,398],{"style":43},[33,399,401],{"class":49,"data-popup":400},"13","name",[33,403,376],{"style":43},[33,405,406],{"style":77},"'plugin-example'",[33,408,409],{"style":43}," },",[33,411,412,414,420],{"class":35,"style":36},[33,413,367],{"style":43},[33,415,416],{"style":43},[33,417,419],{"class":49,"data-popup":418},"14","hooks",[33,421,422],{"style":43},": {",[33,424,425,428],{"class":35,"style":36},[33,426,427],{"style":77},"    'kubb:plugin:setup'",[33,429,430],{"style":43},"() {",[33,432,433,436,441,444,449,451,454,456,462,465,468],{"class":35,"style":36},[33,434,435],{"style":354},"      ",[33,437,438],{"style":354},[33,439,263],{"class":49,"data-popup":440},"15",[33,442,443],{"style":43},"({ ",[33,445,446],{"style":43},[33,447,401],{"class":49,"data-popup":448},"16",[33,450,376],{"style":43},[33,452,453],{"style":77},"'example'",[33,455,54],{"style":43},[33,457,458],{"style":354},[33,459,461],{"class":49,"data-popup":460},"17","operation",[33,463,464],{"style":43},": () ",[33,466,467],{"style":39},"=>",[33,469,470],{"style":43}," [] })",[33,472,473],{"class":35,"style":36},[33,474,475],{"style":43},"    },",[33,477,478],{"class":35,"style":36},[33,479,480],{"style":43},"  },",[33,482,483],{"class":35,"style":36},[33,484,485],{"style":43},"})",[33,487],{"class":35,"style":36},[33,489,490,495,498,501,504,506],{"class":35,"style":36},[33,491,492],{"style":354},[33,493,324],{"class":49,"data-popup":494},"18",[33,496,497],{"style":43},"(",[33,499,500],{"style":77},"'registers one generator'",[33,502,503],{"style":43},", () ",[33,505,467],{"style":39},[33,507,508],{"style":43}," {",[33,510,511,514,516,522,524,526,531],{"class":35,"style":36},[33,512,513],{"style":39},"  const",[33,515,342],{"style":341},[33,517,518],{"style":341},[33,519,521],{"class":49,"data-popup":520},"19","plugin",[33,523,351],{"style":39},[33,525,342],{"style":354},[33,527,528],{"style":354},[33,529,348],{"class":49,"data-popup":530},"20",[33,532,533],{"style":43},"()",[33,535,536,538,540,546,548,550,555],{"class":35,"style":36},[33,537,513],{"style":39},[33,539,342],{"style":341},[33,541,542],{"style":341},[33,543,545],{"class":49,"data-popup":544},"21","ctx",[33,547,351],{"style":39},[33,549,342],{"style":354},[33,551,552],{"style":354},[33,553,145],{"class":49,"data-popup":554},"22",[33,556,533],{"style":43},[33,558],{"class":35,"style":36},[33,560,561,563,568,570,576,578,583,585,587,589,594,596,601,604,607,610,615],{"class":35,"style":36},[33,562,367],{"style":43},[33,564,565],{"style":43},[33,566,279],{"class":49,"data-popup":567},"23",[33,569,160],{"style":43},[33,571,572],{"style":354},[33,573,575],{"class":49,"data-popup":574},"24","run",[33,577,497],{"style":43},[33,579,580],{"style":43},[33,581,545],{"class":49,"data-popup":582},"25",[33,584,503],{"style":43},[33,586,467],{"style":39},[33,588,342],{"style":43},[33,590,591],{"style":43},[33,592,521],{"class":49,"data-popup":593},"26",[33,595,160],{"style":43},[33,597,598],{"style":43},[33,599,419],{"class":49,"data-popup":600},"27",[33,602,603],{"style":43},"[",[33,605,606],{"style":77},"'kubb:plugin:setup'",[33,608,609],{"style":43},"]?.(",[33,611,612],{"style":43},[33,613,545],{"class":49,"data-popup":614},"28",[33,616,617],{"style":43},"))",[33,619],{"class":35,"style":36},[33,621,622,624,629,631,636,638,643,646,652,654,656],{"class":35,"style":36},[33,623,367],{"style":354},[33,625,626],{"style":354},[33,627,316],{"class":49,"data-popup":628},"29",[33,630,497],{"style":43},[33,632,633],{"style":43},[33,634,545],{"class":49,"data-popup":635},"30",[33,637,160],{"style":43},[33,639,640],{"style":43},[33,641,263],{"class":49,"data-popup":642},"31",[33,644,645],{"style":43},").",[33,647,648],{"style":354},[33,649,651],{"class":49,"data-popup":650},"32","toHaveBeenCalledTimes",[33,653,497],{"style":43},[33,655,59],{"style":341},[33,657,658],{"style":43},")",[33,660,661],{"class":35,"style":36},[33,662,485],{"style":43},{"title":664,"searchDepth":665,"depth":665,"links":666},"",5,[667],{"id":226,"depth":668,"text":227},2,"kubb\u002Fkit\u002Ftesting is a separate subpath for the Vitest-backed helpers used to test plugins, generators, and adapters, kept apart from kubb\u002Fkit so the authoring toolkit never pulls in Vitest.","md",{"layout":672,"title":5,"description":669,"outline":673,"order":675,"navigation":676},"doc",[668,674],3,12,{"title":5,"icon":677},"i-iconoir-flask",{"layout":672,"outline":679},[668,674],{"title":5,"icon":677},"\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftesting",{"title":5,"description":669},{"loc":681},"kubb-labs\u002Fkubb\u002Fdocs\u002F5.x\u002Freference\u002Fkit\u002Ftesting.md","docs\u002F5.x\u002Freference\u002Fkit\u002Ftesting","1RaXg8-nTy_Abgv5KK1IpMZGYhZ8iWClB49Rs0E9Lpg",true,1792317737218]