@storybook/addon-vitest 0.0.0-pr-32047-sha-fa54ee2d → 0.0.0-pr-32047-sha-2c994900
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TestContext } from 'vitest';
|
|
1
2
|
import { ChildProcess } from 'child_process';
|
|
2
3
|
import { Readable } from 'stream';
|
|
3
4
|
import { ReadStream } from 'fs';
|
|
@@ -42643,6 +42644,6 @@ declare global {
|
|
|
42643
42644
|
declare const convertToFilePath: (url: string) => string;
|
|
42644
42645
|
declare function prepareScript(page: Page): Promise<void>;
|
|
42645
42646
|
declare function setupPageScript(page: Page): Promise<void>;
|
|
42646
|
-
declare function testStory(storyId: string, page: Page): Promise<void>;
|
|
42647
|
+
declare function testStory(storyId: string, page: Page): (context: TestContext) => Promise<void>;
|
|
42647
42648
|
|
|
42648
42649
|
export { convertToFilePath, prepareScript, setupPageScript, testStory };
|
|
@@ -26,7 +26,7 @@ ${blue(violation.helpUrl)}`:"")}).join(lineBreak)).join(lineBreak+"\u2500\u2500\
|
|
|
26
26
|
HTML: ${document.body.innerHTML}`;throw new StorybookTestRunnerError({storyId,errorMessage:message})}let channel=globalThis.__STORYBOOK_ADDONS_CHANNEL__;if(!channel)throw new StorybookTestRunnerError({storyId,errorMessage:"The test runner could not access the Storybook channel. Are you sure the Storybook is running correctly in that URL?"});addToUserAgent(`(StorybookTestRunner@${TEST_RUNNER_VERSION})`);let logs=[],hasErrors=!1,logLevelMapping={log:["info","verbose"],warn:["info","warn","verbose"],error:["info","warn","error","verbose"],info:["verbose"],trace:["verbose"],debug:["verbose"],group:["verbose"],groupCollapsed:["verbose"],table:["verbose"],dir:["verbose"]},spyOnConsole=(method,name)=>{let originalFn=console[method].bind(console);console[method]=function(...args){if(method==="error"&&isServerComponentError(args[0]))return;let shouldCollectError=method==="error";shouldCollectError&&(hasErrors=!0);let message=args.map(composeMessage).join(", ");if(method==="trace"){let stackTrace=new Error().stack;message+=`
|
|
27
27
|
${stackTrace}
|
|
28
28
|
`;}if(logLevelMapping[method].includes(TEST_RUNNER_LOG_LEVEL)||shouldCollectError){let prefix=`${bold(name)}: `;logs.push(prefix+message);}originalFn(...args);};};Object.entries({log:blue,info:blue,warn:yellow,error:red,dir:magenta,trace:magenta,group:magenta,groupCollapsed:magenta,table:magenta,debug:magenta}).forEach(([method,color])=>{spyOnConsole(method,color(method));});let cleanup=_listeners=>{Object.entries(_listeners).forEach(([eventName,listener])=>{channel.off(eventName,listener);});};return new Promise((resolve,reject)=>{let rejectWithFormattedError=(storyId2,message,panel)=>{let errorMessage=StorybookTestRunnerError.buildErrorMessage({storyId:storyId2,errorMessage:message,logs,panel});reject(new StorybookTestRunnerError({storyId:storyId2,errorMessage,logs,isMessageFormatted:!0}));},INTERACTIONS_PANEL="storybook/interactions/panel",A11Y_PANEL="storybook/a11y/panel",listeners={[TEST_RUNNER_RENDERED_EVENT]:data=>{if(cleanup(listeners),hasErrors){rejectWithFormattedError(storyId,"Browser console errors");return}else if(data?.reporters){let story=getStory(),a11yGlobals=story.globals?.a11y,a11yParameter=story.parameters?.a11y,a11yTestParameter=a11yParameter?.test,a11yReport=data.reporters.find(reporter=>reporter.type==="a11y");if(a11yParameter?.disable!==!0&&a11yParameter?.test!=="off"&&a11yGlobals?.manual!==!0&&a11yReport?.result?.violations?.length>0){let violations=expectToHaveNoViolations(a11yReport.result);if(violations&&a11yTestParameter==="error"){rejectWithFormattedError(storyId,violations.long,A11Y_PANEL);return}else if(violations&&a11yTestParameter==="todo"){let warningMessage=StorybookTestRunnerError.buildErrorMessage({storyId,errorMessagePrefix:`--------------------------
|
|
29
|
-
${story.title} > ${story.name}`,errorMessage:yellow(violations.short),logs,panel:A11Y_PANEL});logToPage(warningMessage);}}}resolve(document.getElementById("root"));},storyUnchanged:()=>{cleanup(listeners),resolve(document.getElementById("root"));},storyErrored:({description})=>{cleanup(listeners),rejectWithFormattedError(storyId,description,INTERACTIONS_PANEL);},storyThrewException:error=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},playFunctionThrewException:error=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},unhandledErrorsWhilePlaying:([error])=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},storyMissing:id=>{cleanup(listeners),id===storyId&&rejectWithFormattedError(storyId,"The story was missing when trying to access it.");}};Object.entries(listeners).forEach(([eventName,listener])=>{channel.on(eventName,listener);}),channel.emit("setCurrentStory",{storyId,viewMode:TEST_RUNNER_VIEW_MODE});})}globalThis.__test=__test;});}
|
|
29
|
+
${story.title} > ${story.name}`,errorMessage:yellow(violations.short),logs,panel:A11Y_PANEL});logToPage(warningMessage);}}}resolve(document.getElementById("root"));},storyUnchanged:()=>{cleanup(listeners),resolve(document.getElementById("root"));},storyErrored:({description})=>{cleanup(listeners),rejectWithFormattedError(storyId,description,INTERACTIONS_PANEL);},storyThrewException:error=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},playFunctionThrewException:error=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},unhandledErrorsWhilePlaying:([error])=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},storyMissing:id=>{cleanup(listeners),id===storyId&&rejectWithFormattedError(storyId,"The story was missing when trying to access it.");}};Object.entries(listeners).forEach(([eventName,listener])=>{channel.on(eventName,listener);}),channel.emit("setCurrentStory",{storyId,viewMode:TEST_RUNNER_VIEW_MODE});})}globalThis.__test=__test;});}function testStory(storyId,page){return async context=>{let _task=context.task;_task.meta.storyId=storyId,await page.evaluate(async storyId2=>await globalThis.__test(storyId2),storyId);}}
|
|
30
30
|
|
|
31
31
|
exports.convertToFilePath = convertToFilePath;
|
|
32
32
|
exports.prepareScript = prepareScript;
|
|
@@ -24,6 +24,6 @@ ${blue(violation.helpUrl)}`:"")}).join(lineBreak)).join(lineBreak+"\u2500\u2500\
|
|
|
24
24
|
HTML: ${document.body.innerHTML}`;throw new StorybookTestRunnerError({storyId,errorMessage:message})}let channel=globalThis.__STORYBOOK_ADDONS_CHANNEL__;if(!channel)throw new StorybookTestRunnerError({storyId,errorMessage:"The test runner could not access the Storybook channel. Are you sure the Storybook is running correctly in that URL?"});addToUserAgent(`(StorybookTestRunner@${TEST_RUNNER_VERSION})`);let logs=[],hasErrors=!1,logLevelMapping={log:["info","verbose"],warn:["info","warn","verbose"],error:["info","warn","error","verbose"],info:["verbose"],trace:["verbose"],debug:["verbose"],group:["verbose"],groupCollapsed:["verbose"],table:["verbose"],dir:["verbose"]},spyOnConsole=(method,name)=>{let originalFn=console[method].bind(console);console[method]=function(...args){if(method==="error"&&isServerComponentError(args[0]))return;let shouldCollectError=method==="error";shouldCollectError&&(hasErrors=!0);let message=args.map(composeMessage).join(", ");if(method==="trace"){let stackTrace=new Error().stack;message+=`
|
|
25
25
|
${stackTrace}
|
|
26
26
|
`;}if(logLevelMapping[method].includes(TEST_RUNNER_LOG_LEVEL)||shouldCollectError){let prefix=`${bold(name)}: `;logs.push(prefix+message);}originalFn(...args);};};Object.entries({log:blue,info:blue,warn:yellow,error:red,dir:magenta,trace:magenta,group:magenta,groupCollapsed:magenta,table:magenta,debug:magenta}).forEach(([method,color])=>{spyOnConsole(method,color(method));});let cleanup=_listeners=>{Object.entries(_listeners).forEach(([eventName,listener])=>{channel.off(eventName,listener);});};return new Promise((resolve,reject)=>{let rejectWithFormattedError=(storyId2,message,panel)=>{let errorMessage=StorybookTestRunnerError.buildErrorMessage({storyId:storyId2,errorMessage:message,logs,panel});reject(new StorybookTestRunnerError({storyId:storyId2,errorMessage,logs,isMessageFormatted:!0}));},INTERACTIONS_PANEL="storybook/interactions/panel",A11Y_PANEL="storybook/a11y/panel",listeners={[TEST_RUNNER_RENDERED_EVENT]:data=>{if(cleanup(listeners),hasErrors){rejectWithFormattedError(storyId,"Browser console errors");return}else if(data?.reporters){let story=getStory(),a11yGlobals=story.globals?.a11y,a11yParameter=story.parameters?.a11y,a11yTestParameter=a11yParameter?.test,a11yReport=data.reporters.find(reporter=>reporter.type==="a11y");if(a11yParameter?.disable!==!0&&a11yParameter?.test!=="off"&&a11yGlobals?.manual!==!0&&a11yReport?.result?.violations?.length>0){let violations=expectToHaveNoViolations(a11yReport.result);if(violations&&a11yTestParameter==="error"){rejectWithFormattedError(storyId,violations.long,A11Y_PANEL);return}else if(violations&&a11yTestParameter==="todo"){let warningMessage=StorybookTestRunnerError.buildErrorMessage({storyId,errorMessagePrefix:`--------------------------
|
|
27
|
-
${story.title} > ${story.name}`,errorMessage:yellow(violations.short),logs,panel:A11Y_PANEL});logToPage(warningMessage);}}}resolve(document.getElementById("root"));},storyUnchanged:()=>{cleanup(listeners),resolve(document.getElementById("root"));},storyErrored:({description})=>{cleanup(listeners),rejectWithFormattedError(storyId,description,INTERACTIONS_PANEL);},storyThrewException:error=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},playFunctionThrewException:error=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},unhandledErrorsWhilePlaying:([error])=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},storyMissing:id=>{cleanup(listeners),id===storyId&&rejectWithFormattedError(storyId,"The story was missing when trying to access it.");}};Object.entries(listeners).forEach(([eventName,listener])=>{channel.on(eventName,listener);}),channel.emit("setCurrentStory",{storyId,viewMode:TEST_RUNNER_VIEW_MODE});})}globalThis.__test=__test;});}
|
|
27
|
+
${story.title} > ${story.name}`,errorMessage:yellow(violations.short),logs,panel:A11Y_PANEL});logToPage(warningMessage);}}}resolve(document.getElementById("root"));},storyUnchanged:()=>{cleanup(listeners),resolve(document.getElementById("root"));},storyErrored:({description})=>{cleanup(listeners),rejectWithFormattedError(storyId,description,INTERACTIONS_PANEL);},storyThrewException:error=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},playFunctionThrewException:error=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},unhandledErrorsWhilePlaying:([error])=>{cleanup(listeners),rejectWithFormattedError(storyId,error.message,INTERACTIONS_PANEL);},storyMissing:id=>{cleanup(listeners),id===storyId&&rejectWithFormattedError(storyId,"The story was missing when trying to access it.");}};Object.entries(listeners).forEach(([eventName,listener])=>{channel.on(eventName,listener);}),channel.emit("setCurrentStory",{storyId,viewMode:TEST_RUNNER_VIEW_MODE});})}globalThis.__test=__test;});}function testStory(storyId,page){return async context=>{let _task=context.task;_task.meta.storyId=storyId,await page.evaluate(async storyId2=>await globalThis.__test(storyId2),storyId);}}
|
|
28
28
|
|
|
29
29
|
export { convertToFilePath, prepareScript, setupPageScript, testStory };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-vitest",
|
|
3
|
-
"version": "0.0.0-pr-32047-sha-
|
|
3
|
+
"version": "0.0.0-pr-32047-sha-2c994900",
|
|
4
4
|
"description": "Storybook addon for testing components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook-addons",
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"peerDependencies": {
|
|
130
130
|
"@vitest/browser": "^3.0.0",
|
|
131
131
|
"@vitest/runner": "^3.0.0",
|
|
132
|
-
"storybook": "^0.0.0-pr-32047-sha-
|
|
132
|
+
"storybook": "^0.0.0-pr-32047-sha-2c994900",
|
|
133
133
|
"vitest": "^3.0.0"
|
|
134
134
|
},
|
|
135
135
|
"peerDependenciesMeta": {
|