storybook_vitest_addon 0.0.1

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/.babelrc.js ADDED
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ presets: [
3
+ "@babel/preset-env",
4
+ "@babel/preset-typescript",
5
+ "@babel/preset-react",
6
+ ],
7
+ env: {
8
+ esm: {
9
+ presets: [
10
+ [
11
+ "@babel/preset-env",
12
+ {
13
+ modules: false,
14
+ },
15
+ ],
16
+ ],
17
+ },
18
+ },
19
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # v0.0.1 (Sun Mar 27 2022)
2
+
3
+ #### ⚠️ Pushed to `main`
4
+
5
+ - remove postinstall script (krzysztof.radomski@netigate.se)
6
+ - initial commit (krzysztof.radomski@netigate.se)
7
+ - project setup (krzysztof.radomski@netigate.se)
8
+ - Initial commit ([@krzysztofradomski](https://github.com/krzysztofradomski))
9
+
10
+ #### Authors: 2
11
+
12
+ - Krzysztof "Chris" Radomski ([@krzysztofradomski](https://github.com/krzysztofradomski))
13
+ - Krzysztof Radomski (krzysztof.radomski@netigate.se)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Storybook contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ Addon meant to display Vitest unit test results in a new Stoybook panel. Developed and tested with React.
2
+
3
+ Example usage:
4
+
5
+ ```
6
+ // Component.stories.tsx
7
+
8
+ import vitestResults from "./unit-test-results.json";
9
+ /.../
10
+ export default {
11
+ title: "Example/Component",
12
+ component: Header,
13
+ parameters: {
14
+ vitest: {
15
+ testFile: "Header.test.tsx",
16
+ results: vitestResults,
17
+ },
18
+ },
19
+ };
20
+ /.../
21
+ ```
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _api = require("@storybook/api");
11
+
12
+ var _constants = require("./constants");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
16
+ var VitestPanel = function VitestPanel() {
17
+ var _json$testResults;
18
+
19
+ var params = (0, _api.useParameter)(_constants.PARAM_KEY, null);
20
+ var fileName = (params === null || params === void 0 ? void 0 : params.testFile) || null;
21
+ var json = (params === null || params === void 0 ? void 0 : params.results) || null;
22
+ var data = json === null || json === void 0 ? void 0 : (_json$testResults = json.testResults) === null || _json$testResults === void 0 ? void 0 : _json$testResults.filter(function (t) {
23
+ return t.testFilePath.includes(fileName);
24
+ }).map(function (t) {
25
+ return {
26
+ status: t.status,
27
+ displayName: t.displayName
28
+ };
29
+ });
30
+ return /*#__PURE__*/_react["default"].createElement("ul", null, !data && /*#__PURE__*/_react["default"].createElement("li", null, "No test results file available"), (data === null || data === void 0 ? void 0 : data.length) == 0 && /*#__PURE__*/_react["default"].createElement("li", null, "No tests found"), data === null || data === void 0 ? void 0 : data.map(function (d) {
31
+ return /*#__PURE__*/_react["default"].createElement("li", {
32
+ key: d.displayName
33
+ }, /*#__PURE__*/_react["default"].createElement("p", null, d.displayName, /*#__PURE__*/_react["default"].createElement("span", {
34
+ style: {
35
+ color: d.status === "pass" ? "green" : "red"
36
+ }
37
+ }, d.status)));
38
+ }));
39
+ };
40
+
41
+ var _default = VitestPanel;
42
+ exports["default"] = _default;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PARAM_KEY = exports.PANEL_ID = exports.ADDON_ID = void 0;
7
+ var ADDON_ID = "storybook/vitest";
8
+ exports.ADDON_ID = ADDON_ID;
9
+ var PANEL_ID = "".concat(ADDON_ID, "/panel");
10
+ exports.PANEL_ID = PANEL_ID;
11
+ var PARAM_KEY = "vitest";
12
+ exports.PARAM_KEY = PARAM_KEY;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ if (module && module.hot && module.hot.decline) {
9
+ module.hot.decline();
10
+ } // make it work with --isolatedModules
11
+
12
+
13
+ var _default = {};
14
+ exports["default"] = _default;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _addons = require("@storybook/addons");
4
+
5
+ var _constants = require("../constants");
6
+
7
+ var _Panel = _interopRequireDefault(require("../Panel"));
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+
11
+ _addons.addons.register(_constants.ADDON_ID, function () {
12
+ _addons.addons.add(_constants.PANEL_ID, {
13
+ type: _addons.types.PANEL,
14
+ title: "Tests results",
15
+ match: function match(_ref) {
16
+ var viewMode = _ref.viewMode;
17
+ return viewMode === "story";
18
+ },
19
+ render: _Panel["default"]
20
+ });
21
+ });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.decorators = void 0;
7
+ var decorators = [];
8
+ exports.decorators = decorators;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import { useParameter } from "@storybook/api";
3
+ import { PARAM_KEY } from "./constants";
4
+
5
+ var VitestPanel = function VitestPanel() {
6
+ var _json$testResults;
7
+
8
+ var params = useParameter(PARAM_KEY, null);
9
+ var fileName = (params === null || params === void 0 ? void 0 : params.testFile) || null;
10
+ var json = (params === null || params === void 0 ? void 0 : params.results) || null;
11
+ var data = json === null || json === void 0 ? void 0 : (_json$testResults = json.testResults) === null || _json$testResults === void 0 ? void 0 : _json$testResults.filter(function (t) {
12
+ return t.testFilePath.includes(fileName);
13
+ }).map(function (t) {
14
+ return {
15
+ status: t.status,
16
+ displayName: t.displayName
17
+ };
18
+ });
19
+ return /*#__PURE__*/React.createElement("ul", null, !data && /*#__PURE__*/React.createElement("li", null, "No test results file available"), (data === null || data === void 0 ? void 0 : data.length) == 0 && /*#__PURE__*/React.createElement("li", null, "No tests found"), data === null || data === void 0 ? void 0 : data.map(function (d) {
20
+ return /*#__PURE__*/React.createElement("li", {
21
+ key: d.displayName
22
+ }, /*#__PURE__*/React.createElement("p", null, d.displayName, /*#__PURE__*/React.createElement("span", {
23
+ style: {
24
+ color: d.status === "pass" ? "green" : "red"
25
+ }
26
+ }, d.status)));
27
+ }));
28
+ };
29
+
30
+ export default VitestPanel;
@@ -0,0 +1,3 @@
1
+ export var ADDON_ID = "storybook/vitest";
2
+ export var PANEL_ID = "".concat(ADDON_ID, "/panel");
3
+ export var PARAM_KEY = "vitest";
@@ -0,0 +1,6 @@
1
+ if (module && module.hot && module.hot.decline) {
2
+ module.hot.decline();
3
+ } // make it work with --isolatedModules
4
+
5
+
6
+ export default {};
@@ -0,0 +1,14 @@
1
+ import { addons, types } from "@storybook/addons";
2
+ import { ADDON_ID, PANEL_ID } from "../constants";
3
+ import Panel from "../Panel";
4
+ addons.register(ADDON_ID, function () {
5
+ addons.add(PANEL_ID, {
6
+ type: types.PANEL,
7
+ title: "Tests results",
8
+ match: function match(_ref) {
9
+ var viewMode = _ref.viewMode;
10
+ return viewMode === "story";
11
+ },
12
+ render: Panel
13
+ });
14
+ });
@@ -0,0 +1 @@
1
+ export var decorators = [];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const VitestPanel: () => JSX.Element;
3
+ export default VitestPanel;
@@ -0,0 +1,3 @@
1
+ export declare const ADDON_ID = "storybook/vitest";
2
+ export declare const PANEL_ID: string;
3
+ export declare const PARAM_KEY = "vitest";
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const decorators: any[];
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "storybook_vitest_addon",
3
+ "version": "0.0.1",
4
+ "description": "Adds a panel to display Vitest unit test results",
5
+ "keywords": [
6
+ "storybook-addons",
7
+ "vitest",
8
+ "storybook-addons"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/krzysztofradomski/storybook-addon-vitest"
13
+ },
14
+ "author": "Krzysztof Radomski <krzysztof@radomski.io>",
15
+ "license": "MIT",
16
+ "main": "dist/cjs/index.js",
17
+ "module": "dist/esm/index.js",
18
+ "types": "dist/ts/index.d.ts",
19
+ "files": [
20
+ "dist/**/*",
21
+ "README.md",
22
+ "*.js",
23
+ "*.d.ts"
24
+ ],
25
+ "scripts": {
26
+ "clean": "rimraf ./dist",
27
+ "buildBabel": "concurrently \"yarn buildBabel:cjs\" \"yarn buildBabel:esm\"",
28
+ "buildBabel:cjs": "babel ./src -d ./dist/cjs --extensions \".js,.jsx,.ts,.tsx\"",
29
+ "buildBabel:esm": "babel ./src -d ./dist/esm --env-name esm --extensions \".js,.jsx,.ts,.tsx\"",
30
+ "buildTsc": "tsc --declaration --emitDeclarationOnly --outDir ./dist/ts",
31
+ "prebuild": "yarn clean",
32
+ "build": "concurrently \"yarn buildBabel\" \"yarn buildTsc\"",
33
+ "build:watch": "concurrently \"yarn buildBabel:esm -- --watch\" \"yarn buildTsc -- --watch\"",
34
+ "test": "echo \"Error: no test specified\" && exit 1",
35
+ "storybook": "start-storybook -p 6006",
36
+ "start": "concurrently \"yarn build:watch\" \"yarn storybook -- --no-manager-cache --quiet\"",
37
+ "build-storybook": "build-storybook",
38
+ "prerelease": "zx scripts/prepublish-checks.mjs",
39
+ "release": "yarn build && auto shipit",
40
+ "eject-ts": "zx scripts/eject-typescript.mjs"
41
+ },
42
+ "devDependencies": {
43
+ "@babel/cli": "^7.12.1",
44
+ "@babel/core": "^7.12.3",
45
+ "@babel/preset-env": "^7.12.1",
46
+ "@babel/preset-react": "^7.12.5",
47
+ "@babel/preset-typescript": "^7.13.0",
48
+ "@storybook/addon-essentials": "^6.4.0",
49
+ "@storybook/react": "^6.4.0",
50
+ "auto": "^10.3.0",
51
+ "babel-loader": "^8.1.0",
52
+ "boxen": "^5.0.1",
53
+ "concurrently": "^6.2.0",
54
+ "dedent": "^0.7.0",
55
+ "prettier": "^2.3.1",
56
+ "prop-types": "^15.7.2",
57
+ "react": "^17.0.1",
58
+ "react-dom": "^17.0.1",
59
+ "rimraf": "^3.0.2",
60
+ "typescript": "^4.2.4",
61
+ "zx": "^1.14.1"
62
+ },
63
+ "peerDependencies": {
64
+ "@storybook/addons": "^6.4.0",
65
+ "@storybook/api": "^6.4.0",
66
+ "@storybook/components": "^6.4.0",
67
+ "@storybook/core-events": "^6.4.0",
68
+ "@storybook/theming": "^6.4.0",
69
+ "react": "^16.8.0 || ^17.0.0",
70
+ "react-dom": "^16.8.0 || ^17.0.0"
71
+ },
72
+ "peerDependenciesMeta": {
73
+ "react": {
74
+ "optional": true
75
+ },
76
+ "react-dom": {
77
+ "optional": true
78
+ }
79
+ },
80
+ "publishConfig": {
81
+ "access": "public"
82
+ },
83
+ "storybook": {
84
+ "displayName": "Storybook Vitest",
85
+ "supportedFrameworks": [
86
+ "react"
87
+ ],
88
+ "icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png"
89
+ },
90
+ "dependencies": {}
91
+ }
package/preset.js ADDED
@@ -0,0 +1,12 @@
1
+ function config(entry = []) {
2
+ return [...entry, require.resolve("./dist/esm/preset/preview")];
3
+ }
4
+
5
+ function managerEntries(entry = []) {
6
+ return [...entry, require.resolve("./dist/esm/preset/manager")];
7
+ }
8
+
9
+ module.exports = {
10
+ managerEntries,
11
+ config,
12
+ };