@chromatic-com/vitest 0.0.0 → 0.12.8
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/dist/bin/archive-storybook.cjs +210 -0
- package/dist/bin/build-archive-storybook.cjs +210 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.mjs +95 -0
- package/dist/plugin.d.ts +49 -0
- package/dist/plugin.mjs +789 -0
- package/dist/setupFile.mjs +109 -0
- package/dist/storybook-config/main.js +145 -0
- package/dist/storybook-config/manager.js +10 -0
- package/dist/storybook-config/preview.d.ts +278 -0
- package/dist/storybook-config/preview.mjs +81 -0
- package/package.json +79 -8
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../shared/dist/archive-storybook/index.mjs
|
|
28
|
+
var import_child_process = require("child_process");
|
|
29
|
+
var import_path = __toESM(require("path"), 1);
|
|
30
|
+
var import_fs = require("fs");
|
|
31
|
+
var import_promises = require("fs/promises");
|
|
32
|
+
var L = Object.defineProperty;
|
|
33
|
+
var r = /* @__PURE__ */ __name((t, e) => L(t, "name", { value: e, configurable: true }), "r");
|
|
34
|
+
var u = ((t) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(t, { get: (e, o) => (typeof require < "u" ? require : e)[o] }) : t)(function(t) {
|
|
35
|
+
if (typeof require < "u")
|
|
36
|
+
return require.apply(this, arguments);
|
|
37
|
+
throw Error('Dynamic require of "' + t + '" is not supported');
|
|
38
|
+
});
|
|
39
|
+
function V() {
|
|
40
|
+
return process.cwd();
|
|
41
|
+
}
|
|
42
|
+
__name(V, "V");
|
|
43
|
+
r(V, "rootDir");
|
|
44
|
+
function B() {
|
|
45
|
+
let { CHROMATIC_ARCHIVE_LOCATION: t } = process.env;
|
|
46
|
+
return t;
|
|
47
|
+
}
|
|
48
|
+
__name(B, "B");
|
|
49
|
+
r(B, "outputDirOverride");
|
|
50
|
+
function c(t) {
|
|
51
|
+
let e = B() || t;
|
|
52
|
+
return import_path.default.resolve(V(), e, "chromatic-archives");
|
|
53
|
+
}
|
|
54
|
+
__name(c, "c");
|
|
55
|
+
r(c, "archivesDir");
|
|
56
|
+
function f(t) {
|
|
57
|
+
return import_path.default.resolve(c(t), "archive");
|
|
58
|
+
}
|
|
59
|
+
__name(f, "f");
|
|
60
|
+
r(f, "assetsDir");
|
|
61
|
+
function h(t) {
|
|
62
|
+
let e = c(t);
|
|
63
|
+
if (!(0, import_fs.existsSync)(e))
|
|
64
|
+
throw new Error(`Chromatic archives directory cannot be found: ${e}
|
|
65
|
+
|
|
66
|
+
Please make sure that you have run your E2E tests, or have set the CHROMATIC_ARCHIVE_LOCATION env var if the output directory for the tests is not in the standard location.`);
|
|
67
|
+
}
|
|
68
|
+
__name(h, "h");
|
|
69
|
+
r(h, "checkArchivesDirExists");
|
|
70
|
+
function O(t) {
|
|
71
|
+
(0, import_fs.existsSync)(t) || (0, import_fs.mkdirSync)(t, { recursive: true });
|
|
72
|
+
}
|
|
73
|
+
__name(O, "O");
|
|
74
|
+
r(O, "ensureDir");
|
|
75
|
+
async function $(t, e) {
|
|
76
|
+
return O(import_path.default.dirname(t)), (0, import_promises.writeFile)(t, e, { mode: 511 });
|
|
77
|
+
}
|
|
78
|
+
__name($, "$");
|
|
79
|
+
r($, "outputFile");
|
|
80
|
+
async function w(t, e) {
|
|
81
|
+
return $(t, JSON.stringify(e));
|
|
82
|
+
}
|
|
83
|
+
__name(w, "w");
|
|
84
|
+
r(w, "outputJSONFile");
|
|
85
|
+
async function x(t) {
|
|
86
|
+
let e = await (0, import_promises.readFile)(t);
|
|
87
|
+
return JSON.parse(e.toString());
|
|
88
|
+
}
|
|
89
|
+
__name(x, "x");
|
|
90
|
+
r(x, "readJSONFile");
|
|
91
|
+
function a(t) {
|
|
92
|
+
return `w${t.width}h${t.height}`;
|
|
93
|
+
}
|
|
94
|
+
__name(a, "a");
|
|
95
|
+
r(a, "viewportToString");
|
|
96
|
+
function N(t) {
|
|
97
|
+
let e = t.match(/w(\d+)h(\d+)/);
|
|
98
|
+
return { width: Number(e[1]), height: Number(e[2]) };
|
|
99
|
+
}
|
|
100
|
+
__name(N, "N");
|
|
101
|
+
r(N, "parseViewport");
|
|
102
|
+
var M = "snapshot.json";
|
|
103
|
+
function F(t) {
|
|
104
|
+
let e = t.split(".");
|
|
105
|
+
return e.slice(0, e.length - 3).join(".");
|
|
106
|
+
}
|
|
107
|
+
__name(F, "F");
|
|
108
|
+
r(F, "snapshotIdFromFileName");
|
|
109
|
+
function v(t) {
|
|
110
|
+
let e = t.split("."), o = e[e.length - 3];
|
|
111
|
+
return N(o);
|
|
112
|
+
}
|
|
113
|
+
__name(v, "v");
|
|
114
|
+
r(v, "viewportFromFileName");
|
|
115
|
+
async function y(t) {
|
|
116
|
+
return (await (0, import_promises.readdir)(t)).filter((o) => o.endsWith(`.${M}`));
|
|
117
|
+
}
|
|
118
|
+
__name(y, "y");
|
|
119
|
+
r(y, "listSnapshotFiles");
|
|
120
|
+
var J = "stories.json";
|
|
121
|
+
function S(t, e) {
|
|
122
|
+
let { stories: o } = t, n = o.map((i) => {
|
|
123
|
+
let p = i.parameters.server.id, s = e[p];
|
|
124
|
+
return { ...i, parameters: { ...i.parameters, chromatic: { ...i.parameters.chromatic, modes: R(s) }, viewport: { viewports: X(s), defaultViewport: a(W(s)) } } };
|
|
125
|
+
});
|
|
126
|
+
return { ...t, stories: n };
|
|
127
|
+
}
|
|
128
|
+
__name(S, "S");
|
|
129
|
+
r(S, "addViewportsToStories");
|
|
130
|
+
async function E(t) {
|
|
131
|
+
return (await (0, import_promises.readdir)(t)).filter((o) => o.endsWith(`.${J}`));
|
|
132
|
+
}
|
|
133
|
+
__name(E, "E");
|
|
134
|
+
r(E, "listStoriesFiles");
|
|
135
|
+
function R(t) {
|
|
136
|
+
return t.reduce((e, o) => {
|
|
137
|
+
let n = a(o);
|
|
138
|
+
return e[n] = { viewport: n }, e;
|
|
139
|
+
}, {});
|
|
140
|
+
}
|
|
141
|
+
__name(R, "R");
|
|
142
|
+
r(R, "buildStoryModesConfig");
|
|
143
|
+
function X(t) {
|
|
144
|
+
return t.reduce((e, o) => {
|
|
145
|
+
let n = a(o);
|
|
146
|
+
return e[n] = { name: n, styles: { width: `${o.width}px`, height: `${o.height}px` } }, e;
|
|
147
|
+
}, {});
|
|
148
|
+
}
|
|
149
|
+
__name(X, "X");
|
|
150
|
+
r(X, "buildStoryViewportsConfig");
|
|
151
|
+
function W(t) {
|
|
152
|
+
let e = r((o, n) => o.width < n.width ? 1 : o.width > n.width ? -1 : 0, "compareFn");
|
|
153
|
+
return t.sort(e)[0];
|
|
154
|
+
}
|
|
155
|
+
__name(W, "W");
|
|
156
|
+
r(W, "findDefaultViewport");
|
|
157
|
+
async function l(t) {
|
|
158
|
+
let e = f(t), o = await y(e), n = G(o), i = c(t), p = (await E(i)).map((s) => import_path.default.resolve(i, s));
|
|
159
|
+
await Promise.all(p.map(async (s) => {
|
|
160
|
+
let b = await x(s), A = S(b, n);
|
|
161
|
+
await w(s, A);
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
__name(l, "l");
|
|
165
|
+
r(l, "addViewportsToStoriesFiles");
|
|
166
|
+
function G(t) {
|
|
167
|
+
let e = {};
|
|
168
|
+
return t.forEach((o) => {
|
|
169
|
+
let n = F(o), i = e[n] || [];
|
|
170
|
+
i.push(v(o)), e[n] = i;
|
|
171
|
+
}), e;
|
|
172
|
+
}
|
|
173
|
+
__name(G, "G");
|
|
174
|
+
r(G, "buildSnapshotViewportsLookup");
|
|
175
|
+
function It(t, e, o) {
|
|
176
|
+
h(o), l(o).then(() => {
|
|
177
|
+
(0, import_child_process.execFileSync)("node", [T(), "dev", ...t, "-c", e], { stdio: "inherit" });
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
__name(It, "It");
|
|
181
|
+
r(It, "archiveStorybook");
|
|
182
|
+
function kt(t, e, o) {
|
|
183
|
+
h(o), l(o).then(() => {
|
|
184
|
+
(0, import_child_process.execFileSync)("node", [T(), "build", ...t, "-c", e], { stdio: "inherit" });
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
__name(kt, "kt");
|
|
188
|
+
r(kt, "buildArchiveStorybook");
|
|
189
|
+
function T() {
|
|
190
|
+
let t = u("storybook/package.json");
|
|
191
|
+
return (0, import_path.resolve)((0, import_path.dirname)(u.resolve("storybook/package.json")), t.bin.storybook);
|
|
192
|
+
}
|
|
193
|
+
__name(T, "T");
|
|
194
|
+
r(T, "binPath");
|
|
195
|
+
|
|
196
|
+
// src/bin/archive-storybook.ts
|
|
197
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
198
|
+
|
|
199
|
+
// src/constants.ts
|
|
200
|
+
var DEFAULT_OUTPUT_DIR = process.cwd();
|
|
201
|
+
|
|
202
|
+
// src/bin/archive-storybook.ts
|
|
203
|
+
var args = process.argv.slice(2);
|
|
204
|
+
var configDir = import_path2.default.resolve(__dirname, "../storybook-config");
|
|
205
|
+
try {
|
|
206
|
+
It(args, configDir, DEFAULT_OUTPUT_DIR);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
console.error(err.message);
|
|
209
|
+
process.exitCode = 1;
|
|
210
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../shared/dist/archive-storybook/index.mjs
|
|
28
|
+
var import_child_process = require("child_process");
|
|
29
|
+
var import_path = __toESM(require("path"), 1);
|
|
30
|
+
var import_fs = require("fs");
|
|
31
|
+
var import_promises = require("fs/promises");
|
|
32
|
+
var L = Object.defineProperty;
|
|
33
|
+
var r = /* @__PURE__ */ __name((t, e) => L(t, "name", { value: e, configurable: true }), "r");
|
|
34
|
+
var u = ((t) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(t, { get: (e, o) => (typeof require < "u" ? require : e)[o] }) : t)(function(t) {
|
|
35
|
+
if (typeof require < "u")
|
|
36
|
+
return require.apply(this, arguments);
|
|
37
|
+
throw Error('Dynamic require of "' + t + '" is not supported');
|
|
38
|
+
});
|
|
39
|
+
function V() {
|
|
40
|
+
return process.cwd();
|
|
41
|
+
}
|
|
42
|
+
__name(V, "V");
|
|
43
|
+
r(V, "rootDir");
|
|
44
|
+
function B() {
|
|
45
|
+
let { CHROMATIC_ARCHIVE_LOCATION: t } = process.env;
|
|
46
|
+
return t;
|
|
47
|
+
}
|
|
48
|
+
__name(B, "B");
|
|
49
|
+
r(B, "outputDirOverride");
|
|
50
|
+
function c(t) {
|
|
51
|
+
let e = B() || t;
|
|
52
|
+
return import_path.default.resolve(V(), e, "chromatic-archives");
|
|
53
|
+
}
|
|
54
|
+
__name(c, "c");
|
|
55
|
+
r(c, "archivesDir");
|
|
56
|
+
function f(t) {
|
|
57
|
+
return import_path.default.resolve(c(t), "archive");
|
|
58
|
+
}
|
|
59
|
+
__name(f, "f");
|
|
60
|
+
r(f, "assetsDir");
|
|
61
|
+
function h(t) {
|
|
62
|
+
let e = c(t);
|
|
63
|
+
if (!(0, import_fs.existsSync)(e))
|
|
64
|
+
throw new Error(`Chromatic archives directory cannot be found: ${e}
|
|
65
|
+
|
|
66
|
+
Please make sure that you have run your E2E tests, or have set the CHROMATIC_ARCHIVE_LOCATION env var if the output directory for the tests is not in the standard location.`);
|
|
67
|
+
}
|
|
68
|
+
__name(h, "h");
|
|
69
|
+
r(h, "checkArchivesDirExists");
|
|
70
|
+
function O(t) {
|
|
71
|
+
(0, import_fs.existsSync)(t) || (0, import_fs.mkdirSync)(t, { recursive: true });
|
|
72
|
+
}
|
|
73
|
+
__name(O, "O");
|
|
74
|
+
r(O, "ensureDir");
|
|
75
|
+
async function $(t, e) {
|
|
76
|
+
return O(import_path.default.dirname(t)), (0, import_promises.writeFile)(t, e, { mode: 511 });
|
|
77
|
+
}
|
|
78
|
+
__name($, "$");
|
|
79
|
+
r($, "outputFile");
|
|
80
|
+
async function w(t, e) {
|
|
81
|
+
return $(t, JSON.stringify(e));
|
|
82
|
+
}
|
|
83
|
+
__name(w, "w");
|
|
84
|
+
r(w, "outputJSONFile");
|
|
85
|
+
async function x(t) {
|
|
86
|
+
let e = await (0, import_promises.readFile)(t);
|
|
87
|
+
return JSON.parse(e.toString());
|
|
88
|
+
}
|
|
89
|
+
__name(x, "x");
|
|
90
|
+
r(x, "readJSONFile");
|
|
91
|
+
function a(t) {
|
|
92
|
+
return `w${t.width}h${t.height}`;
|
|
93
|
+
}
|
|
94
|
+
__name(a, "a");
|
|
95
|
+
r(a, "viewportToString");
|
|
96
|
+
function N(t) {
|
|
97
|
+
let e = t.match(/w(\d+)h(\d+)/);
|
|
98
|
+
return { width: Number(e[1]), height: Number(e[2]) };
|
|
99
|
+
}
|
|
100
|
+
__name(N, "N");
|
|
101
|
+
r(N, "parseViewport");
|
|
102
|
+
var M = "snapshot.json";
|
|
103
|
+
function F(t) {
|
|
104
|
+
let e = t.split(".");
|
|
105
|
+
return e.slice(0, e.length - 3).join(".");
|
|
106
|
+
}
|
|
107
|
+
__name(F, "F");
|
|
108
|
+
r(F, "snapshotIdFromFileName");
|
|
109
|
+
function v(t) {
|
|
110
|
+
let e = t.split("."), o = e[e.length - 3];
|
|
111
|
+
return N(o);
|
|
112
|
+
}
|
|
113
|
+
__name(v, "v");
|
|
114
|
+
r(v, "viewportFromFileName");
|
|
115
|
+
async function y(t) {
|
|
116
|
+
return (await (0, import_promises.readdir)(t)).filter((o) => o.endsWith(`.${M}`));
|
|
117
|
+
}
|
|
118
|
+
__name(y, "y");
|
|
119
|
+
r(y, "listSnapshotFiles");
|
|
120
|
+
var J = "stories.json";
|
|
121
|
+
function S(t, e) {
|
|
122
|
+
let { stories: o } = t, n = o.map((i) => {
|
|
123
|
+
let p = i.parameters.server.id, s = e[p];
|
|
124
|
+
return { ...i, parameters: { ...i.parameters, chromatic: { ...i.parameters.chromatic, modes: R(s) }, viewport: { viewports: X(s), defaultViewport: a(W(s)) } } };
|
|
125
|
+
});
|
|
126
|
+
return { ...t, stories: n };
|
|
127
|
+
}
|
|
128
|
+
__name(S, "S");
|
|
129
|
+
r(S, "addViewportsToStories");
|
|
130
|
+
async function E(t) {
|
|
131
|
+
return (await (0, import_promises.readdir)(t)).filter((o) => o.endsWith(`.${J}`));
|
|
132
|
+
}
|
|
133
|
+
__name(E, "E");
|
|
134
|
+
r(E, "listStoriesFiles");
|
|
135
|
+
function R(t) {
|
|
136
|
+
return t.reduce((e, o) => {
|
|
137
|
+
let n = a(o);
|
|
138
|
+
return e[n] = { viewport: n }, e;
|
|
139
|
+
}, {});
|
|
140
|
+
}
|
|
141
|
+
__name(R, "R");
|
|
142
|
+
r(R, "buildStoryModesConfig");
|
|
143
|
+
function X(t) {
|
|
144
|
+
return t.reduce((e, o) => {
|
|
145
|
+
let n = a(o);
|
|
146
|
+
return e[n] = { name: n, styles: { width: `${o.width}px`, height: `${o.height}px` } }, e;
|
|
147
|
+
}, {});
|
|
148
|
+
}
|
|
149
|
+
__name(X, "X");
|
|
150
|
+
r(X, "buildStoryViewportsConfig");
|
|
151
|
+
function W(t) {
|
|
152
|
+
let e = r((o, n) => o.width < n.width ? 1 : o.width > n.width ? -1 : 0, "compareFn");
|
|
153
|
+
return t.sort(e)[0];
|
|
154
|
+
}
|
|
155
|
+
__name(W, "W");
|
|
156
|
+
r(W, "findDefaultViewport");
|
|
157
|
+
async function l(t) {
|
|
158
|
+
let e = f(t), o = await y(e), n = G(o), i = c(t), p = (await E(i)).map((s) => import_path.default.resolve(i, s));
|
|
159
|
+
await Promise.all(p.map(async (s) => {
|
|
160
|
+
let b = await x(s), A = S(b, n);
|
|
161
|
+
await w(s, A);
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
__name(l, "l");
|
|
165
|
+
r(l, "addViewportsToStoriesFiles");
|
|
166
|
+
function G(t) {
|
|
167
|
+
let e = {};
|
|
168
|
+
return t.forEach((o) => {
|
|
169
|
+
let n = F(o), i = e[n] || [];
|
|
170
|
+
i.push(v(o)), e[n] = i;
|
|
171
|
+
}), e;
|
|
172
|
+
}
|
|
173
|
+
__name(G, "G");
|
|
174
|
+
r(G, "buildSnapshotViewportsLookup");
|
|
175
|
+
function It(t, e, o) {
|
|
176
|
+
h(o), l(o).then(() => {
|
|
177
|
+
(0, import_child_process.execFileSync)("node", [T(), "dev", ...t, "-c", e], { stdio: "inherit" });
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
__name(It, "It");
|
|
181
|
+
r(It, "archiveStorybook");
|
|
182
|
+
function kt(t, e, o) {
|
|
183
|
+
h(o), l(o).then(() => {
|
|
184
|
+
(0, import_child_process.execFileSync)("node", [T(), "build", ...t, "-c", e], { stdio: "inherit" });
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
__name(kt, "kt");
|
|
188
|
+
r(kt, "buildArchiveStorybook");
|
|
189
|
+
function T() {
|
|
190
|
+
let t = u("storybook/package.json");
|
|
191
|
+
return (0, import_path.resolve)((0, import_path.dirname)(u.resolve("storybook/package.json")), t.bin.storybook);
|
|
192
|
+
}
|
|
193
|
+
__name(T, "T");
|
|
194
|
+
r(T, "binPath");
|
|
195
|
+
|
|
196
|
+
// src/bin/build-archive-storybook.ts
|
|
197
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
198
|
+
|
|
199
|
+
// src/constants.ts
|
|
200
|
+
var DEFAULT_OUTPUT_DIR = process.cwd();
|
|
201
|
+
|
|
202
|
+
// src/bin/build-archive-storybook.ts
|
|
203
|
+
var args = process.argv.slice(2);
|
|
204
|
+
var configDir = import_path2.default.resolve(__dirname, "../storybook-config");
|
|
205
|
+
try {
|
|
206
|
+
kt(args, configDir, DEFAULT_OUTPUT_DIR);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
console.error(err.message);
|
|
209
|
+
process.exitCode = 1;
|
|
210
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Take visual regression snapshot of the current state of the DOM.
|
|
3
|
+
*/
|
|
4
|
+
declare function takeSnapshot(name?: string): Promise<void>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Disable automatic test snapshotting
|
|
8
|
+
* - When called within `test()`, it disables snapshotting for that test.
|
|
9
|
+
* - When called within `describe()`, it disables snapshotting for all tests within that describe block.
|
|
10
|
+
* - When called at the top level, it disables snapshotting for all tests in the file.
|
|
11
|
+
*/
|
|
12
|
+
declare function disableAutoSnapshot(): void;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Wait for network to be idle, meaning no new network requests for at least `idleNetworkInterval` ms.
|
|
16
|
+
*
|
|
17
|
+
* The `idleNetworkInterval` can be configured via the Chromatic plugin's options.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* export default defineConfig({
|
|
21
|
+
* plugins: [chromaticPlugin({ idleNetworkInterval: 50 })]
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Use `timeout` argument to reject if network doesn't become idle within given time.
|
|
26
|
+
*/
|
|
27
|
+
declare function waitForIdleNetwork(timeout: number): Promise<void>;
|
|
28
|
+
|
|
29
|
+
export { disableAutoSnapshot, takeSnapshot, waitForIdleNetwork };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/browser/public/takeSnapshot.ts
|
|
5
|
+
import { assert } from "vitest";
|
|
6
|
+
import { commands } from "vitest/browser";
|
|
7
|
+
import { snapshot } from "@chromaui/rrweb-snapshot";
|
|
8
|
+
|
|
9
|
+
// src/browser/getCurrentTest.ts
|
|
10
|
+
import * as vitest from "vitest";
|
|
11
|
+
var hooks = vitest.TestRunner ? vitest.TestRunner : await import("vitest/suite");
|
|
12
|
+
function getCurrentTest() {
|
|
13
|
+
return hooks.getCurrentTest();
|
|
14
|
+
}
|
|
15
|
+
__name(getCurrentTest, "getCurrentTest");
|
|
16
|
+
|
|
17
|
+
// src/browser/public/takeSnapshot.ts
|
|
18
|
+
async function takeSnapshot(name) {
|
|
19
|
+
const test = getCurrentTest();
|
|
20
|
+
assert(test, "takeSnapshot() must be called within a test()");
|
|
21
|
+
test.meta.__chromatic_isTakeSnapshotCalled = true;
|
|
22
|
+
if (!test.meta.__chromatic_isRegistered) {
|
|
23
|
+
throw new Error("takeSnapshot() cannot be called in a test that is not registered for Chromatic plugin");
|
|
24
|
+
}
|
|
25
|
+
const domSnapshot = snapshot(document, {
|
|
26
|
+
recordCanvas: true
|
|
27
|
+
});
|
|
28
|
+
assert(domSnapshot, "Failed to capture DOM snapshot");
|
|
29
|
+
await replaceBlobUrls(domSnapshot);
|
|
30
|
+
await commands.__chromatic_uploadDOMSnapshot(test.id, domSnapshot, name);
|
|
31
|
+
}
|
|
32
|
+
__name(takeSnapshot, "takeSnapshot");
|
|
33
|
+
async function replaceBlobUrls(node) {
|
|
34
|
+
if (!("childNodes" in node)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
await Promise.all(node.childNodes.map(async (childNode) => {
|
|
38
|
+
if ("tagName" in childNode && childNode.tagName === "img" && typeof childNode.attributes.src === "string" && childNode.attributes.src?.startsWith("blob:")) {
|
|
39
|
+
const base64Url = await toDataURL(childNode.attributes.src);
|
|
40
|
+
childNode.attributes.src = base64Url;
|
|
41
|
+
}
|
|
42
|
+
if ("childNodes" in childNode && childNode.childNodes?.length) {
|
|
43
|
+
await replaceBlobUrls(childNode);
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
__name(replaceBlobUrls, "replaceBlobUrls");
|
|
48
|
+
async function toDataURL(url) {
|
|
49
|
+
const blob = await fetch(url).then((res) => res.blob());
|
|
50
|
+
return new Promise((resolveFileRead, reject) => {
|
|
51
|
+
const reader = new FileReader();
|
|
52
|
+
reader.onloadend = () => resolveFileRead(reader.result?.toString() || "");
|
|
53
|
+
reader.onerror = reject;
|
|
54
|
+
reader.readAsDataURL(blob);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
__name(toDataURL, "toDataURL");
|
|
58
|
+
|
|
59
|
+
// src/browser/public/autoSnapshot.ts
|
|
60
|
+
import { beforeAll } from "vitest";
|
|
61
|
+
function disableAutoSnapshot() {
|
|
62
|
+
const test = getCurrentTest();
|
|
63
|
+
if (test) {
|
|
64
|
+
test.meta.__chromatic_autoSnapshot = false;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
beforeAll(({}, suite) => {
|
|
68
|
+
traverseTests(suite);
|
|
69
|
+
function traverseTests(task) {
|
|
70
|
+
if (task.type === "test") {
|
|
71
|
+
task.meta.__chromatic_autoSnapshot = false;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
task.tasks.forEach(traverseTests);
|
|
75
|
+
}
|
|
76
|
+
__name(traverseTests, "traverseTests");
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
__name(disableAutoSnapshot, "disableAutoSnapshot");
|
|
80
|
+
|
|
81
|
+
// src/browser/public/waitForIdleNetwork.ts
|
|
82
|
+
import { assert as assert2 } from "vitest";
|
|
83
|
+
import { commands as commands2 } from "vitest/browser";
|
|
84
|
+
async function waitForIdleNetwork(timeout) {
|
|
85
|
+
const test = getCurrentTest();
|
|
86
|
+
assert2(test, "waitForIdleNetwork() must be called within a test()");
|
|
87
|
+
assert2(test.meta.__chromatic_isRegistered, "Cannot call waitForIdleNetwork for a test that hasn't been registered with the Chromatic plugin");
|
|
88
|
+
return await commands2.__chromatic_waitForIdleNetwork(test.id, timeout);
|
|
89
|
+
}
|
|
90
|
+
__name(waitForIdleNetwork, "waitForIdleNetwork");
|
|
91
|
+
export {
|
|
92
|
+
disableAutoSnapshot,
|
|
93
|
+
takeSnapshot,
|
|
94
|
+
waitForIdleNetwork
|
|
95
|
+
};
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Vite } from 'vitest/node';
|
|
2
|
+
|
|
3
|
+
interface ChromaticConfig {
|
|
4
|
+
delay?: number;
|
|
5
|
+
diffIncludeAntiAliasing?: boolean;
|
|
6
|
+
diffThreshold?: number;
|
|
7
|
+
disableAutoSnapshot?: boolean;
|
|
8
|
+
forcedColors?: string;
|
|
9
|
+
pauseAnimationAtEnd?: boolean;
|
|
10
|
+
prefersReducedMotion?: string;
|
|
11
|
+
resourceArchiveTimeout?: number;
|
|
12
|
+
assetDomains?: string[];
|
|
13
|
+
cropToViewport?: boolean;
|
|
14
|
+
ignoreSelectors?: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Options for the Chromatic Vitest plugin
|
|
19
|
+
*/
|
|
20
|
+
interface Options extends ChromaticConfig {
|
|
21
|
+
/**
|
|
22
|
+
* Tags used to register tests for visual regression tracking.
|
|
23
|
+
* If specified, only tests with at least one matching tag will be registered for visual regression tracking.
|
|
24
|
+
* Tests without any of the specified tags will be ignored and won't have snapshots taken, even if `disableAutoSnapshot` is false.
|
|
25
|
+
*
|
|
26
|
+
* @default none (all tests are registered)
|
|
27
|
+
*/
|
|
28
|
+
tags?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Directory where temporary archives and snapshots will be stored.
|
|
31
|
+
*
|
|
32
|
+
* Defaults to `chromatic-archives` in the current working directory.
|
|
33
|
+
*/
|
|
34
|
+
outputDirectory?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Time in milliseconds to determine whether network is idle.
|
|
37
|
+
* The network is considered idle if there are no new network requests for at least this duration.
|
|
38
|
+
*
|
|
39
|
+
* @default 100
|
|
40
|
+
*/
|
|
41
|
+
idleNetworkInterval?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Vitest plugin for integrating with Chromatic's visual regression testing.
|
|
46
|
+
*/
|
|
47
|
+
declare function chromaticPlugin(userOptions?: Options): Vite.Plugin;
|
|
48
|
+
|
|
49
|
+
export { chromaticPlugin };
|