@argos-ci/storybook 0.1.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/LICENSE +7 -0
- package/README.md +20 -0
- package/dist/index.cjs +7 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.mjs +57 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2022 Smooth Code
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://argos-ci.com/?utm_source=github&utm_medium=logo" target="_blank">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/argos-ci/argos/main/resources/logos/logo-github-readme.png" alt="Argos" width="300" height="61">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
_Argos is a visual testing solution that fits in your workflow to avoid visual regression. Takes screenshots on each commit and be notified if something changes._
|
|
8
|
+
|
|
9
|
+
# Official Argos Storybook integration
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/@argos-ci/storybook)
|
|
12
|
+
[](https://www.npmjs.com/package/@argos-ci/storybook)
|
|
13
|
+
[](https://www.npmjs.com/package/@argos-ci/storybook)
|
|
14
|
+
|
|
15
|
+
Visit [argos-ci.com/docs/storybook](https://argos-ci.com/docs/storybook) for guides, API and more.
|
|
16
|
+
|
|
17
|
+
## Links
|
|
18
|
+
|
|
19
|
+
- [Official SDK Docs](https://argos-ci.com/docs/)
|
|
20
|
+
- [Discord](https://argos-ci.com/discord)
|
package/dist/index.cjs
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TestContext } from "@storybook/test-runner";
|
|
2
|
+
import { ArgosScreenshotOptions as ArgosPlaywrightScreenshotOptions } from "@argos-ci/playwright";
|
|
3
|
+
import { Page } from "playwright";
|
|
4
|
+
type ArgosScreenshotOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Fit the screenshot to the content size.
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
fitToContent?: boolean | {
|
|
10
|
+
/**
|
|
11
|
+
* Padding around the content in pixels.
|
|
12
|
+
* @default 16
|
|
13
|
+
*/
|
|
14
|
+
padding?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Zoom level.
|
|
17
|
+
* @default 2
|
|
18
|
+
*/
|
|
19
|
+
zoom?: number;
|
|
20
|
+
};
|
|
21
|
+
} & ArgosPlaywrightScreenshotOptions;
|
|
22
|
+
/**
|
|
23
|
+
* Stabilize the UI and takes a screenshot of the application under test.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* argosScreenshot(page, "my-screenshot")
|
|
27
|
+
* @see https://argos-ci.com/docs/playwright#api-overview
|
|
28
|
+
*/
|
|
29
|
+
declare function argosScreenshot(
|
|
30
|
+
/**
|
|
31
|
+
* Playwright `page` object.
|
|
32
|
+
*/
|
|
33
|
+
page: Page,
|
|
34
|
+
/**
|
|
35
|
+
* Context of the test.
|
|
36
|
+
*/
|
|
37
|
+
context: TestContext,
|
|
38
|
+
/**
|
|
39
|
+
* Options for the screenshot.
|
|
40
|
+
*/
|
|
41
|
+
options?: ArgosScreenshotOptions): Promise<void>;
|
|
42
|
+
export { ArgosScreenshotOptions, argosScreenshot };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { waitForPageReady } from '@storybook/test-runner';
|
|
2
|
+
import { DO_NOT_USE_setMetadataConfig, argosScreenshot as argosScreenshot$1 } from '@argos-ci/playwright';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { readVersionFromPackage } from '@argos-ci/util';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
/**
|
|
9
|
+
* Get the version of the Argos Playwright SDK.
|
|
10
|
+
*/ async function getArgosStorybookVersion() {
|
|
11
|
+
const pkgPath = require.resolve("@argos-ci/storybook/package.json");
|
|
12
|
+
return readVersionFromPackage(pkgPath);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Stabilize the UI and takes a screenshot of the application under test.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* argosScreenshot(page, "my-screenshot")
|
|
20
|
+
* @see https://argos-ci.com/docs/playwright#api-overview
|
|
21
|
+
*/ async function argosScreenshot(/**
|
|
22
|
+
* Playwright `page` object.
|
|
23
|
+
*/ page, /**
|
|
24
|
+
* Context of the test.
|
|
25
|
+
*/ context, /**
|
|
26
|
+
* Options for the screenshot.
|
|
27
|
+
*/ options) {
|
|
28
|
+
const { fitToContent = true, ...screenshotOptions } = options ?? {};
|
|
29
|
+
await waitForPageReady(page);
|
|
30
|
+
const fitToContentOptions = (()=>{
|
|
31
|
+
if (options?.element || !fitToContent) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
const { padding = 16, zoom = 2 } = fitToContent === true ? {} : fitToContent;
|
|
35
|
+
return {
|
|
36
|
+
element: "#storybook-root",
|
|
37
|
+
argosCSS: `#storybook-root { padding: ${padding}px; width: fit-content; height: fit-content; zoom: ${zoom}; }` + (options?.argosCSS ?? "")
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
const version = await getArgosStorybookVersion();
|
|
41
|
+
await DO_NOT_USE_setMetadataConfig({
|
|
42
|
+
sdk: {
|
|
43
|
+
name: "@argos-ci/storybook",
|
|
44
|
+
version
|
|
45
|
+
},
|
|
46
|
+
playwrightLibraries: [
|
|
47
|
+
"playwright",
|
|
48
|
+
"playwright-core"
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
await argosScreenshot$1(page, join(context.title, context.name), {
|
|
52
|
+
...screenshotOptions,
|
|
53
|
+
...fitToContentOptions
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { argosScreenshot };
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@argos-ci/storybook",
|
|
3
|
+
"description": "Visual testing for Storybook test runner.",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": "Smooth Code",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/argos-ci/argos-javascript.git",
|
|
10
|
+
"directory": "packages/storybook"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://argos-ci.com/docs/storybook",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"storybook",
|
|
15
|
+
"storybook-addon",
|
|
16
|
+
"screenshot",
|
|
17
|
+
"capture",
|
|
18
|
+
"testing",
|
|
19
|
+
"visual testing",
|
|
20
|
+
"argos",
|
|
21
|
+
"regression",
|
|
22
|
+
"visual regression"
|
|
23
|
+
],
|
|
24
|
+
"bin": {
|
|
25
|
+
"argos-storybook": "./bin/argos-storybook.js"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"require": "./dist/index.cjs",
|
|
36
|
+
"import": "./dist/index.mjs",
|
|
37
|
+
"default": "./dist/index.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18.16.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@argos-ci/playwright": "3.8.0",
|
|
46
|
+
"@argos-ci/util": "2.1.2"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@storybook/test-runner": "*",
|
|
50
|
+
"playwright": "*"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@argos-ci/cli": "2.4.7",
|
|
54
|
+
"@argos-ci/util": "workspace:*",
|
|
55
|
+
"@storybook/addon-essentials": "^8.3.6",
|
|
56
|
+
"@storybook/addon-interactions": "^8.3.6",
|
|
57
|
+
"@storybook/addon-links": "^8.3.6",
|
|
58
|
+
"@storybook/blocks": "^8.3.6",
|
|
59
|
+
"@storybook/react": "^8.3.6",
|
|
60
|
+
"@storybook/react-vite": "^8.3.6",
|
|
61
|
+
"@storybook/test": "^8.3.6",
|
|
62
|
+
"@storybook/test-runner": "^0.19.1",
|
|
63
|
+
"playwright": "^1.48.1",
|
|
64
|
+
"prop-types": "^15.8.1",
|
|
65
|
+
"storybook": "^8.3.6"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"prebuild": "rm -rf dist",
|
|
69
|
+
"build": "rollup -c",
|
|
70
|
+
"storybook": "storybook dev -p 6006",
|
|
71
|
+
"build-storybook": "storybook build",
|
|
72
|
+
"test-storybook": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-vm-modules test-storybook",
|
|
73
|
+
"argos-upload": "pnpm exec argos upload screenshots --build-name \"argos-storybook-e2e-node-$NODE_VERSION-$OS\"",
|
|
74
|
+
"e2e": "pnpm run test-storybook && pnpm run argos-upload"
|
|
75
|
+
},
|
|
76
|
+
"gitHead": "d0fa8cd790ffd2343d1cd32706bcb757c4f3b26e"
|
|
77
|
+
}
|