@chromatic-com/vitest 0.0.6 → 0.0.7-431e625-20260518134753
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 +10 -33
- package/dist/bin/build-archive-storybook.js +10 -33
- package/dist/plugin.js +182 -173
- package/dist/storybook-config/main.js +1 -77
- package/dist/storybook-config/preview.js +63 -2
- package/package.json +1 -1
|
@@ -9,37 +9,29 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
9
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
// ../shared/
|
|
12
|
+
// ../shared/src/archive-storybook/index.ts
|
|
13
13
|
import { execFileSync } from "child_process";
|
|
14
|
-
import
|
|
15
|
-
import { readFileSync
|
|
14
|
+
import { resolve, dirname } from "path";
|
|
15
|
+
import { readFileSync } from "fs";
|
|
16
16
|
import { createRequire } from "module";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}) : x)(function(x) {
|
|
22
|
-
if (typeof __require !== "undefined")
|
|
23
|
-
return __require.apply(this, arguments);
|
|
24
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
25
|
-
});
|
|
17
|
+
|
|
18
|
+
// ../shared/src/utils/filePaths.ts
|
|
19
|
+
import { existsSync, mkdirSync } from "fs";
|
|
20
|
+
import path from "path";
|
|
26
21
|
function rootDir() {
|
|
27
22
|
return process.cwd();
|
|
28
23
|
}
|
|
29
24
|
__name(rootDir, "rootDir");
|
|
30
|
-
__name2(rootDir, "rootDir");
|
|
31
25
|
function outputDirOverride() {
|
|
32
26
|
const { CHROMATIC_ARCHIVE_LOCATION } = process.env;
|
|
33
27
|
return CHROMATIC_ARCHIVE_LOCATION;
|
|
34
28
|
}
|
|
35
29
|
__name(outputDirOverride, "outputDirOverride");
|
|
36
|
-
__name2(outputDirOverride, "outputDirOverride");
|
|
37
30
|
function archivesDir(defaultOutputDir) {
|
|
38
31
|
const outputDir = outputDirOverride() || defaultOutputDir;
|
|
39
32
|
return path.resolve(rootDir(), outputDir, "chromatic-archives");
|
|
40
33
|
}
|
|
41
34
|
__name(archivesDir, "archivesDir");
|
|
42
|
-
__name2(archivesDir, "archivesDir");
|
|
43
35
|
function checkArchivesDirExists(defaultOutputDir) {
|
|
44
36
|
const dir = archivesDir(defaultOutputDir);
|
|
45
37
|
if (!existsSync(dir)) {
|
|
@@ -49,8 +41,9 @@ Please make sure that you have run your E2E tests, or have set the CHROMATIC_ARC
|
|
|
49
41
|
}
|
|
50
42
|
}
|
|
51
43
|
__name(checkArchivesDirExists, "checkArchivesDirExists");
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
|
|
45
|
+
// ../shared/src/archive-storybook/index.ts
|
|
46
|
+
var req = __require.resolve ? __require : createRequire(import.meta.url);
|
|
54
47
|
function archiveStorybook(processArgs, configDir2, defaultOutputDir) {
|
|
55
48
|
checkArchivesDirExists(defaultOutputDir);
|
|
56
49
|
execFileSync("node", [
|
|
@@ -64,28 +57,12 @@ function archiveStorybook(processArgs, configDir2, defaultOutputDir) {
|
|
|
64
57
|
});
|
|
65
58
|
}
|
|
66
59
|
__name(archiveStorybook, "archiveStorybook");
|
|
67
|
-
__name2(archiveStorybook, "archiveStorybook");
|
|
68
|
-
function buildArchiveStorybook(processArgs, configDir2, defaultOutputDir) {
|
|
69
|
-
checkArchivesDirExists(defaultOutputDir);
|
|
70
|
-
execFileSync("node", [
|
|
71
|
-
binPath(),
|
|
72
|
-
"build",
|
|
73
|
-
...processArgs,
|
|
74
|
-
"-c",
|
|
75
|
-
configDir2
|
|
76
|
-
], {
|
|
77
|
-
stdio: "inherit"
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
__name(buildArchiveStorybook, "buildArchiveStorybook");
|
|
81
|
-
__name2(buildArchiveStorybook, "buildArchiveStorybook");
|
|
82
60
|
function binPath() {
|
|
83
61
|
const filename = req.resolve("storybook/package.json");
|
|
84
62
|
const packageJson = JSON.parse(readFileSync(filename, "utf8"));
|
|
85
63
|
return resolve(dirname(filename), packageJson.bin);
|
|
86
64
|
}
|
|
87
65
|
__name(binPath, "binPath");
|
|
88
|
-
__name2(binPath, "binPath");
|
|
89
66
|
|
|
90
67
|
// src/bin/archive-storybook.ts
|
|
91
68
|
import path2 from "path";
|
|
@@ -9,37 +9,29 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
9
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
// ../shared/
|
|
12
|
+
// ../shared/src/archive-storybook/index.ts
|
|
13
13
|
import { execFileSync } from "child_process";
|
|
14
|
-
import
|
|
15
|
-
import { readFileSync
|
|
14
|
+
import { resolve, dirname } from "path";
|
|
15
|
+
import { readFileSync } from "fs";
|
|
16
16
|
import { createRequire } from "module";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}) : x)(function(x) {
|
|
22
|
-
if (typeof __require !== "undefined")
|
|
23
|
-
return __require.apply(this, arguments);
|
|
24
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
25
|
-
});
|
|
17
|
+
|
|
18
|
+
// ../shared/src/utils/filePaths.ts
|
|
19
|
+
import { existsSync, mkdirSync } from "fs";
|
|
20
|
+
import path from "path";
|
|
26
21
|
function rootDir() {
|
|
27
22
|
return process.cwd();
|
|
28
23
|
}
|
|
29
24
|
__name(rootDir, "rootDir");
|
|
30
|
-
__name2(rootDir, "rootDir");
|
|
31
25
|
function outputDirOverride() {
|
|
32
26
|
const { CHROMATIC_ARCHIVE_LOCATION } = process.env;
|
|
33
27
|
return CHROMATIC_ARCHIVE_LOCATION;
|
|
34
28
|
}
|
|
35
29
|
__name(outputDirOverride, "outputDirOverride");
|
|
36
|
-
__name2(outputDirOverride, "outputDirOverride");
|
|
37
30
|
function archivesDir(defaultOutputDir) {
|
|
38
31
|
const outputDir = outputDirOverride() || defaultOutputDir;
|
|
39
32
|
return path.resolve(rootDir(), outputDir, "chromatic-archives");
|
|
40
33
|
}
|
|
41
34
|
__name(archivesDir, "archivesDir");
|
|
42
|
-
__name2(archivesDir, "archivesDir");
|
|
43
35
|
function checkArchivesDirExists(defaultOutputDir) {
|
|
44
36
|
const dir = archivesDir(defaultOutputDir);
|
|
45
37
|
if (!existsSync(dir)) {
|
|
@@ -49,22 +41,9 @@ Please make sure that you have run your E2E tests, or have set the CHROMATIC_ARC
|
|
|
49
41
|
}
|
|
50
42
|
}
|
|
51
43
|
__name(checkArchivesDirExists, "checkArchivesDirExists");
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
checkArchivesDirExists(defaultOutputDir);
|
|
56
|
-
execFileSync("node", [
|
|
57
|
-
binPath(),
|
|
58
|
-
"dev",
|
|
59
|
-
...processArgs,
|
|
60
|
-
"-c",
|
|
61
|
-
configDir2
|
|
62
|
-
], {
|
|
63
|
-
stdio: "inherit"
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
__name(archiveStorybook, "archiveStorybook");
|
|
67
|
-
__name2(archiveStorybook, "archiveStorybook");
|
|
44
|
+
|
|
45
|
+
// ../shared/src/archive-storybook/index.ts
|
|
46
|
+
var req = __require.resolve ? __require : createRequire(import.meta.url);
|
|
68
47
|
function buildArchiveStorybook(processArgs, configDir2, defaultOutputDir) {
|
|
69
48
|
checkArchivesDirExists(defaultOutputDir);
|
|
70
49
|
execFileSync("node", [
|
|
@@ -78,14 +57,12 @@ function buildArchiveStorybook(processArgs, configDir2, defaultOutputDir) {
|
|
|
78
57
|
});
|
|
79
58
|
}
|
|
80
59
|
__name(buildArchiveStorybook, "buildArchiveStorybook");
|
|
81
|
-
__name2(buildArchiveStorybook, "buildArchiveStorybook");
|
|
82
60
|
function binPath() {
|
|
83
61
|
const filename = req.resolve("storybook/package.json");
|
|
84
62
|
const packageJson = JSON.parse(readFileSync(filename, "utf8"));
|
|
85
63
|
return resolve(dirname(filename), packageJson.bin);
|
|
86
64
|
}
|
|
87
65
|
__name(binPath, "binPath");
|
|
88
|
-
__name2(binPath, "binPath");
|
|
89
66
|
|
|
90
67
|
// src/bin/build-archive-storybook.ts
|
|
91
68
|
import path2 from "path";
|
package/dist/plugin.js
CHANGED
|
@@ -1,50 +1,34 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/node/plugin.ts
|
|
5
|
-
import { rmSync } from "node:fs";
|
|
6
|
-
import { resolve as resolve2 } from "node:path";
|
|
7
|
-
import colors from "tinyrainbow";
|
|
8
|
-
|
|
9
|
-
// ../shared/dist/index.mjs
|
|
10
|
-
import path2, { join } from "path";
|
|
11
|
-
import { existsSync, mkdirSync } from "fs";
|
|
12
|
-
import { writeFile } from "fs/promises";
|
|
13
|
-
import { createHash } from "crypto";
|
|
14
|
-
import { Analytics } from "@segment/analytics-node";
|
|
15
1
|
var __create = Object.create;
|
|
16
|
-
var
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
17
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
18
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
19
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
20
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var __commonJS = /* @__PURE__ */ __name((cb, mod) => /* @__PURE__ */ __name(function __require() {
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
24
9
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
25
|
-
}
|
|
26
|
-
var __copyProps =
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
12
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
13
|
for (let key of __getOwnPropNames(from))
|
|
29
14
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
-
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
16
|
}
|
|
32
17
|
return to;
|
|
33
|
-
}
|
|
34
|
-
var __toESM =
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
20
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
21
|
// file that has been converted to a CommonJS file using a Babel-
|
|
37
22
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
23
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
-
!mod || !mod.__esModule ?
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
25
|
mod
|
|
41
|
-
))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return value;
|
|
45
|
-
}, "__publicField");
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
// ../../node_modules/mime/Mime.js
|
|
46
29
|
var require_Mime = __commonJS({
|
|
47
|
-
"../../node_modules/mime/Mime.js"(exports
|
|
30
|
+
"../../node_modules/mime/Mime.js"(exports, module) {
|
|
31
|
+
"use strict";
|
|
48
32
|
function Mime() {
|
|
49
33
|
this._types = /* @__PURE__ */ Object.create(null);
|
|
50
34
|
this._extensions = /* @__PURE__ */ Object.create(null);
|
|
@@ -56,7 +40,6 @@ var require_Mime = __commonJS({
|
|
|
56
40
|
this.getExtension = this.getExtension.bind(this);
|
|
57
41
|
}
|
|
58
42
|
__name(Mime, "Mime");
|
|
59
|
-
__name2(Mime, "Mime");
|
|
60
43
|
Mime.prototype.define = function(typeMap, force) {
|
|
61
44
|
for (let type in typeMap) {
|
|
62
45
|
let extensions = typeMap[type].map(function(t) {
|
|
@@ -94,8 +77,10 @@ var require_Mime = __commonJS({
|
|
|
94
77
|
module.exports = Mime;
|
|
95
78
|
}
|
|
96
79
|
});
|
|
80
|
+
|
|
81
|
+
// ../../node_modules/mime/types/standard.js
|
|
97
82
|
var require_standard = __commonJS({
|
|
98
|
-
"../../node_modules/mime/types/standard.js"(exports
|
|
83
|
+
"../../node_modules/mime/types/standard.js"(exports, module) {
|
|
99
84
|
module.exports = {
|
|
100
85
|
"application/andrew-inset": [
|
|
101
86
|
"ez"
|
|
@@ -1115,8 +1100,10 @@ var require_standard = __commonJS({
|
|
|
1115
1100
|
};
|
|
1116
1101
|
}
|
|
1117
1102
|
});
|
|
1103
|
+
|
|
1104
|
+
// ../../node_modules/mime/types/other.js
|
|
1118
1105
|
var require_other = __commonJS({
|
|
1119
|
-
"../../node_modules/mime/types/other.js"(exports
|
|
1106
|
+
"../../node_modules/mime/types/other.js"(exports, module) {
|
|
1120
1107
|
module.exports = {
|
|
1121
1108
|
"application/prs.cww": [
|
|
1122
1109
|
"cww"
|
|
@@ -3229,23 +3216,29 @@ var require_other = __commonJS({
|
|
|
3229
3216
|
};
|
|
3230
3217
|
}
|
|
3231
3218
|
});
|
|
3219
|
+
|
|
3220
|
+
// ../../node_modules/mime/index.js
|
|
3232
3221
|
var require_mime = __commonJS({
|
|
3233
|
-
"../../node_modules/mime/index.js"(exports
|
|
3222
|
+
"../../node_modules/mime/index.js"(exports, module) {
|
|
3223
|
+
"use strict";
|
|
3234
3224
|
var Mime = require_Mime();
|
|
3235
3225
|
module.exports = new Mime(require_standard(), require_other());
|
|
3236
3226
|
}
|
|
3237
3227
|
});
|
|
3228
|
+
|
|
3229
|
+
// ../../node_modules/srcset/index.js
|
|
3238
3230
|
var require_srcset = __commonJS({
|
|
3239
|
-
"../../node_modules/srcset/index.js"(exports
|
|
3231
|
+
"../../node_modules/srcset/index.js"(exports) {
|
|
3232
|
+
"use strict";
|
|
3240
3233
|
var imageCandidateRegex = /\s*([^,]\S*[^,](?:\s+[^,]+)?)\s*(?:,|$)/;
|
|
3241
|
-
var duplicateDescriptorCheck = /* @__PURE__ */
|
|
3234
|
+
var duplicateDescriptorCheck = /* @__PURE__ */ __name((allDescriptors, value, postfix) => {
|
|
3242
3235
|
allDescriptors[postfix] = allDescriptors[postfix] || {};
|
|
3243
3236
|
if (allDescriptors[postfix][value]) {
|
|
3244
3237
|
throw new Error(`No more than one image candidate is allowed for a given descriptor: ${value}${postfix}`);
|
|
3245
3238
|
}
|
|
3246
3239
|
allDescriptors[postfix][value] = true;
|
|
3247
3240
|
}, "duplicateDescriptorCheck");
|
|
3248
|
-
var fallbackDescriptorDuplicateCheck = /* @__PURE__ */
|
|
3241
|
+
var fallbackDescriptorDuplicateCheck = /* @__PURE__ */ __name((allDescriptors) => {
|
|
3249
3242
|
if (allDescriptors.fallback) {
|
|
3250
3243
|
throw new Error("Only one fallback image candidate is allowed");
|
|
3251
3244
|
}
|
|
@@ -3254,14 +3247,14 @@ var require_srcset = __commonJS({
|
|
|
3254
3247
|
}
|
|
3255
3248
|
allDescriptors.fallback = true;
|
|
3256
3249
|
}, "fallbackDescriptorDuplicateCheck");
|
|
3257
|
-
var descriptorCountCheck = /* @__PURE__ */
|
|
3250
|
+
var descriptorCountCheck = /* @__PURE__ */ __name((allDescriptors, currentDescriptors) => {
|
|
3258
3251
|
if (currentDescriptors.length === 0) {
|
|
3259
3252
|
fallbackDescriptorDuplicateCheck(allDescriptors);
|
|
3260
3253
|
} else if (currentDescriptors.length > 1) {
|
|
3261
3254
|
throw new Error(`Image candidate may have no more than one descriptor, found ${currentDescriptors.length}: ${currentDescriptors.join(" ")}`);
|
|
3262
3255
|
}
|
|
3263
3256
|
}, "descriptorCountCheck");
|
|
3264
|
-
var validDescriptorCheck = /* @__PURE__ */
|
|
3257
|
+
var validDescriptorCheck = /* @__PURE__ */ __name((value, postfix, descriptor) => {
|
|
3265
3258
|
if (Number.isNaN(value)) {
|
|
3266
3259
|
throw new TypeError(`${descriptor || value} is not a valid number`);
|
|
3267
3260
|
}
|
|
@@ -3288,7 +3281,7 @@ var require_srcset = __commonJS({
|
|
|
3288
3281
|
}
|
|
3289
3282
|
}
|
|
3290
3283
|
}, "validDescriptorCheck");
|
|
3291
|
-
exports
|
|
3284
|
+
exports.parse = (string, { strict = false } = {}) => {
|
|
3292
3285
|
const allDescriptors = strict ? {} : void 0;
|
|
3293
3286
|
return string.split(imageCandidateRegex).filter((part, index) => index % 2 === 1).map((part) => {
|
|
3294
3287
|
const [url, ...descriptors] = part.trim().split(/\s+/);
|
|
@@ -3328,7 +3321,7 @@ var require_srcset = __commonJS({
|
|
|
3328
3321
|
"height",
|
|
3329
3322
|
"density"
|
|
3330
3323
|
]);
|
|
3331
|
-
exports
|
|
3324
|
+
exports.stringify = (array, { strict = false } = {}) => {
|
|
3332
3325
|
const allDescriptors = strict ? {} : null;
|
|
3333
3326
|
return array.map((element) => {
|
|
3334
3327
|
if (!element.url) {
|
|
@@ -3373,76 +3366,55 @@ var require_srcset = __commonJS({
|
|
|
3373
3366
|
};
|
|
3374
3367
|
}
|
|
3375
3368
|
});
|
|
3369
|
+
|
|
3370
|
+
// src/node/plugin.ts
|
|
3371
|
+
import { rmSync } from "node:fs";
|
|
3372
|
+
import { resolve as resolve2 } from "node:path";
|
|
3373
|
+
import colors from "tinyrainbow";
|
|
3374
|
+
|
|
3375
|
+
// ../shared/src/utils/logger.ts
|
|
3376
3376
|
var logger = process.env.LOG ? console : {
|
|
3377
3377
|
log: (..._args) => {
|
|
3378
3378
|
},
|
|
3379
3379
|
warn: (..._args) => {
|
|
3380
3380
|
}
|
|
3381
3381
|
};
|
|
3382
|
-
|
|
3382
|
+
|
|
3383
|
+
// ../shared/src/resource-archiver/index.ts
|
|
3384
|
+
var ResourceArchiver = class {
|
|
3383
3385
|
static {
|
|
3384
|
-
__name(this, "
|
|
3386
|
+
__name(this, "ResourceArchiver");
|
|
3385
3387
|
}
|
|
3388
|
+
archive = {};
|
|
3389
|
+
client;
|
|
3390
|
+
/**
|
|
3391
|
+
Specifies which domains (origins) we should archive resources for (by default we only archive same-origin resources).
|
|
3392
|
+
Useful in situations where the environment running the archived storybook (e.g. in CI) may be restricted to an intranet or other domain restrictions
|
|
3393
|
+
*/
|
|
3394
|
+
assetDomains;
|
|
3395
|
+
/**
|
|
3396
|
+
* We assume the first URL loaded after @watch is called is the base URL of the
|
|
3397
|
+
* page and we only save resources that are loaded from the same protocol/host/port combination.
|
|
3398
|
+
* We also skip archiving this page because we only care about resources requested by this page.
|
|
3399
|
+
*/
|
|
3400
|
+
firstUrl;
|
|
3401
|
+
/**
|
|
3402
|
+
* HTTP Basic Auth credentials to use when accessing protected resources.
|
|
3403
|
+
*/
|
|
3404
|
+
httpCredentials;
|
|
3405
|
+
/**
|
|
3406
|
+
* Currently active requests
|
|
3407
|
+
*/
|
|
3408
|
+
pendingRequests = /* @__PURE__ */ new Set();
|
|
3386
3409
|
constructor(cdpClient, allowedDomains, httpCredentials) {
|
|
3387
|
-
__publicField(this, "archive", {});
|
|
3388
|
-
__publicField(this, "client");
|
|
3389
|
-
__publicField(this, "assetDomains");
|
|
3390
|
-
__publicField(this, "firstUrl");
|
|
3391
|
-
__publicField(this, "httpCredentials");
|
|
3392
|
-
__publicField(this, "pendingRequests", /* @__PURE__ */ new Set());
|
|
3393
|
-
__publicField(this, "authRequired", /* @__PURE__ */ __name2(async ({ requestId, request }) => {
|
|
3394
|
-
await this.clientSend(request, "Fetch.continueWithAuth", {
|
|
3395
|
-
requestId,
|
|
3396
|
-
authChallengeResponse: {
|
|
3397
|
-
response: "ProvideCredentials",
|
|
3398
|
-
...this.httpCredentials
|
|
3399
|
-
}
|
|
3400
|
-
});
|
|
3401
|
-
}, "authRequired"));
|
|
3402
|
-
__publicField(this, "requestPaused", /* @__PURE__ */ __name2(async ({ requestId, request, responseStatusCode, responseStatusText, responseErrorReason, responseHeaders }) => {
|
|
3403
|
-
this.pendingRequests.delete(requestId);
|
|
3404
|
-
if (!request.method.match(/get/i)) {
|
|
3405
|
-
await this.clientSend(request, "Fetch.continueRequest", {
|
|
3406
|
-
requestId
|
|
3407
|
-
});
|
|
3408
|
-
return;
|
|
3409
|
-
}
|
|
3410
|
-
if (responseStatusCode === 304) {
|
|
3411
|
-
await this.clientSend(request, "Fetch.continueRequest", {
|
|
3412
|
-
requestId
|
|
3413
|
-
});
|
|
3414
|
-
return;
|
|
3415
|
-
}
|
|
3416
|
-
const requestUrl = new URL(request.url);
|
|
3417
|
-
this.firstUrl ?? (this.firstUrl = requestUrl);
|
|
3418
|
-
const isRequestFromAllowedDomain = requestUrl.origin === this.firstUrl.origin || this.assetDomains.includes(requestUrl.origin);
|
|
3419
|
-
logger.log("requestPaused", requestUrl.toString(), responseStatusCode || responseErrorReason ? "response" : "request", this.firstUrl.toString(), isRequestFromAllowedDomain);
|
|
3420
|
-
if (responseErrorReason) {
|
|
3421
|
-
logger.log(`Got response error: ${responseErrorReason}`);
|
|
3422
|
-
await this.clientSend(request, "Fetch.continueRequest", {
|
|
3423
|
-
requestId
|
|
3424
|
-
});
|
|
3425
|
-
return;
|
|
3426
|
-
}
|
|
3427
|
-
if (responseStatusCode) {
|
|
3428
|
-
await this.handleSuccessfulResponse({
|
|
3429
|
-
request,
|
|
3430
|
-
requestId,
|
|
3431
|
-
responseStatusCode,
|
|
3432
|
-
responseStatusText,
|
|
3433
|
-
responseHeaders
|
|
3434
|
-
}, requestUrl, isRequestFromAllowedDomain);
|
|
3435
|
-
return;
|
|
3436
|
-
}
|
|
3437
|
-
this.pendingRequests.add(requestId);
|
|
3438
|
-
await this.clientSend(request, "Fetch.continueRequest", {
|
|
3439
|
-
requestId,
|
|
3440
|
-
interceptResponse: true
|
|
3441
|
-
});
|
|
3442
|
-
}, "requestPaused"));
|
|
3443
3410
|
this.client = cdpClient;
|
|
3444
|
-
this.assetDomains = (allowedDomains || []).map((domain) => `https://${domain}`);
|
|
3445
3411
|
this.httpCredentials = httpCredentials;
|
|
3412
|
+
this.assetDomains = (allowedDomains || []).map((domain) => {
|
|
3413
|
+
if (domain.startsWith("http")) {
|
|
3414
|
+
return domain;
|
|
3415
|
+
}
|
|
3416
|
+
return `https://${domain}`;
|
|
3417
|
+
});
|
|
3446
3418
|
}
|
|
3447
3419
|
async watch() {
|
|
3448
3420
|
this.client.on("Fetch.requestPaused", this.requestPaused);
|
|
@@ -3471,6 +3443,56 @@ var _ResourceArchiver = class _ResourceArchiver2 {
|
|
|
3471
3443
|
return null;
|
|
3472
3444
|
}
|
|
3473
3445
|
}
|
|
3446
|
+
authRequired = async ({ requestId, request }) => {
|
|
3447
|
+
await this.clientSend(request, "Fetch.continueWithAuth", {
|
|
3448
|
+
requestId,
|
|
3449
|
+
authChallengeResponse: {
|
|
3450
|
+
response: "ProvideCredentials",
|
|
3451
|
+
...this.httpCredentials
|
|
3452
|
+
}
|
|
3453
|
+
});
|
|
3454
|
+
};
|
|
3455
|
+
requestPaused = async ({ requestId, request, responseStatusCode, responseStatusText, responseErrorReason, responseHeaders }) => {
|
|
3456
|
+
this.pendingRequests.delete(requestId);
|
|
3457
|
+
if (!request.method.match(/get/i)) {
|
|
3458
|
+
await this.clientSend(request, "Fetch.continueRequest", {
|
|
3459
|
+
requestId
|
|
3460
|
+
});
|
|
3461
|
+
return;
|
|
3462
|
+
}
|
|
3463
|
+
if (responseStatusCode === 304) {
|
|
3464
|
+
await this.clientSend(request, "Fetch.continueRequest", {
|
|
3465
|
+
requestId
|
|
3466
|
+
});
|
|
3467
|
+
return;
|
|
3468
|
+
}
|
|
3469
|
+
const requestUrl = new URL(request.url);
|
|
3470
|
+
this.firstUrl ??= requestUrl;
|
|
3471
|
+
const isRequestFromAllowedDomain = requestUrl.origin === this.firstUrl.origin || this.assetDomains.includes(requestUrl.origin);
|
|
3472
|
+
logger.log("requestPaused", requestUrl.toString(), responseStatusCode || responseErrorReason ? "response" : "request", this.firstUrl.toString(), isRequestFromAllowedDomain);
|
|
3473
|
+
if (responseErrorReason) {
|
|
3474
|
+
logger.log(`Got response error: ${responseErrorReason}`);
|
|
3475
|
+
await this.clientSend(request, "Fetch.continueRequest", {
|
|
3476
|
+
requestId
|
|
3477
|
+
});
|
|
3478
|
+
return;
|
|
3479
|
+
}
|
|
3480
|
+
if (responseStatusCode) {
|
|
3481
|
+
await this.handleSuccessfulResponse({
|
|
3482
|
+
request,
|
|
3483
|
+
requestId,
|
|
3484
|
+
responseStatusCode,
|
|
3485
|
+
responseStatusText,
|
|
3486
|
+
responseHeaders
|
|
3487
|
+
}, requestUrl, isRequestFromAllowedDomain);
|
|
3488
|
+
return;
|
|
3489
|
+
}
|
|
3490
|
+
this.pendingRequests.add(requestId);
|
|
3491
|
+
await this.clientSend(request, "Fetch.continueRequest", {
|
|
3492
|
+
requestId,
|
|
3493
|
+
interceptResponse: true
|
|
3494
|
+
});
|
|
3495
|
+
};
|
|
3474
3496
|
async handleSuccessfulResponse(requestPausedPayload, requestUrl, isRequestFromAllowedDomain) {
|
|
3475
3497
|
const { request, requestId, responseStatusCode, responseStatusText, responseHeaders } = requestPausedPayload;
|
|
3476
3498
|
if ([
|
|
@@ -3508,8 +3530,15 @@ var _ResourceArchiver = class _ResourceArchiver2 {
|
|
|
3508
3530
|
});
|
|
3509
3531
|
}
|
|
3510
3532
|
};
|
|
3511
|
-
|
|
3512
|
-
|
|
3533
|
+
|
|
3534
|
+
// ../shared/src/write-archive/index.ts
|
|
3535
|
+
import { join } from "node:path";
|
|
3536
|
+
|
|
3537
|
+
// ../shared/src/utils/filePaths.ts
|
|
3538
|
+
import { existsSync, mkdirSync } from "fs";
|
|
3539
|
+
import { writeFile } from "fs/promises";
|
|
3540
|
+
import { createHash } from "node:crypto";
|
|
3541
|
+
import path from "path";
|
|
3513
3542
|
function ensureDir(directory) {
|
|
3514
3543
|
if (!existsSync(directory)) {
|
|
3515
3544
|
mkdirSync(directory, {
|
|
@@ -3518,27 +3547,23 @@ function ensureDir(directory) {
|
|
|
3518
3547
|
}
|
|
3519
3548
|
}
|
|
3520
3549
|
__name(ensureDir, "ensureDir");
|
|
3521
|
-
__name2(ensureDir, "ensureDir");
|
|
3522
3550
|
async function outputFile(filePath, data) {
|
|
3523
|
-
ensureDir(
|
|
3551
|
+
ensureDir(path.dirname(filePath));
|
|
3524
3552
|
return writeFile(filePath, data, {
|
|
3525
3553
|
mode: 511
|
|
3526
3554
|
});
|
|
3527
3555
|
}
|
|
3528
3556
|
__name(outputFile, "outputFile");
|
|
3529
|
-
__name2(outputFile, "outputFile");
|
|
3530
3557
|
async function outputJSONFile(filePath, data) {
|
|
3531
3558
|
return outputFile(filePath, JSON.stringify(data));
|
|
3532
3559
|
}
|
|
3533
3560
|
__name(outputJSONFile, "outputJSONFile");
|
|
3534
|
-
__name2(outputJSONFile, "outputJSONFile");
|
|
3535
3561
|
function hash(data) {
|
|
3536
3562
|
return createHash("shake256", {
|
|
3537
3563
|
outputLength: 2
|
|
3538
3564
|
}).update(data).digest("hex");
|
|
3539
3565
|
}
|
|
3540
3566
|
__name(hash, "hash");
|
|
3541
|
-
__name2(hash, "hash");
|
|
3542
3567
|
var MAX_FILE_NAME_BYTE_LENGTH = 255;
|
|
3543
3568
|
function truncateFileName(filePath, maxByteLength = MAX_FILE_NAME_BYTE_LENGTH) {
|
|
3544
3569
|
const encoder = new TextEncoder();
|
|
@@ -3567,8 +3592,7 @@ function truncateFileName(filePath, maxByteLength = MAX_FILE_NAME_BYTE_LENGTH) {
|
|
|
3567
3592
|
].join("/");
|
|
3568
3593
|
}
|
|
3569
3594
|
__name(truncateFileName, "truncateFileName");
|
|
3570
|
-
|
|
3571
|
-
var removeLocalhostFromBaseUrl = /* @__PURE__ */ __name2((href) => {
|
|
3595
|
+
var removeLocalhostFromBaseUrl = /* @__PURE__ */ __name((href) => {
|
|
3572
3596
|
let baseUrl;
|
|
3573
3597
|
try {
|
|
3574
3598
|
baseUrl = new URL(href);
|
|
@@ -3580,7 +3604,11 @@ var removeLocalhostFromBaseUrl = /* @__PURE__ */ __name2((href) => {
|
|
|
3580
3604
|
return href;
|
|
3581
3605
|
}
|
|
3582
3606
|
}, "removeLocalhostFromBaseUrl");
|
|
3607
|
+
|
|
3608
|
+
// ../shared/src/write-archive/archive-file.ts
|
|
3583
3609
|
var import_mime = __toESM(require_mime());
|
|
3610
|
+
import path2 from "path";
|
|
3611
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
3584
3612
|
var RESERVED_PATHNAMES = [
|
|
3585
3613
|
// This is a list of filenames that are reserved for Storybook as a dev target.
|
|
3586
3614
|
// If we encounter these filenames, we will rename them to avoid collisions.
|
|
@@ -3593,15 +3621,17 @@ var RESERVED_PATHNAMES = [
|
|
|
3593
3621
|
"/runtime~main.iframe.bundle.js",
|
|
3594
3622
|
"/sb-preview/runtime.js"
|
|
3595
3623
|
];
|
|
3596
|
-
var
|
|
3624
|
+
var ArchiveFile = class {
|
|
3597
3625
|
static {
|
|
3598
|
-
__name(this, "
|
|
3626
|
+
__name(this, "ArchiveFile");
|
|
3599
3627
|
}
|
|
3628
|
+
// The URL to the asset being archived.
|
|
3629
|
+
url;
|
|
3630
|
+
response;
|
|
3631
|
+
shortenedFileNameLength;
|
|
3632
|
+
// The URL to page being tested.
|
|
3633
|
+
pageUrl;
|
|
3600
3634
|
constructor(url, response, pageUrl) {
|
|
3601
|
-
__publicField(this, "url");
|
|
3602
|
-
__publicField(this, "response");
|
|
3603
|
-
__publicField(this, "shortenedFileNameLength");
|
|
3604
|
-
__publicField(this, "pageUrl");
|
|
3605
3635
|
this.url = new URL(url);
|
|
3606
3636
|
this.response = response;
|
|
3607
3637
|
this.shortenedFileNameLength = 250;
|
|
@@ -3665,7 +3695,7 @@ var _ArchiveFile = class _ArchiveFile2 {
|
|
|
3665
3695
|
return `/${encodedHost}${this.url.pathname}`;
|
|
3666
3696
|
}
|
|
3667
3697
|
hash(name) {
|
|
3668
|
-
return
|
|
3698
|
+
return createHash2("md5").update(name).digest("hex");
|
|
3669
3699
|
}
|
|
3670
3700
|
renameReservedPathnames(pathname) {
|
|
3671
3701
|
if (this.url.origin === this.pageUrl.origin && RESERVED_PATHNAMES.includes(pathname)) {
|
|
@@ -3676,8 +3706,8 @@ var _ArchiveFile = class _ArchiveFile2 {
|
|
|
3676
3706
|
return pathname;
|
|
3677
3707
|
}
|
|
3678
3708
|
};
|
|
3679
|
-
|
|
3680
|
-
|
|
3709
|
+
|
|
3710
|
+
// ../../node_modules/@rrweb/types/dist/types.js
|
|
3681
3711
|
var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
3682
3712
|
NodeType2[NodeType2["Document"] = 0] = "Document";
|
|
3683
3713
|
NodeType2[NodeType2["DocumentType"] = 1] = "DocumentType";
|
|
@@ -3687,15 +3717,25 @@ var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
|
3687
3717
|
NodeType2[NodeType2["Comment"] = 5] = "Comment";
|
|
3688
3718
|
return NodeType2;
|
|
3689
3719
|
})(NodeType || {});
|
|
3720
|
+
|
|
3721
|
+
// ../shared/src/write-archive/dom-snapshot.ts
|
|
3690
3722
|
var import_srcset = __toESM(require_srcset());
|
|
3723
|
+
|
|
3724
|
+
// ../shared/src/utils/nodes.ts
|
|
3725
|
+
function isIframeSerializedNode(node) {
|
|
3726
|
+
return node.type === NodeType.Element && node.tagName === "iframe" && "contentDocument" in node && !!node.contentDocument;
|
|
3727
|
+
}
|
|
3728
|
+
__name(isIframeSerializedNode, "isIframeSerializedNode");
|
|
3729
|
+
|
|
3730
|
+
// ../shared/src/write-archive/dom-snapshot.ts
|
|
3691
3731
|
var CSS_URL_REGEX = /url\((?!['"]?(?:data):)['"]?([^'")]*)['"]?\)/gi;
|
|
3692
|
-
var
|
|
3732
|
+
var DOMSnapshot = class {
|
|
3693
3733
|
static {
|
|
3694
|
-
__name(this, "
|
|
3734
|
+
__name(this, "DOMSnapshot");
|
|
3695
3735
|
}
|
|
3736
|
+
snapshot;
|
|
3737
|
+
pseudoClassIds;
|
|
3696
3738
|
constructor({ snapshot, pseudoClassIds }) {
|
|
3697
|
-
__publicField(this, "snapshot");
|
|
3698
|
-
__publicField(this, "pseudoClassIds");
|
|
3699
3739
|
if (Buffer.isBuffer(snapshot)) {
|
|
3700
3740
|
const bufferAsString = snapshot.toString("utf-8");
|
|
3701
3741
|
this.snapshot = JSON.parse(bufferAsString);
|
|
@@ -3719,6 +3759,9 @@ var _DOMSnapshot = class _DOMSnapshot2 {
|
|
|
3719
3759
|
return this.mapNode(childNode, sourceMap);
|
|
3720
3760
|
}));
|
|
3721
3761
|
}
|
|
3762
|
+
if (isIframeSerializedNode(node)) {
|
|
3763
|
+
node.contentDocument = await this.mapNode(node.contentDocument, sourceMap);
|
|
3764
|
+
}
|
|
3722
3765
|
return node;
|
|
3723
3766
|
}
|
|
3724
3767
|
mapNodeAttributes(node, sourceMap) {
|
|
@@ -3817,25 +3860,19 @@ var _DOMSnapshot = class _DOMSnapshot2 {
|
|
|
3817
3860
|
return currentSrc;
|
|
3818
3861
|
}
|
|
3819
3862
|
};
|
|
3820
|
-
|
|
3821
|
-
|
|
3863
|
+
|
|
3864
|
+
// ../shared/src/utils/viewport.ts
|
|
3822
3865
|
function viewportToString(viewport) {
|
|
3823
3866
|
return `w${viewport.width}h${viewport.height}`;
|
|
3824
3867
|
}
|
|
3825
3868
|
__name(viewportToString, "viewportToString");
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
return {
|
|
3830
|
-
width: Number(matcher[1]),
|
|
3831
|
-
height: Number(matcher[2])
|
|
3832
|
-
};
|
|
3833
|
-
}
|
|
3834
|
-
__name(parseViewport, "parseViewport");
|
|
3835
|
-
__name2(parseViewport, "parseViewport");
|
|
3836
|
-
var sanitize = /* @__PURE__ */ __name2((string) => {
|
|
3869
|
+
|
|
3870
|
+
// ../shared/src/write-archive/storybook-sanitize.ts
|
|
3871
|
+
var sanitize = /* @__PURE__ */ __name((string) => {
|
|
3837
3872
|
return string.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").replace(/[\r\n]/g, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
3838
3873
|
}, "sanitize");
|
|
3874
|
+
|
|
3875
|
+
// ../shared/src/write-archive/snapshot-files.ts
|
|
3839
3876
|
var SNAPSHOT_FILE_EXT = "snapshot.json";
|
|
3840
3877
|
function snapshotId(testTitle, snapshotName) {
|
|
3841
3878
|
const fullSnapshotId = `${sanitize(testTitle)}-${sanitize(snapshotName)}`;
|
|
@@ -3843,7 +3880,6 @@ function snapshotId(testTitle, snapshotName) {
|
|
|
3843
3880
|
return truncateFileName(fullSnapshotId, maxByteLength);
|
|
3844
3881
|
}
|
|
3845
3882
|
__name(snapshotId, "snapshotId");
|
|
3846
|
-
__name2(snapshotId, "snapshotId");
|
|
3847
3883
|
function snapshotFileName(snapshotId2, viewport) {
|
|
3848
3884
|
const fileNameParts = [
|
|
3849
3885
|
snapshotId2,
|
|
@@ -3853,7 +3889,8 @@ function snapshotFileName(snapshotId2, viewport) {
|
|
|
3853
3889
|
return fileNameParts.join(".");
|
|
3854
3890
|
}
|
|
3855
3891
|
__name(snapshotFileName, "snapshotFileName");
|
|
3856
|
-
|
|
3892
|
+
|
|
3893
|
+
// ../shared/src/write-archive/stories-files.ts
|
|
3857
3894
|
var STORIES_FILE_EXT = "stories.json";
|
|
3858
3895
|
function storiesFileName(testTitle) {
|
|
3859
3896
|
const fileName = [
|
|
@@ -3864,7 +3901,6 @@ function storiesFileName(testTitle) {
|
|
|
3864
3901
|
return truncateFileName(fileName, maxByteLength);
|
|
3865
3902
|
}
|
|
3866
3903
|
__name(storiesFileName, "storiesFileName");
|
|
3867
|
-
__name2(storiesFileName, "storiesFileName");
|
|
3868
3904
|
function createStories(title, domSnapshots, chromaticStorybookParams) {
|
|
3869
3905
|
return {
|
|
3870
3906
|
title,
|
|
@@ -3899,7 +3935,6 @@ function createStories(title, domSnapshots, chromaticStorybookParams) {
|
|
|
3899
3935
|
};
|
|
3900
3936
|
}
|
|
3901
3937
|
__name(createStories, "createStories");
|
|
3902
|
-
__name2(createStories, "createStories");
|
|
3903
3938
|
function buildStoryModesConfig(viewports) {
|
|
3904
3939
|
return viewports.reduce((modes, viewport) => {
|
|
3905
3940
|
const viewportName = viewportToString(viewport);
|
|
@@ -3910,7 +3945,6 @@ function buildStoryModesConfig(viewports) {
|
|
|
3910
3945
|
}, {});
|
|
3911
3946
|
}
|
|
3912
3947
|
__name(buildStoryModesConfig, "buildStoryModesConfig");
|
|
3913
|
-
__name2(buildStoryModesConfig, "buildStoryModesConfig");
|
|
3914
3948
|
function buildStoryViewportsConfig(viewports) {
|
|
3915
3949
|
return viewports.reduce((viewportsConfig, viewport) => {
|
|
3916
3950
|
const viewportName = viewportToString(viewport);
|
|
@@ -3926,7 +3960,6 @@ function buildStoryViewportsConfig(viewports) {
|
|
|
3926
3960
|
}, {});
|
|
3927
3961
|
}
|
|
3928
3962
|
__name(buildStoryViewportsConfig, "buildStoryViewportsConfig");
|
|
3929
|
-
__name2(buildStoryViewportsConfig, "buildStoryViewportsConfig");
|
|
3930
3963
|
function viewportAddonType(viewport) {
|
|
3931
3964
|
if (viewport.width < 600) {
|
|
3932
3965
|
return "mobile";
|
|
@@ -3937,9 +3970,8 @@ function viewportAddonType(viewport) {
|
|
|
3937
3970
|
return "desktop";
|
|
3938
3971
|
}
|
|
3939
3972
|
__name(viewportAddonType, "viewportAddonType");
|
|
3940
|
-
__name2(viewportAddonType, "viewportAddonType");
|
|
3941
3973
|
function findDefaultViewport(viewports) {
|
|
3942
|
-
const compareFn = /* @__PURE__ */
|
|
3974
|
+
const compareFn = /* @__PURE__ */ __name((vp1, vp2) => {
|
|
3943
3975
|
if (vp1.width < vp2.width) {
|
|
3944
3976
|
return 1;
|
|
3945
3977
|
}
|
|
@@ -3951,7 +3983,8 @@ function findDefaultViewport(viewports) {
|
|
|
3951
3983
|
return viewports.sort(compareFn)[0];
|
|
3952
3984
|
}
|
|
3953
3985
|
__name(findDefaultViewport, "findDefaultViewport");
|
|
3954
|
-
|
|
3986
|
+
|
|
3987
|
+
// ../shared/src/write-archive/index.ts
|
|
3955
3988
|
async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams) {
|
|
3956
3989
|
const { titlePath, outputDir, pageUrl } = e2eTestInfo;
|
|
3957
3990
|
const titlePathWithoutFileExtensions = titlePath.map((pathPart) => (
|
|
@@ -3996,38 +4029,14 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
3996
4029
|
}
|
|
3997
4030
|
}
|
|
3998
4031
|
__name(writeTestResult, "writeTestResult");
|
|
3999
|
-
|
|
4032
|
+
|
|
4033
|
+
// ../shared/src/utils/analytics.ts
|
|
4034
|
+
import { Analytics } from "@segment/analytics-node";
|
|
4000
4035
|
var analytics = new Analytics({
|
|
4001
4036
|
writeKey: process.env.SEGMENT_WRITE_KEY || "cwWhBWso2gwzyenW29CnCp30Kjz4DogE"
|
|
4002
4037
|
});
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
analytics.track({
|
|
4006
|
-
userId,
|
|
4007
|
-
event,
|
|
4008
|
-
properties
|
|
4009
|
-
});
|
|
4010
|
-
}
|
|
4011
|
-
__name(track, "track");
|
|
4012
|
-
__name2(track, "track");
|
|
4013
|
-
var hasTrackedRun = false;
|
|
4014
|
-
function trackRun(properties = {}) {
|
|
4015
|
-
if (hasTrackedRun)
|
|
4016
|
-
return;
|
|
4017
|
-
track("run", properties);
|
|
4018
|
-
hasTrackedRun = true;
|
|
4019
|
-
}
|
|
4020
|
-
__name(trackRun, "trackRun");
|
|
4021
|
-
__name2(trackRun, "trackRun");
|
|
4022
|
-
var hasTrackedComplete = false;
|
|
4023
|
-
function trackComplete(properties = {}) {
|
|
4024
|
-
if (hasTrackedComplete)
|
|
4025
|
-
return;
|
|
4026
|
-
track("complete", properties);
|
|
4027
|
-
hasTrackedComplete = true;
|
|
4028
|
-
}
|
|
4029
|
-
__name(trackComplete, "trackComplete");
|
|
4030
|
-
__name2(trackComplete, "trackComplete");
|
|
4038
|
+
|
|
4039
|
+
// ../shared/src/constants.ts
|
|
4031
4040
|
var DEFAULT_GLOBAL_RESOURCE_ARCHIVE_TIMEOUT_MS = 1e4;
|
|
4032
4041
|
|
|
4033
4042
|
// src/node/commands.ts
|
|
@@ -5,98 +5,22 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
5
5
|
import path2 from "node:path";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
|
|
8
|
-
// ../shared/
|
|
9
|
-
import { existsSync, mkdirSync } from "fs";
|
|
10
|
-
import { writeFile } from "fs/promises";
|
|
11
|
-
import { createHash } from "crypto";
|
|
8
|
+
// ../shared/src/utils/filePaths.ts
|
|
12
9
|
import path from "path";
|
|
13
|
-
var __defProp2 = Object.defineProperty;
|
|
14
|
-
var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
|
|
15
10
|
function rootDir() {
|
|
16
11
|
return process.cwd();
|
|
17
12
|
}
|
|
18
13
|
__name(rootDir, "rootDir");
|
|
19
|
-
__name2(rootDir, "rootDir");
|
|
20
14
|
function outputDirOverride() {
|
|
21
15
|
const { CHROMATIC_ARCHIVE_LOCATION } = process.env;
|
|
22
16
|
return CHROMATIC_ARCHIVE_LOCATION;
|
|
23
17
|
}
|
|
24
18
|
__name(outputDirOverride, "outputDirOverride");
|
|
25
|
-
__name2(outputDirOverride, "outputDirOverride");
|
|
26
19
|
function archivesDir(defaultOutputDir) {
|
|
27
20
|
const outputDir = outputDirOverride() || defaultOutputDir;
|
|
28
21
|
return path.resolve(rootDir(), outputDir, "chromatic-archives");
|
|
29
22
|
}
|
|
30
23
|
__name(archivesDir, "archivesDir");
|
|
31
|
-
__name2(archivesDir, "archivesDir");
|
|
32
|
-
function checkArchivesDirExists(defaultOutputDir) {
|
|
33
|
-
const dir = archivesDir(defaultOutputDir);
|
|
34
|
-
if (!existsSync(dir)) {
|
|
35
|
-
throw new Error(`Chromatic archives directory cannot be found: ${dir}
|
|
36
|
-
|
|
37
|
-
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.`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
__name(checkArchivesDirExists, "checkArchivesDirExists");
|
|
41
|
-
__name2(checkArchivesDirExists, "checkArchivesDirExists");
|
|
42
|
-
function ensureDir(directory) {
|
|
43
|
-
if (!existsSync(directory)) {
|
|
44
|
-
mkdirSync(directory, {
|
|
45
|
-
recursive: true
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
__name(ensureDir, "ensureDir");
|
|
50
|
-
__name2(ensureDir, "ensureDir");
|
|
51
|
-
async function outputFile(filePath, data) {
|
|
52
|
-
ensureDir(path.dirname(filePath));
|
|
53
|
-
return writeFile(filePath, data, {
|
|
54
|
-
mode: 511
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
__name(outputFile, "outputFile");
|
|
58
|
-
__name2(outputFile, "outputFile");
|
|
59
|
-
async function outputJSONFile(filePath, data) {
|
|
60
|
-
return outputFile(filePath, JSON.stringify(data));
|
|
61
|
-
}
|
|
62
|
-
__name(outputJSONFile, "outputJSONFile");
|
|
63
|
-
__name2(outputJSONFile, "outputJSONFile");
|
|
64
|
-
function hash(data) {
|
|
65
|
-
return createHash("shake256", {
|
|
66
|
-
outputLength: 2
|
|
67
|
-
}).update(data).digest("hex");
|
|
68
|
-
}
|
|
69
|
-
__name(hash, "hash");
|
|
70
|
-
__name2(hash, "hash");
|
|
71
|
-
var MAX_FILE_NAME_BYTE_LENGTH = 255;
|
|
72
|
-
function truncateFileName(filePath, maxByteLength = MAX_FILE_NAME_BYTE_LENGTH) {
|
|
73
|
-
const encoder = new TextEncoder();
|
|
74
|
-
const decoder = new TextDecoder();
|
|
75
|
-
const filePathParts = filePath.split("/");
|
|
76
|
-
const fileName = filePathParts.pop();
|
|
77
|
-
const fileNameByteArray = encoder.encode(fileName);
|
|
78
|
-
if (fileNameByteArray.byteLength <= maxByteLength) {
|
|
79
|
-
return filePath;
|
|
80
|
-
}
|
|
81
|
-
const hashedFileName = hash(fileName);
|
|
82
|
-
const [baseName, ...extensions] = fileName.split(".");
|
|
83
|
-
const baseNameByteArray = encoder.encode(baseName);
|
|
84
|
-
const ext = extensions.join(".");
|
|
85
|
-
const extLength = ext.length === 0 ? 0 : encoder.encode(ext).byteLength + 1;
|
|
86
|
-
const lengthHashAndExt = encoder.encode(hashedFileName).byteLength + extLength;
|
|
87
|
-
const truncatedBaseNameByteArray = baseNameByteArray.slice(0, maxByteLength - lengthHashAndExt);
|
|
88
|
-
const truncatedBaseName = decoder.decode(truncatedBaseNameByteArray);
|
|
89
|
-
const truncatedFileName = [
|
|
90
|
-
`${truncatedBaseName}${hashedFileName}`,
|
|
91
|
-
ext
|
|
92
|
-
].filter(Boolean).join(".");
|
|
93
|
-
return [
|
|
94
|
-
...filePathParts,
|
|
95
|
-
truncatedFileName
|
|
96
|
-
].join("/");
|
|
97
|
-
}
|
|
98
|
-
__name(truncateFileName, "truncateFileName");
|
|
99
|
-
__name2(truncateFileName, "truncateFileName");
|
|
100
24
|
|
|
101
25
|
// src/constants.ts
|
|
102
26
|
var DEFAULT_OUTPUT_DIR = ".vitest/chromatic";
|
|
@@ -14,6 +14,22 @@ var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
|
14
14
|
|
|
15
15
|
// ../shared/storybook-config/preview.ts
|
|
16
16
|
import { rebuild, createMirror, createCache } from "@chromaui/rrweb-snapshot";
|
|
17
|
+
|
|
18
|
+
// ../shared/src/utils/nodes.ts
|
|
19
|
+
function isIframeSerializedNode(node) {
|
|
20
|
+
return node.type === NodeType.Element && node.tagName === "iframe" && "contentDocument" in node && !!node.contentDocument;
|
|
21
|
+
}
|
|
22
|
+
__name(isIframeSerializedNode, "isIframeSerializedNode");
|
|
23
|
+
function isElement(node) {
|
|
24
|
+
return node?.nodeType === Node.ELEMENT_NODE;
|
|
25
|
+
}
|
|
26
|
+
__name(isElement, "isElement");
|
|
27
|
+
function isIframeElement(node) {
|
|
28
|
+
return isElement(node) && node.tagName.toLowerCase() === "iframe";
|
|
29
|
+
}
|
|
30
|
+
__name(isIframeElement, "isIframeElement");
|
|
31
|
+
|
|
32
|
+
// ../shared/storybook-config/preview.ts
|
|
17
33
|
var pageUrl = new URL(window.location.href);
|
|
18
34
|
pageUrl.pathname = "";
|
|
19
35
|
pageUrl.search = "";
|
|
@@ -29,6 +45,20 @@ var findHtmlNode = /* @__PURE__ */ __name((node) => {
|
|
|
29
45
|
}
|
|
30
46
|
return void 0;
|
|
31
47
|
}, "findHtmlNode");
|
|
48
|
+
var findNodeById = /* @__PURE__ */ __name((node, id) => {
|
|
49
|
+
if (node.id === id) {
|
|
50
|
+
return node;
|
|
51
|
+
}
|
|
52
|
+
if ("childNodes" in node) {
|
|
53
|
+
for (const childNode of node.childNodes) {
|
|
54
|
+
const match = findNodeById(childNode, id);
|
|
55
|
+
if (match) {
|
|
56
|
+
return match;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
61
|
+
}, "findNodeById");
|
|
32
62
|
function snapshotFileName(snapshotId, viewport) {
|
|
33
63
|
const fileNameParts = [
|
|
34
64
|
snapshotId,
|
|
@@ -62,12 +92,13 @@ var renderToCanvas = /* @__PURE__ */ __name(async (context) => {
|
|
|
62
92
|
const html = rebuild(htmlNode, {
|
|
63
93
|
doc: document,
|
|
64
94
|
mirror,
|
|
65
|
-
cache: createCache()
|
|
95
|
+
cache: createCache(),
|
|
96
|
+
afterAppend: afterAppendIframes(snapshot)
|
|
66
97
|
});
|
|
67
98
|
for (const [className, ids] of Object.entries(pseudoClassIds)) {
|
|
68
99
|
for (const id of ids) {
|
|
69
100
|
const el = mirror.getNode(id);
|
|
70
|
-
if (el
|
|
101
|
+
if (isElement(el)) {
|
|
71
102
|
el.classList.add(className);
|
|
72
103
|
}
|
|
73
104
|
}
|
|
@@ -78,6 +109,36 @@ var renderToCanvas = /* @__PURE__ */ __name(async (context) => {
|
|
|
78
109
|
return () => {
|
|
79
110
|
};
|
|
80
111
|
}, "renderToCanvas");
|
|
112
|
+
function afterAppendIframes(snapshot) {
|
|
113
|
+
return /* @__PURE__ */ __name(function afterAppend(node, id) {
|
|
114
|
+
if (!isIframeElement(node)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const serializedNode = findNodeById(snapshot, id);
|
|
118
|
+
if (!isIframeSerializedNode(serializedNode)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
node.onload = () => {
|
|
122
|
+
const mirror = createMirror();
|
|
123
|
+
rebuild(serializedNode.contentDocument, {
|
|
124
|
+
doc: node.contentDocument,
|
|
125
|
+
mirror,
|
|
126
|
+
cache: createCache(),
|
|
127
|
+
// Recursively build iframes within iframes
|
|
128
|
+
afterAppend: afterAppendIframes(serializedNode.contentDocument)
|
|
129
|
+
});
|
|
130
|
+
for (const [className, ids] of Object.entries(serializedNode.pseudoClassIds)) {
|
|
131
|
+
for (const id2 of ids) {
|
|
132
|
+
const el = mirror.getNode(id2);
|
|
133
|
+
if (isElement(el)) {
|
|
134
|
+
el.classList.add(className);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}, "afterAppend");
|
|
140
|
+
}
|
|
141
|
+
__name(afterAppendIframes, "afterAppendIframes");
|
|
81
142
|
var preview_default = {
|
|
82
143
|
renderToCanvas,
|
|
83
144
|
parameters: {
|