@chromatic-com/vitest 0.0.1 → 0.0.2-0473a2c-20260422103524
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.js +17 -189
- package/dist/bin/build-archive-storybook.js +17 -189
- package/dist/plugin.js +84 -21
- package/dist/storybook-config/main.js +1 -12
- package/package.json +1 -1
|
@@ -12,9 +12,8 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
12
12
|
// ../shared/dist/archive-storybook/index.mjs
|
|
13
13
|
import { execFileSync } from "child_process";
|
|
14
14
|
import path, { resolve, dirname } from "path";
|
|
15
|
-
import { readFileSync, existsSync
|
|
15
|
+
import { readFileSync, existsSync } from "fs";
|
|
16
16
|
import { createRequire } from "module";
|
|
17
|
-
import { writeFile, readFile, readdir } from "fs/promises";
|
|
18
17
|
var __defProp2 = Object.defineProperty;
|
|
19
18
|
var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
|
|
20
19
|
var __require2 = /* @__PURE__ */ ((x) => typeof __require !== "undefined" ? __require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
@@ -41,11 +40,6 @@ function archivesDir(defaultOutputDir) {
|
|
|
41
40
|
}
|
|
42
41
|
__name(archivesDir, "archivesDir");
|
|
43
42
|
__name2(archivesDir, "archivesDir");
|
|
44
|
-
function assetsDir(defaultOutputDir) {
|
|
45
|
-
return path.resolve(archivesDir(defaultOutputDir), "archive");
|
|
46
|
-
}
|
|
47
|
-
__name(assetsDir, "assetsDir");
|
|
48
|
-
__name2(assetsDir, "assetsDir");
|
|
49
43
|
function checkArchivesDirExists(defaultOutputDir) {
|
|
50
44
|
const dir = archivesDir(defaultOutputDir);
|
|
51
45
|
if (!existsSync(dir)) {
|
|
@@ -56,197 +50,31 @@ Please make sure that you have run your E2E tests, or have set the CHROMATIC_ARC
|
|
|
56
50
|
}
|
|
57
51
|
__name(checkArchivesDirExists, "checkArchivesDirExists");
|
|
58
52
|
__name2(checkArchivesDirExists, "checkArchivesDirExists");
|
|
59
|
-
function ensureDir(directory) {
|
|
60
|
-
if (!existsSync(directory)) {
|
|
61
|
-
mkdirSync(directory, {
|
|
62
|
-
recursive: true
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
__name(ensureDir, "ensureDir");
|
|
67
|
-
__name2(ensureDir, "ensureDir");
|
|
68
|
-
async function outputFile(filePath, data) {
|
|
69
|
-
ensureDir(path.dirname(filePath));
|
|
70
|
-
return writeFile(filePath, data, {
|
|
71
|
-
mode: 511
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
__name(outputFile, "outputFile");
|
|
75
|
-
__name2(outputFile, "outputFile");
|
|
76
|
-
async function outputJSONFile(filePath, data) {
|
|
77
|
-
return outputFile(filePath, JSON.stringify(data));
|
|
78
|
-
}
|
|
79
|
-
__name(outputJSONFile, "outputJSONFile");
|
|
80
|
-
__name2(outputJSONFile, "outputJSONFile");
|
|
81
|
-
async function readJSONFile(filePath) {
|
|
82
|
-
const data = await readFile(filePath);
|
|
83
|
-
return JSON.parse(data.toString());
|
|
84
|
-
}
|
|
85
|
-
__name(readJSONFile, "readJSONFile");
|
|
86
|
-
__name2(readJSONFile, "readJSONFile");
|
|
87
|
-
function viewportToString(viewport) {
|
|
88
|
-
return `w${viewport.width}h${viewport.height}`;
|
|
89
|
-
}
|
|
90
|
-
__name(viewportToString, "viewportToString");
|
|
91
|
-
__name2(viewportToString, "viewportToString");
|
|
92
|
-
function parseViewport(viewportString) {
|
|
93
|
-
const matcher = viewportString.match(/w(\d+)h(\d+)/);
|
|
94
|
-
return {
|
|
95
|
-
width: Number(matcher[1]),
|
|
96
|
-
height: Number(matcher[2])
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
__name(parseViewport, "parseViewport");
|
|
100
|
-
__name2(parseViewport, "parseViewport");
|
|
101
|
-
var SNAPSHOT_FILE_EXT = "snapshot.json";
|
|
102
|
-
function snapshotIdFromFileName(fileName) {
|
|
103
|
-
const fileParts = fileName.split(".");
|
|
104
|
-
return fileParts.slice(0, fileParts.length - 3).join(".");
|
|
105
|
-
}
|
|
106
|
-
__name(snapshotIdFromFileName, "snapshotIdFromFileName");
|
|
107
|
-
__name2(snapshotIdFromFileName, "snapshotIdFromFileName");
|
|
108
|
-
function viewportFromFileName(fileName) {
|
|
109
|
-
const fileParts = fileName.split(".");
|
|
110
|
-
const viewportStr = fileParts[fileParts.length - 3];
|
|
111
|
-
return parseViewport(viewportStr);
|
|
112
|
-
}
|
|
113
|
-
__name(viewportFromFileName, "viewportFromFileName");
|
|
114
|
-
__name2(viewportFromFileName, "viewportFromFileName");
|
|
115
|
-
async function listSnapshotFiles(snapshotsDir) {
|
|
116
|
-
const files = await readdir(snapshotsDir);
|
|
117
|
-
return files.filter((file) => file.endsWith(`.${SNAPSHOT_FILE_EXT}`));
|
|
118
|
-
}
|
|
119
|
-
__name(listSnapshotFiles, "listSnapshotFiles");
|
|
120
|
-
__name2(listSnapshotFiles, "listSnapshotFiles");
|
|
121
|
-
var STORIES_FILE_EXT = "stories.json";
|
|
122
|
-
function addViewportsToStories(storiesFileJson, viewportsStoriesLookup) {
|
|
123
|
-
const { stories } = storiesFileJson;
|
|
124
|
-
const storiesWithViewports = stories.map((story) => {
|
|
125
|
-
const storyId = story.parameters.server.id;
|
|
126
|
-
const viewports = viewportsStoriesLookup[storyId];
|
|
127
|
-
return {
|
|
128
|
-
...story,
|
|
129
|
-
parameters: {
|
|
130
|
-
...story.parameters,
|
|
131
|
-
chromatic: {
|
|
132
|
-
...story.parameters.chromatic,
|
|
133
|
-
modes: buildStoryModesConfig(viewports)
|
|
134
|
-
},
|
|
135
|
-
viewport: {
|
|
136
|
-
viewports: buildStoryViewportsConfig(viewports),
|
|
137
|
-
defaultViewport: viewportToString(findDefaultViewport(viewports))
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
return {
|
|
143
|
-
...storiesFileJson,
|
|
144
|
-
stories: storiesWithViewports
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
__name(addViewportsToStories, "addViewportsToStories");
|
|
148
|
-
__name2(addViewportsToStories, "addViewportsToStories");
|
|
149
|
-
async function listStoriesFiles(storiesDir) {
|
|
150
|
-
const files = await readdir(storiesDir);
|
|
151
|
-
return files.filter((file) => file.endsWith(`.${STORIES_FILE_EXT}`));
|
|
152
|
-
}
|
|
153
|
-
__name(listStoriesFiles, "listStoriesFiles");
|
|
154
|
-
__name2(listStoriesFiles, "listStoriesFiles");
|
|
155
|
-
function buildStoryModesConfig(viewports) {
|
|
156
|
-
return viewports.reduce((modes, viewport) => {
|
|
157
|
-
const viewportName = viewportToString(viewport);
|
|
158
|
-
modes[viewportName] = {
|
|
159
|
-
viewport: viewportName
|
|
160
|
-
};
|
|
161
|
-
return modes;
|
|
162
|
-
}, {});
|
|
163
|
-
}
|
|
164
|
-
__name(buildStoryModesConfig, "buildStoryModesConfig");
|
|
165
|
-
__name2(buildStoryModesConfig, "buildStoryModesConfig");
|
|
166
|
-
function buildStoryViewportsConfig(viewports) {
|
|
167
|
-
return viewports.reduce((viewportsConfig, viewport) => {
|
|
168
|
-
const viewportName = viewportToString(viewport);
|
|
169
|
-
viewportsConfig[viewportName] = {
|
|
170
|
-
name: viewportName,
|
|
171
|
-
styles: {
|
|
172
|
-
width: `${viewport.width}px`,
|
|
173
|
-
height: `${viewport.height}px`
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
return viewportsConfig;
|
|
177
|
-
}, {});
|
|
178
|
-
}
|
|
179
|
-
__name(buildStoryViewportsConfig, "buildStoryViewportsConfig");
|
|
180
|
-
__name2(buildStoryViewportsConfig, "buildStoryViewportsConfig");
|
|
181
|
-
function findDefaultViewport(viewports) {
|
|
182
|
-
const compareFn = /* @__PURE__ */ __name2((vp1, vp2) => {
|
|
183
|
-
if (vp1.width < vp2.width) {
|
|
184
|
-
return 1;
|
|
185
|
-
}
|
|
186
|
-
if (vp1.width > vp2.width) {
|
|
187
|
-
return -1;
|
|
188
|
-
}
|
|
189
|
-
return 0;
|
|
190
|
-
}, "compareFn");
|
|
191
|
-
return viewports.sort(compareFn)[0];
|
|
192
|
-
}
|
|
193
|
-
__name(findDefaultViewport, "findDefaultViewport");
|
|
194
|
-
__name2(findDefaultViewport, "findDefaultViewport");
|
|
195
|
-
async function addViewportsToStoriesFiles(defaultOutputDir) {
|
|
196
|
-
const snapshotsDir = assetsDir(defaultOutputDir);
|
|
197
|
-
const snapshotFileNames = await listSnapshotFiles(snapshotsDir);
|
|
198
|
-
const viewportsLookup = buildSnapshotViewportsLookup(snapshotFileNames);
|
|
199
|
-
const storiesDir = archivesDir(defaultOutputDir);
|
|
200
|
-
const storiesFilePaths = (await listStoriesFiles(storiesDir)).map((storiesFileName) => path.resolve(storiesDir, storiesFileName));
|
|
201
|
-
await Promise.all(storiesFilePaths.map(async (storiesFilePath) => {
|
|
202
|
-
const storiesFileJson = await readJSONFile(storiesFilePath);
|
|
203
|
-
const storiesWithViewports = addViewportsToStories(storiesFileJson, viewportsLookup);
|
|
204
|
-
await outputJSONFile(storiesFilePath, storiesWithViewports);
|
|
205
|
-
}));
|
|
206
|
-
}
|
|
207
|
-
__name(addViewportsToStoriesFiles, "addViewportsToStoriesFiles");
|
|
208
|
-
__name2(addViewportsToStoriesFiles, "addViewportsToStoriesFiles");
|
|
209
|
-
function buildSnapshotViewportsLookup(snapshotFileNames) {
|
|
210
|
-
const lookup = {};
|
|
211
|
-
snapshotFileNames.forEach((file) => {
|
|
212
|
-
const snapshotId2 = snapshotIdFromFileName(file);
|
|
213
|
-
const viewports = lookup[snapshotId2] || [];
|
|
214
|
-
viewports.push(viewportFromFileName(file));
|
|
215
|
-
lookup[snapshotId2] = viewports;
|
|
216
|
-
});
|
|
217
|
-
return lookup;
|
|
218
|
-
}
|
|
219
|
-
__name(buildSnapshotViewportsLookup, "buildSnapshotViewportsLookup");
|
|
220
|
-
__name2(buildSnapshotViewportsLookup, "buildSnapshotViewportsLookup");
|
|
221
53
|
var req = __require2.resolve ? __require2 : createRequire(import.meta.url);
|
|
222
54
|
function archiveStorybook(processArgs, configDir2, defaultOutputDir) {
|
|
223
55
|
checkArchivesDirExists(defaultOutputDir);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
stdio: "inherit"
|
|
233
|
-
});
|
|
56
|
+
execFileSync("node", [
|
|
57
|
+
binPath(),
|
|
58
|
+
"dev",
|
|
59
|
+
...processArgs,
|
|
60
|
+
"-c",
|
|
61
|
+
configDir2
|
|
62
|
+
], {
|
|
63
|
+
stdio: "inherit"
|
|
234
64
|
});
|
|
235
65
|
}
|
|
236
66
|
__name(archiveStorybook, "archiveStorybook");
|
|
237
67
|
__name2(archiveStorybook, "archiveStorybook");
|
|
238
68
|
function buildArchiveStorybook(processArgs, configDir2, defaultOutputDir) {
|
|
239
69
|
checkArchivesDirExists(defaultOutputDir);
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
stdio: "inherit"
|
|
249
|
-
});
|
|
70
|
+
execFileSync("node", [
|
|
71
|
+
binPath(),
|
|
72
|
+
"build",
|
|
73
|
+
...processArgs,
|
|
74
|
+
"-c",
|
|
75
|
+
configDir2
|
|
76
|
+
], {
|
|
77
|
+
stdio: "inherit"
|
|
250
78
|
});
|
|
251
79
|
}
|
|
252
80
|
__name(buildArchiveStorybook, "buildArchiveStorybook");
|
|
@@ -12,9 +12,8 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
12
12
|
// ../shared/dist/archive-storybook/index.mjs
|
|
13
13
|
import { execFileSync } from "child_process";
|
|
14
14
|
import path, { resolve, dirname } from "path";
|
|
15
|
-
import { readFileSync, existsSync
|
|
15
|
+
import { readFileSync, existsSync } from "fs";
|
|
16
16
|
import { createRequire } from "module";
|
|
17
|
-
import { writeFile, readFile, readdir } from "fs/promises";
|
|
18
17
|
var __defProp2 = Object.defineProperty;
|
|
19
18
|
var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
|
|
20
19
|
var __require2 = /* @__PURE__ */ ((x) => typeof __require !== "undefined" ? __require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
@@ -41,11 +40,6 @@ function archivesDir(defaultOutputDir) {
|
|
|
41
40
|
}
|
|
42
41
|
__name(archivesDir, "archivesDir");
|
|
43
42
|
__name2(archivesDir, "archivesDir");
|
|
44
|
-
function assetsDir(defaultOutputDir) {
|
|
45
|
-
return path.resolve(archivesDir(defaultOutputDir), "archive");
|
|
46
|
-
}
|
|
47
|
-
__name(assetsDir, "assetsDir");
|
|
48
|
-
__name2(assetsDir, "assetsDir");
|
|
49
43
|
function checkArchivesDirExists(defaultOutputDir) {
|
|
50
44
|
const dir = archivesDir(defaultOutputDir);
|
|
51
45
|
if (!existsSync(dir)) {
|
|
@@ -56,197 +50,31 @@ Please make sure that you have run your E2E tests, or have set the CHROMATIC_ARC
|
|
|
56
50
|
}
|
|
57
51
|
__name(checkArchivesDirExists, "checkArchivesDirExists");
|
|
58
52
|
__name2(checkArchivesDirExists, "checkArchivesDirExists");
|
|
59
|
-
function ensureDir(directory) {
|
|
60
|
-
if (!existsSync(directory)) {
|
|
61
|
-
mkdirSync(directory, {
|
|
62
|
-
recursive: true
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
__name(ensureDir, "ensureDir");
|
|
67
|
-
__name2(ensureDir, "ensureDir");
|
|
68
|
-
async function outputFile(filePath, data) {
|
|
69
|
-
ensureDir(path.dirname(filePath));
|
|
70
|
-
return writeFile(filePath, data, {
|
|
71
|
-
mode: 511
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
__name(outputFile, "outputFile");
|
|
75
|
-
__name2(outputFile, "outputFile");
|
|
76
|
-
async function outputJSONFile(filePath, data) {
|
|
77
|
-
return outputFile(filePath, JSON.stringify(data));
|
|
78
|
-
}
|
|
79
|
-
__name(outputJSONFile, "outputJSONFile");
|
|
80
|
-
__name2(outputJSONFile, "outputJSONFile");
|
|
81
|
-
async function readJSONFile(filePath) {
|
|
82
|
-
const data = await readFile(filePath);
|
|
83
|
-
return JSON.parse(data.toString());
|
|
84
|
-
}
|
|
85
|
-
__name(readJSONFile, "readJSONFile");
|
|
86
|
-
__name2(readJSONFile, "readJSONFile");
|
|
87
|
-
function viewportToString(viewport) {
|
|
88
|
-
return `w${viewport.width}h${viewport.height}`;
|
|
89
|
-
}
|
|
90
|
-
__name(viewportToString, "viewportToString");
|
|
91
|
-
__name2(viewportToString, "viewportToString");
|
|
92
|
-
function parseViewport(viewportString) {
|
|
93
|
-
const matcher = viewportString.match(/w(\d+)h(\d+)/);
|
|
94
|
-
return {
|
|
95
|
-
width: Number(matcher[1]),
|
|
96
|
-
height: Number(matcher[2])
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
__name(parseViewport, "parseViewport");
|
|
100
|
-
__name2(parseViewport, "parseViewport");
|
|
101
|
-
var SNAPSHOT_FILE_EXT = "snapshot.json";
|
|
102
|
-
function snapshotIdFromFileName(fileName) {
|
|
103
|
-
const fileParts = fileName.split(".");
|
|
104
|
-
return fileParts.slice(0, fileParts.length - 3).join(".");
|
|
105
|
-
}
|
|
106
|
-
__name(snapshotIdFromFileName, "snapshotIdFromFileName");
|
|
107
|
-
__name2(snapshotIdFromFileName, "snapshotIdFromFileName");
|
|
108
|
-
function viewportFromFileName(fileName) {
|
|
109
|
-
const fileParts = fileName.split(".");
|
|
110
|
-
const viewportStr = fileParts[fileParts.length - 3];
|
|
111
|
-
return parseViewport(viewportStr);
|
|
112
|
-
}
|
|
113
|
-
__name(viewportFromFileName, "viewportFromFileName");
|
|
114
|
-
__name2(viewportFromFileName, "viewportFromFileName");
|
|
115
|
-
async function listSnapshotFiles(snapshotsDir) {
|
|
116
|
-
const files = await readdir(snapshotsDir);
|
|
117
|
-
return files.filter((file) => file.endsWith(`.${SNAPSHOT_FILE_EXT}`));
|
|
118
|
-
}
|
|
119
|
-
__name(listSnapshotFiles, "listSnapshotFiles");
|
|
120
|
-
__name2(listSnapshotFiles, "listSnapshotFiles");
|
|
121
|
-
var STORIES_FILE_EXT = "stories.json";
|
|
122
|
-
function addViewportsToStories(storiesFileJson, viewportsStoriesLookup) {
|
|
123
|
-
const { stories } = storiesFileJson;
|
|
124
|
-
const storiesWithViewports = stories.map((story) => {
|
|
125
|
-
const storyId = story.parameters.server.id;
|
|
126
|
-
const viewports = viewportsStoriesLookup[storyId];
|
|
127
|
-
return {
|
|
128
|
-
...story,
|
|
129
|
-
parameters: {
|
|
130
|
-
...story.parameters,
|
|
131
|
-
chromatic: {
|
|
132
|
-
...story.parameters.chromatic,
|
|
133
|
-
modes: buildStoryModesConfig(viewports)
|
|
134
|
-
},
|
|
135
|
-
viewport: {
|
|
136
|
-
viewports: buildStoryViewportsConfig(viewports),
|
|
137
|
-
defaultViewport: viewportToString(findDefaultViewport(viewports))
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
return {
|
|
143
|
-
...storiesFileJson,
|
|
144
|
-
stories: storiesWithViewports
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
__name(addViewportsToStories, "addViewportsToStories");
|
|
148
|
-
__name2(addViewportsToStories, "addViewportsToStories");
|
|
149
|
-
async function listStoriesFiles(storiesDir) {
|
|
150
|
-
const files = await readdir(storiesDir);
|
|
151
|
-
return files.filter((file) => file.endsWith(`.${STORIES_FILE_EXT}`));
|
|
152
|
-
}
|
|
153
|
-
__name(listStoriesFiles, "listStoriesFiles");
|
|
154
|
-
__name2(listStoriesFiles, "listStoriesFiles");
|
|
155
|
-
function buildStoryModesConfig(viewports) {
|
|
156
|
-
return viewports.reduce((modes, viewport) => {
|
|
157
|
-
const viewportName = viewportToString(viewport);
|
|
158
|
-
modes[viewportName] = {
|
|
159
|
-
viewport: viewportName
|
|
160
|
-
};
|
|
161
|
-
return modes;
|
|
162
|
-
}, {});
|
|
163
|
-
}
|
|
164
|
-
__name(buildStoryModesConfig, "buildStoryModesConfig");
|
|
165
|
-
__name2(buildStoryModesConfig, "buildStoryModesConfig");
|
|
166
|
-
function buildStoryViewportsConfig(viewports) {
|
|
167
|
-
return viewports.reduce((viewportsConfig, viewport) => {
|
|
168
|
-
const viewportName = viewportToString(viewport);
|
|
169
|
-
viewportsConfig[viewportName] = {
|
|
170
|
-
name: viewportName,
|
|
171
|
-
styles: {
|
|
172
|
-
width: `${viewport.width}px`,
|
|
173
|
-
height: `${viewport.height}px`
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
return viewportsConfig;
|
|
177
|
-
}, {});
|
|
178
|
-
}
|
|
179
|
-
__name(buildStoryViewportsConfig, "buildStoryViewportsConfig");
|
|
180
|
-
__name2(buildStoryViewportsConfig, "buildStoryViewportsConfig");
|
|
181
|
-
function findDefaultViewport(viewports) {
|
|
182
|
-
const compareFn = /* @__PURE__ */ __name2((vp1, vp2) => {
|
|
183
|
-
if (vp1.width < vp2.width) {
|
|
184
|
-
return 1;
|
|
185
|
-
}
|
|
186
|
-
if (vp1.width > vp2.width) {
|
|
187
|
-
return -1;
|
|
188
|
-
}
|
|
189
|
-
return 0;
|
|
190
|
-
}, "compareFn");
|
|
191
|
-
return viewports.sort(compareFn)[0];
|
|
192
|
-
}
|
|
193
|
-
__name(findDefaultViewport, "findDefaultViewport");
|
|
194
|
-
__name2(findDefaultViewport, "findDefaultViewport");
|
|
195
|
-
async function addViewportsToStoriesFiles(defaultOutputDir) {
|
|
196
|
-
const snapshotsDir = assetsDir(defaultOutputDir);
|
|
197
|
-
const snapshotFileNames = await listSnapshotFiles(snapshotsDir);
|
|
198
|
-
const viewportsLookup = buildSnapshotViewportsLookup(snapshotFileNames);
|
|
199
|
-
const storiesDir = archivesDir(defaultOutputDir);
|
|
200
|
-
const storiesFilePaths = (await listStoriesFiles(storiesDir)).map((storiesFileName) => path.resolve(storiesDir, storiesFileName));
|
|
201
|
-
await Promise.all(storiesFilePaths.map(async (storiesFilePath) => {
|
|
202
|
-
const storiesFileJson = await readJSONFile(storiesFilePath);
|
|
203
|
-
const storiesWithViewports = addViewportsToStories(storiesFileJson, viewportsLookup);
|
|
204
|
-
await outputJSONFile(storiesFilePath, storiesWithViewports);
|
|
205
|
-
}));
|
|
206
|
-
}
|
|
207
|
-
__name(addViewportsToStoriesFiles, "addViewportsToStoriesFiles");
|
|
208
|
-
__name2(addViewportsToStoriesFiles, "addViewportsToStoriesFiles");
|
|
209
|
-
function buildSnapshotViewportsLookup(snapshotFileNames) {
|
|
210
|
-
const lookup = {};
|
|
211
|
-
snapshotFileNames.forEach((file) => {
|
|
212
|
-
const snapshotId2 = snapshotIdFromFileName(file);
|
|
213
|
-
const viewports = lookup[snapshotId2] || [];
|
|
214
|
-
viewports.push(viewportFromFileName(file));
|
|
215
|
-
lookup[snapshotId2] = viewports;
|
|
216
|
-
});
|
|
217
|
-
return lookup;
|
|
218
|
-
}
|
|
219
|
-
__name(buildSnapshotViewportsLookup, "buildSnapshotViewportsLookup");
|
|
220
|
-
__name2(buildSnapshotViewportsLookup, "buildSnapshotViewportsLookup");
|
|
221
53
|
var req = __require2.resolve ? __require2 : createRequire(import.meta.url);
|
|
222
54
|
function archiveStorybook(processArgs, configDir2, defaultOutputDir) {
|
|
223
55
|
checkArchivesDirExists(defaultOutputDir);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
stdio: "inherit"
|
|
233
|
-
});
|
|
56
|
+
execFileSync("node", [
|
|
57
|
+
binPath(),
|
|
58
|
+
"dev",
|
|
59
|
+
...processArgs,
|
|
60
|
+
"-c",
|
|
61
|
+
configDir2
|
|
62
|
+
], {
|
|
63
|
+
stdio: "inherit"
|
|
234
64
|
});
|
|
235
65
|
}
|
|
236
66
|
__name(archiveStorybook, "archiveStorybook");
|
|
237
67
|
__name2(archiveStorybook, "archiveStorybook");
|
|
238
68
|
function buildArchiveStorybook(processArgs, configDir2, defaultOutputDir) {
|
|
239
69
|
checkArchivesDirExists(defaultOutputDir);
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
stdio: "inherit"
|
|
249
|
-
});
|
|
70
|
+
execFileSync("node", [
|
|
71
|
+
binPath(),
|
|
72
|
+
"build",
|
|
73
|
+
...processArgs,
|
|
74
|
+
"-c",
|
|
75
|
+
configDir2
|
|
76
|
+
], {
|
|
77
|
+
stdio: "inherit"
|
|
250
78
|
});
|
|
251
79
|
}
|
|
252
80
|
__name(buildArchiveStorybook, "buildArchiveStorybook");
|
package/dist/plugin.js
CHANGED
|
@@ -3863,14 +3863,25 @@ __name2(storiesFileName, "storiesFileName");
|
|
|
3863
3863
|
function createStories(title, domSnapshots, chromaticStorybookParams) {
|
|
3864
3864
|
return {
|
|
3865
3865
|
title,
|
|
3866
|
-
stories: Object.
|
|
3866
|
+
stories: Object.entries(domSnapshots).map(([name, { viewport }]) => ({
|
|
3867
3867
|
name,
|
|
3868
3868
|
parameters: {
|
|
3869
3869
|
server: {
|
|
3870
3870
|
id: snapshotId(title, name)
|
|
3871
3871
|
},
|
|
3872
3872
|
chromatic: {
|
|
3873
|
-
...chromaticStorybookParams
|
|
3873
|
+
...chromaticStorybookParams,
|
|
3874
|
+
modes: buildStoryModesConfig([
|
|
3875
|
+
viewport
|
|
3876
|
+
])
|
|
3877
|
+
},
|
|
3878
|
+
viewport: {
|
|
3879
|
+
viewports: buildStoryViewportsConfig([
|
|
3880
|
+
viewport
|
|
3881
|
+
]),
|
|
3882
|
+
defaultViewport: viewportToString(findDefaultViewport([
|
|
3883
|
+
viewport
|
|
3884
|
+
]))
|
|
3874
3885
|
}
|
|
3875
3886
|
}
|
|
3876
3887
|
}))
|
|
@@ -3878,8 +3889,48 @@ function createStories(title, domSnapshots, chromaticStorybookParams) {
|
|
|
3878
3889
|
}
|
|
3879
3890
|
__name(createStories, "createStories");
|
|
3880
3891
|
__name2(createStories, "createStories");
|
|
3892
|
+
function buildStoryModesConfig(viewports) {
|
|
3893
|
+
return viewports.reduce((modes, viewport) => {
|
|
3894
|
+
const viewportName = viewportToString(viewport);
|
|
3895
|
+
modes[viewportName] = {
|
|
3896
|
+
viewport: viewportName
|
|
3897
|
+
};
|
|
3898
|
+
return modes;
|
|
3899
|
+
}, {});
|
|
3900
|
+
}
|
|
3901
|
+
__name(buildStoryModesConfig, "buildStoryModesConfig");
|
|
3902
|
+
__name2(buildStoryModesConfig, "buildStoryModesConfig");
|
|
3903
|
+
function buildStoryViewportsConfig(viewports) {
|
|
3904
|
+
return viewports.reduce((viewportsConfig, viewport) => {
|
|
3905
|
+
const viewportName = viewportToString(viewport);
|
|
3906
|
+
viewportsConfig[viewportName] = {
|
|
3907
|
+
name: viewportName,
|
|
3908
|
+
styles: {
|
|
3909
|
+
width: `${viewport.width}px`,
|
|
3910
|
+
height: `${viewport.height}px`
|
|
3911
|
+
}
|
|
3912
|
+
};
|
|
3913
|
+
return viewportsConfig;
|
|
3914
|
+
}, {});
|
|
3915
|
+
}
|
|
3916
|
+
__name(buildStoryViewportsConfig, "buildStoryViewportsConfig");
|
|
3917
|
+
__name2(buildStoryViewportsConfig, "buildStoryViewportsConfig");
|
|
3918
|
+
function findDefaultViewport(viewports) {
|
|
3919
|
+
const compareFn = /* @__PURE__ */ __name2((vp1, vp2) => {
|
|
3920
|
+
if (vp1.width < vp2.width) {
|
|
3921
|
+
return 1;
|
|
3922
|
+
}
|
|
3923
|
+
if (vp1.width > vp2.width) {
|
|
3924
|
+
return -1;
|
|
3925
|
+
}
|
|
3926
|
+
return 0;
|
|
3927
|
+
}, "compareFn");
|
|
3928
|
+
return viewports.sort(compareFn)[0];
|
|
3929
|
+
}
|
|
3930
|
+
__name(findDefaultViewport, "findDefaultViewport");
|
|
3931
|
+
__name2(findDefaultViewport, "findDefaultViewport");
|
|
3881
3932
|
async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams) {
|
|
3882
|
-
const { titlePath, outputDir, pageUrl
|
|
3933
|
+
const { titlePath, outputDir, pageUrl } = e2eTestInfo;
|
|
3883
3934
|
const titlePathWithoutFileExtensions = titlePath.map((pathPart) => (
|
|
3884
3935
|
// make sure we remove file extensions, even if the file name doesn't have .spec or .test or.cy
|
|
3885
3936
|
// possible extensions:
|
|
@@ -3904,7 +3955,7 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
3904
3955
|
}
|
|
3905
3956
|
await outputFile(join(archiveDir, fileSystemPath), response.body);
|
|
3906
3957
|
}));
|
|
3907
|
-
await Promise.all(
|
|
3958
|
+
await Promise.all(Object.entries(domSnapshots).map(async ([name, { snapshot: domSnapshot, viewport }]) => {
|
|
3908
3959
|
const snapshot = new DOMSnapshot(domSnapshot);
|
|
3909
3960
|
const mappedSnapshot = await snapshot.mapAssetPaths(sourceMap);
|
|
3910
3961
|
const snapshotFile = snapshotFileName(snapshotId(title, name), viewport);
|
|
@@ -4049,14 +4100,22 @@ function createCommands(options) {
|
|
|
4049
4100
|
* Store a `@rrweb` generated DOM snapshot for the test.
|
|
4050
4101
|
* Can be called multiple times during a single test case.
|
|
4051
4102
|
*/
|
|
4052
|
-
async __chromatic_uploadDOMSnapshot(
|
|
4103
|
+
async __chromatic_uploadDOMSnapshot(context, id, snapshot, name) {
|
|
4053
4104
|
let sessionSnapshots = snapshots.get(id);
|
|
4054
4105
|
if (!sessionSnapshots) {
|
|
4055
4106
|
sessionSnapshots = /* @__PURE__ */ new Map();
|
|
4056
4107
|
snapshots.set(id, sessionSnapshots);
|
|
4057
4108
|
}
|
|
4058
4109
|
name ||= `Snapshot #${sessionSnapshots.size + 1}`;
|
|
4059
|
-
|
|
4110
|
+
const frame = await context.frame();
|
|
4111
|
+
const viewport = await frame.evaluate(() => ({
|
|
4112
|
+
width: window.innerWidth,
|
|
4113
|
+
height: window.innerHeight
|
|
4114
|
+
}));
|
|
4115
|
+
sessionSnapshots.set(name, {
|
|
4116
|
+
snapshot,
|
|
4117
|
+
viewport
|
|
4118
|
+
});
|
|
4060
4119
|
},
|
|
4061
4120
|
/**
|
|
4062
4121
|
* Wait for network to be idle, meaning no new network requests for at least `idleNetworkInterval` ms.
|
|
@@ -4089,17 +4148,16 @@ function createCommands(options) {
|
|
|
4089
4148
|
const { archive, sessionSnapshots } = await onTestCleanup(id);
|
|
4090
4149
|
assert(sessionSnapshots, `No snapshots found for test ${id}`);
|
|
4091
4150
|
const snapshotBuffers = {};
|
|
4092
|
-
for (const [name,
|
|
4093
|
-
snapshotBuffers[name] =
|
|
4151
|
+
for (const [name, { snapshot, viewport }] of sessionSnapshots) {
|
|
4152
|
+
snapshotBuffers[name] = {
|
|
4153
|
+
snapshot: Buffer.from(JSON.stringify(snapshot)),
|
|
4154
|
+
viewport
|
|
4155
|
+
};
|
|
4094
4156
|
}
|
|
4095
4157
|
await writeTestResult({
|
|
4096
4158
|
outputDir: resolve(context.project.config.root, options.outputDirectory),
|
|
4097
4159
|
pageUrl: context.page.url(),
|
|
4098
|
-
titlePath: getNames(entity)
|
|
4099
|
-
viewport: context.page.viewportSize() || {
|
|
4100
|
-
width: 1920,
|
|
4101
|
-
height: 1080
|
|
4102
|
-
}
|
|
4160
|
+
titlePath: getNames(entity)
|
|
4103
4161
|
}, snapshotBuffers, archive, {
|
|
4104
4162
|
delay: options.delay,
|
|
4105
4163
|
diffIncludeAntiAliasing: options.diffIncludeAntiAliasing,
|
|
@@ -4183,16 +4241,18 @@ function chromaticPlugin(userOptions = {}) {
|
|
|
4183
4241
|
idleNetworkInterval: 100,
|
|
4184
4242
|
...userOptions
|
|
4185
4243
|
};
|
|
4244
|
+
const isDist = import.meta.url.includes("dist/plugin.js");
|
|
4245
|
+
const setupFile = resolve2(import.meta.dirname, isDist ? "./setupFile.js" : "../browser/setupFile.ts");
|
|
4186
4246
|
return {
|
|
4187
4247
|
name: "vitest:chromatic",
|
|
4188
4248
|
config() {
|
|
4189
|
-
const isDist = import.meta.url.includes("dist/plugin.js");
|
|
4190
|
-
const setupFile = resolve2(import.meta.dirname, isDist ? "./setupFile.js" : "../browser/setupFile.ts");
|
|
4191
4249
|
return {
|
|
4192
|
-
|
|
4193
|
-
|
|
4250
|
+
optimizeDeps: {
|
|
4251
|
+
entries: [
|
|
4194
4252
|
setupFile
|
|
4195
|
-
]
|
|
4253
|
+
]
|
|
4254
|
+
},
|
|
4255
|
+
test: {
|
|
4196
4256
|
browser: {
|
|
4197
4257
|
commands: createCommands(options)
|
|
4198
4258
|
}
|
|
@@ -4201,6 +4261,10 @@ function chromaticPlugin(userOptions = {}) {
|
|
|
4201
4261
|
},
|
|
4202
4262
|
configureVitest(context) {
|
|
4203
4263
|
const project = context.project;
|
|
4264
|
+
if (!project.config.browser.enabled) {
|
|
4265
|
+
return;
|
|
4266
|
+
}
|
|
4267
|
+
project.config.setupFiles.push(setupFile);
|
|
4204
4268
|
if (options.tags && context.vitest.version.startsWith("4.0")) {
|
|
4205
4269
|
context.vitest.logger.warn(colors.bgYellow(colors.black(" chromatic ")), colors.yellow(`Tags cannot be used with Vitest ${context.vitest.version}. Please upgrade to Vitest 4.1 or later to use this feature.`));
|
|
4206
4270
|
}
|
|
@@ -4216,9 +4280,8 @@ function chromaticPlugin(userOptions = {}) {
|
|
|
4216
4280
|
}
|
|
4217
4281
|
}
|
|
4218
4282
|
}
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
context.vitest.logger.warn(colors.bgYellow(colors.black(" chromatic ")), colors.yellow("Plugin is used in a non-browser context."));
|
|
4283
|
+
if (!project.globalConfig.mergeReports) {
|
|
4284
|
+
clean();
|
|
4222
4285
|
}
|
|
4223
4286
|
project.onTestsRerun(async () => {
|
|
4224
4287
|
clean();
|
|
@@ -7,7 +7,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
7
7
|
|
|
8
8
|
// ../shared/dist/utils/filePaths.mjs
|
|
9
9
|
import { existsSync, mkdirSync } from "fs";
|
|
10
|
-
import { writeFile
|
|
10
|
+
import { writeFile } from "fs/promises";
|
|
11
11
|
import { createHash } from "crypto";
|
|
12
12
|
import path from "path";
|
|
13
13
|
var __defProp2 = Object.defineProperty;
|
|
@@ -29,11 +29,6 @@ function archivesDir(defaultOutputDir) {
|
|
|
29
29
|
}
|
|
30
30
|
__name(archivesDir, "archivesDir");
|
|
31
31
|
__name2(archivesDir, "archivesDir");
|
|
32
|
-
function assetsDir(defaultOutputDir) {
|
|
33
|
-
return path.resolve(archivesDir(defaultOutputDir), "archive");
|
|
34
|
-
}
|
|
35
|
-
__name(assetsDir, "assetsDir");
|
|
36
|
-
__name2(assetsDir, "assetsDir");
|
|
37
32
|
function checkArchivesDirExists(defaultOutputDir) {
|
|
38
33
|
const dir = archivesDir(defaultOutputDir);
|
|
39
34
|
if (!existsSync(dir)) {
|
|
@@ -66,12 +61,6 @@ async function outputJSONFile(filePath, data) {
|
|
|
66
61
|
}
|
|
67
62
|
__name(outputJSONFile, "outputJSONFile");
|
|
68
63
|
__name2(outputJSONFile, "outputJSONFile");
|
|
69
|
-
async function readJSONFile(filePath) {
|
|
70
|
-
const data = await readFile(filePath);
|
|
71
|
-
return JSON.parse(data.toString());
|
|
72
|
-
}
|
|
73
|
-
__name(readJSONFile, "readJSONFile");
|
|
74
|
-
__name2(readJSONFile, "readJSONFile");
|
|
75
64
|
function hash(data) {
|
|
76
65
|
return createHash("shake256", {
|
|
77
66
|
outputLength: 2
|