@argos-ci/storybook 5.2.15 → 5.3.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.
@@ -1,38 +0,0 @@
1
- // src/vitest-setup-file.ts
2
- import { afterEach } from "vitest";
3
-
4
- // src/vitest.ts
5
- function setupArgos(api) {
6
- api.afterEach(async (ctx) => {
7
- const story = "story" in ctx ? ctx.story : null;
8
- if (!story) {
9
- throw new Error(
10
- `@argos-ci/storybook/vitest-plugin should be used with @storybook/addon-vitest/vitest-plugin`
11
- );
12
- }
13
- const { server } = await import("vitest/browser");
14
- globalThis.__ARGOS_STORYBOOK_STORY = story;
15
- await server.commands.argosScreenshot({
16
- mode: "automatic",
17
- name: story.id,
18
- story: {
19
- id: story.id,
20
- parameters: story.parameters,
21
- globals: story.globals
22
- },
23
- test: {
24
- id: ctx.task.id,
25
- title: ctx.task.name,
26
- titlePath: [ctx.task.file.name, ctx.task.name],
27
- location: {
28
- line: ctx.task.location?.line ?? 1,
29
- column: ctx.task.location?.column ?? 1,
30
- file: ctx.task.file.filepath
31
- }
32
- }
33
- });
34
- });
35
- }
36
-
37
- // src/vitest-setup-file.ts
38
- setupArgos({ afterEach });
package/dist/vitest.d.ts DELETED
@@ -1,57 +0,0 @@
1
- import * as vitest from 'vitest';
2
- import { MetadataConfig, ArgosScreenshotOptions as ArgosScreenshotOptions$1, ArgosAttachment } from '@argos-ci/playwright';
3
- import { Page, Frame, ViewportSize } from 'playwright';
4
-
5
- type StorybookGlobals = Record<string, any>;
6
-
7
- type StorybookScreenshotContext<Handler extends Page | Frame> = {
8
- /**
9
- * - "manual" means the `argosScreenshot` has been called in the story play function.
10
- * - "automatic" means the screenshot is taken automatically after each test.
11
- */
12
- mode: "manual" | "automatic";
13
- name: string;
14
- playwrightLibraries: string[];
15
- test?: MetadataConfig["test"];
16
- setViewportSize: (size: ViewportSize | "default" | "initial") => Promise<void>;
17
- beforeScreenshot?: (input: {
18
- handler: Handler;
19
- globals: StorybookGlobals;
20
- }) => Promise<void>;
21
- afterScreenshot?: (input: {
22
- handler: Handler;
23
- globals: StorybookGlobals;
24
- }) => Promise<void>;
25
- story: {
26
- id: string;
27
- parameters: Record<string, any>;
28
- globals: StorybookGlobals | null;
29
- };
30
- };
31
- type ArgosScreenshotOptions = Omit<ArgosScreenshotOptions$1, "viewports">;
32
-
33
- type ArgosScreenshotCommandArgs = [
34
- Pick<StorybookScreenshotContext<Frame>, "name" | "story" | "test" | "mode">
35
- ];
36
-
37
- declare module "vitest/browser" {
38
- interface BrowserCommands {
39
- argosScreenshot: (...args: ArgosScreenshotCommandArgs) => Promise<ArgosAttachment[]>;
40
- }
41
- }
42
- /**
43
- * Setup Argos hooks for Vitest.
44
- */
45
- declare function setupArgos(api: {
46
- afterEach: typeof vitest.afterEach;
47
- }): void;
48
- /**
49
- * Take an Argos screenshot of a story in Vitest.
50
- */
51
- declare function argosScreenshot(story: {
52
- parameters: Record<string, any>;
53
- globals: StorybookGlobals | null;
54
- id: string;
55
- }, name: string): Promise<void>;
56
-
57
- export { type ArgosScreenshotOptions, argosScreenshot, setupArgos };
package/dist/vitest.js DELETED
@@ -1,60 +0,0 @@
1
- // src/vitest.ts
2
- function setupArgos(api) {
3
- api.afterEach(async (ctx) => {
4
- const story = "story" in ctx ? ctx.story : null;
5
- if (!story) {
6
- throw new Error(
7
- `@argos-ci/storybook/vitest-plugin should be used with @storybook/addon-vitest/vitest-plugin`
8
- );
9
- }
10
- const { server } = await import("vitest/browser");
11
- globalThis.__ARGOS_STORYBOOK_STORY = story;
12
- await server.commands.argosScreenshot({
13
- mode: "automatic",
14
- name: story.id,
15
- story: {
16
- id: story.id,
17
- parameters: story.parameters,
18
- globals: story.globals
19
- },
20
- test: {
21
- id: ctx.task.id,
22
- title: ctx.task.name,
23
- titlePath: [ctx.task.file.name, ctx.task.name],
24
- location: {
25
- line: ctx.task.location?.line ?? 1,
26
- column: ctx.task.location?.column ?? 1,
27
- file: ctx.task.file.filepath
28
- }
29
- }
30
- });
31
- });
32
- }
33
- async function argosScreenshot(story, name) {
34
- const isVitest = await checkIsVitestEnv();
35
- if (!isVitest) {
36
- return;
37
- }
38
- const { server } = await import("vitest/browser");
39
- await server.commands.argosScreenshot({
40
- mode: "manual",
41
- name: `${story.id}/${name}`,
42
- story: {
43
- id: story.id,
44
- parameters: story.parameters,
45
- globals: story.globals
46
- }
47
- });
48
- }
49
- async function checkIsVitestEnv() {
50
- try {
51
- await import("vitest");
52
- return true;
53
- } catch {
54
- return false;
55
- }
56
- }
57
- export {
58
- argosScreenshot,
59
- setupArgos
60
- };