@chromatic-com/playwright 0.14.3 → 0.14.5
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/index.js +56 -59
- package/dist/index.mjs +56 -59
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var path2 = require('path');
|
|
|
6
6
|
var fs = require('fs');
|
|
7
7
|
var promises = require('fs/promises');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
|
+
var csf = require('storybook/internal/csf');
|
|
9
10
|
var analyticsNode = require('@segment/analytics-node');
|
|
10
11
|
|
|
11
12
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -3803,8 +3804,7 @@ var _DOMSnapshot = class _DOMSnapshot {
|
|
|
3803
3804
|
const currentSrc = this.mapSrcsetUrls(srcsetValue, sourceMap);
|
|
3804
3805
|
if (currentSrc) {
|
|
3805
3806
|
node.attributes.src = currentSrc;
|
|
3806
|
-
|
|
3807
|
-
delete node.attributes.sizes;
|
|
3807
|
+
this.removeResponsiveImageAttributes(node.attributes);
|
|
3808
3808
|
}
|
|
3809
3809
|
}
|
|
3810
3810
|
if (node.tagName === "picture") {
|
|
@@ -3829,6 +3829,7 @@ var _DOMSnapshot = class _DOMSnapshot {
|
|
|
3829
3829
|
const imageElement = node.childNodes.find((childNode) => childNode.type === NodeType.Element && childNode.tagName === "img");
|
|
3830
3830
|
if (imageElement && imageElement.attributes) {
|
|
3831
3831
|
imageElement.attributes.src = sourceMap.get(matchingUrl);
|
|
3832
|
+
this.removeResponsiveImageAttributes(imageElement.attributes);
|
|
3832
3833
|
}
|
|
3833
3834
|
}
|
|
3834
3835
|
}
|
|
@@ -3863,6 +3864,10 @@ var _DOMSnapshot = class _DOMSnapshot {
|
|
|
3863
3864
|
});
|
|
3864
3865
|
return currentSrc;
|
|
3865
3866
|
}
|
|
3867
|
+
removeResponsiveImageAttributes(attributes) {
|
|
3868
|
+
delete attributes.srcset;
|
|
3869
|
+
delete attributes.sizes;
|
|
3870
|
+
}
|
|
3866
3871
|
};
|
|
3867
3872
|
__name(_DOMSnapshot, "DOMSnapshot");
|
|
3868
3873
|
var DOMSnapshot = _DOMSnapshot;
|
|
@@ -3877,6 +3882,7 @@ __name(viewportToString, "viewportToString");
|
|
|
3877
3882
|
var sanitize = /* @__PURE__ */ __name((string) => {
|
|
3878
3883
|
return string.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").replace(/[\r\n]/g, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
3879
3884
|
}, "sanitize");
|
|
3885
|
+
var collapseNewlines = /* @__PURE__ */ __name((title) => title.replace(/[\r\n]+/g, " ").trim(), "collapseNewlines");
|
|
3880
3886
|
|
|
3881
3887
|
// ../shared/src/write-archive/snapshot-files.ts
|
|
3882
3888
|
var SNAPSHOT_FILE_EXT = "snapshot.json";
|
|
@@ -3895,49 +3901,57 @@ function snapshotFileName(snapshotId2, viewport) {
|
|
|
3895
3901
|
return fileNameParts.join(".");
|
|
3896
3902
|
}
|
|
3897
3903
|
__name(snapshotFileName, "snapshotFileName");
|
|
3898
|
-
|
|
3899
|
-
// ../shared/src/write-archive/stories-files.ts
|
|
3900
3904
|
var STORIES_FILE_EXT = "stories.json";
|
|
3905
|
+
var uniqueId = {
|
|
3906
|
+
value: 1
|
|
3907
|
+
};
|
|
3901
3908
|
function storiesFileName(testTitle) {
|
|
3902
3909
|
const fileName = [
|
|
3903
|
-
sanitize(testTitle)
|
|
3910
|
+
sanitize(testTitle) + "-" + uniqueId.value++,
|
|
3904
3911
|
STORIES_FILE_EXT
|
|
3905
3912
|
].join(".");
|
|
3906
3913
|
const maxByteLength = MAX_FILE_NAME_BYTE_LENGTH - 25;
|
|
3907
3914
|
return truncateFileName(fileName, maxByteLength);
|
|
3908
3915
|
}
|
|
3909
3916
|
__name(storiesFileName, "storiesFileName");
|
|
3910
|
-
function createStories(
|
|
3917
|
+
function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
|
|
3918
|
+
const title = collapseNewlines(storyTitle);
|
|
3911
3919
|
return {
|
|
3912
3920
|
title,
|
|
3913
|
-
stories: Object.entries(domSnapshots).map(([
|
|
3914
|
-
name
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
server: {
|
|
3923
|
-
id: snapshotId(title, name)
|
|
3921
|
+
stories: Object.entries(domSnapshots).map(([snapshotName, { viewport }]) => {
|
|
3922
|
+
const name = collapseNewlines(snapshotName);
|
|
3923
|
+
return {
|
|
3924
|
+
name,
|
|
3925
|
+
// Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
|
|
3926
|
+
// selects the active one. See https://storybook.js.org/docs/essentials/viewport#defining-the-viewport-for-a-story
|
|
3927
|
+
// `defaultViewport` is not read by SB 10's types but our archive preview uses it as a fetch fallback.
|
|
3928
|
+
globals: {
|
|
3929
|
+
viewport: viewportToString(viewport)
|
|
3924
3930
|
},
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3931
|
+
parameters: {
|
|
3932
|
+
// Work-around for cases where "あ" in story name would cause Storybook to fail to load the story due to an invalid story ID.
|
|
3933
|
+
// See https://github.com/chromaui/chromatic-e2e/issues/365
|
|
3934
|
+
__id: csf.toId(title, csf.storyNameFromExport(name)),
|
|
3935
|
+
server: {
|
|
3936
|
+
id: snapshotId(title, name)
|
|
3937
|
+
},
|
|
3938
|
+
chromatic: {
|
|
3939
|
+
...chromaticStorybookParams,
|
|
3940
|
+
modes: buildStoryModesConfig([
|
|
3941
|
+
viewport
|
|
3942
|
+
])
|
|
3943
|
+
},
|
|
3944
|
+
viewport: {
|
|
3945
|
+
options: buildStoryViewportsConfig([
|
|
3946
|
+
viewport
|
|
3947
|
+
]),
|
|
3948
|
+
defaultViewport: viewportToString(findDefaultViewport([
|
|
3949
|
+
viewport
|
|
3950
|
+
]))
|
|
3951
|
+
}
|
|
3938
3952
|
}
|
|
3939
|
-
}
|
|
3940
|
-
})
|
|
3953
|
+
};
|
|
3954
|
+
})
|
|
3941
3955
|
};
|
|
3942
3956
|
}
|
|
3943
3957
|
__name(createStories, "createStories");
|
|
@@ -4206,38 +4220,21 @@ var performChromaticSnapshot = /* @__PURE__ */ __name(async ({ page, delay, diff
|
|
|
4206
4220
|
}
|
|
4207
4221
|
const resourceArchive = await completeArchive();
|
|
4208
4222
|
const snapshots = chromaticSnapshots.get(testId) || /* @__PURE__ */ new Map();
|
|
4209
|
-
const chromaticStorybookParams = {
|
|
4210
|
-
...delay && {
|
|
4211
|
-
delay
|
|
4212
|
-
},
|
|
4213
|
-
...diffIncludeAntiAliasing && {
|
|
4214
|
-
diffIncludeAntiAliasing
|
|
4215
|
-
},
|
|
4216
|
-
...diffThreshold && {
|
|
4217
|
-
diffThreshold
|
|
4218
|
-
},
|
|
4219
|
-
...forcedColors && {
|
|
4220
|
-
forcedColors
|
|
4221
|
-
},
|
|
4222
|
-
...pauseAnimationAtEnd && {
|
|
4223
|
-
pauseAnimationAtEnd
|
|
4224
|
-
},
|
|
4225
|
-
...prefersReducedMotion && {
|
|
4226
|
-
prefersReducedMotion
|
|
4227
|
-
},
|
|
4228
|
-
...cropToViewport && {
|
|
4229
|
-
cropToViewport
|
|
4230
|
-
},
|
|
4231
|
-
...ignoreSelectors && {
|
|
4232
|
-
ignoreSelectors
|
|
4233
|
-
}
|
|
4234
|
-
};
|
|
4235
4223
|
const outputDir = path2.join(testInfo.outputDir, "..");
|
|
4236
4224
|
await writeTestResult({
|
|
4237
4225
|
...testInfo,
|
|
4238
4226
|
outputDir,
|
|
4239
4227
|
pageUrl: page.url()
|
|
4240
|
-
}, Object.fromEntries(snapshots), resourceArchive,
|
|
4228
|
+
}, Object.fromEntries(snapshots), resourceArchive, {
|
|
4229
|
+
delay,
|
|
4230
|
+
diffIncludeAntiAliasing,
|
|
4231
|
+
diffThreshold,
|
|
4232
|
+
forcedColors,
|
|
4233
|
+
pauseAnimationAtEnd,
|
|
4234
|
+
prefersReducedMotion,
|
|
4235
|
+
cropToViewport,
|
|
4236
|
+
ignoreSelectors
|
|
4237
|
+
});
|
|
4241
4238
|
trackComplete();
|
|
4242
4239
|
} finally {
|
|
4243
4240
|
chromaticSnapshots.delete(testId);
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import path2, { join } from 'path';
|
|
|
5
5
|
import { existsSync, mkdirSync } from 'fs';
|
|
6
6
|
import { writeFile } from 'fs/promises';
|
|
7
7
|
import { createHash } from 'crypto';
|
|
8
|
+
import { toId, storyNameFromExport } from 'storybook/internal/csf';
|
|
8
9
|
import { Analytics } from '@segment/analytics-node';
|
|
9
10
|
|
|
10
11
|
const require$1 = createRequire(import.meta.url);
|
|
@@ -3797,8 +3798,7 @@ var _DOMSnapshot = class _DOMSnapshot {
|
|
|
3797
3798
|
const currentSrc = this.mapSrcsetUrls(srcsetValue, sourceMap);
|
|
3798
3799
|
if (currentSrc) {
|
|
3799
3800
|
node.attributes.src = currentSrc;
|
|
3800
|
-
|
|
3801
|
-
delete node.attributes.sizes;
|
|
3801
|
+
this.removeResponsiveImageAttributes(node.attributes);
|
|
3802
3802
|
}
|
|
3803
3803
|
}
|
|
3804
3804
|
if (node.tagName === "picture") {
|
|
@@ -3823,6 +3823,7 @@ var _DOMSnapshot = class _DOMSnapshot {
|
|
|
3823
3823
|
const imageElement = node.childNodes.find((childNode) => childNode.type === NodeType.Element && childNode.tagName === "img");
|
|
3824
3824
|
if (imageElement && imageElement.attributes) {
|
|
3825
3825
|
imageElement.attributes.src = sourceMap.get(matchingUrl);
|
|
3826
|
+
this.removeResponsiveImageAttributes(imageElement.attributes);
|
|
3826
3827
|
}
|
|
3827
3828
|
}
|
|
3828
3829
|
}
|
|
@@ -3857,6 +3858,10 @@ var _DOMSnapshot = class _DOMSnapshot {
|
|
|
3857
3858
|
});
|
|
3858
3859
|
return currentSrc;
|
|
3859
3860
|
}
|
|
3861
|
+
removeResponsiveImageAttributes(attributes) {
|
|
3862
|
+
delete attributes.srcset;
|
|
3863
|
+
delete attributes.sizes;
|
|
3864
|
+
}
|
|
3860
3865
|
};
|
|
3861
3866
|
__name(_DOMSnapshot, "DOMSnapshot");
|
|
3862
3867
|
var DOMSnapshot = _DOMSnapshot;
|
|
@@ -3871,6 +3876,7 @@ __name(viewportToString, "viewportToString");
|
|
|
3871
3876
|
var sanitize = /* @__PURE__ */ __name((string) => {
|
|
3872
3877
|
return string.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").replace(/[\r\n]/g, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
3873
3878
|
}, "sanitize");
|
|
3879
|
+
var collapseNewlines = /* @__PURE__ */ __name((title) => title.replace(/[\r\n]+/g, " ").trim(), "collapseNewlines");
|
|
3874
3880
|
|
|
3875
3881
|
// ../shared/src/write-archive/snapshot-files.ts
|
|
3876
3882
|
var SNAPSHOT_FILE_EXT = "snapshot.json";
|
|
@@ -3889,49 +3895,57 @@ function snapshotFileName(snapshotId2, viewport) {
|
|
|
3889
3895
|
return fileNameParts.join(".");
|
|
3890
3896
|
}
|
|
3891
3897
|
__name(snapshotFileName, "snapshotFileName");
|
|
3892
|
-
|
|
3893
|
-
// ../shared/src/write-archive/stories-files.ts
|
|
3894
3898
|
var STORIES_FILE_EXT = "stories.json";
|
|
3899
|
+
var uniqueId = {
|
|
3900
|
+
value: 1
|
|
3901
|
+
};
|
|
3895
3902
|
function storiesFileName(testTitle) {
|
|
3896
3903
|
const fileName = [
|
|
3897
|
-
sanitize(testTitle)
|
|
3904
|
+
sanitize(testTitle) + "-" + uniqueId.value++,
|
|
3898
3905
|
STORIES_FILE_EXT
|
|
3899
3906
|
].join(".");
|
|
3900
3907
|
const maxByteLength = MAX_FILE_NAME_BYTE_LENGTH - 25;
|
|
3901
3908
|
return truncateFileName(fileName, maxByteLength);
|
|
3902
3909
|
}
|
|
3903
3910
|
__name(storiesFileName, "storiesFileName");
|
|
3904
|
-
function createStories(
|
|
3911
|
+
function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
|
|
3912
|
+
const title = collapseNewlines(storyTitle);
|
|
3905
3913
|
return {
|
|
3906
3914
|
title,
|
|
3907
|
-
stories: Object.entries(domSnapshots).map(([
|
|
3908
|
-
name
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
server: {
|
|
3917
|
-
id: snapshotId(title, name)
|
|
3915
|
+
stories: Object.entries(domSnapshots).map(([snapshotName, { viewport }]) => {
|
|
3916
|
+
const name = collapseNewlines(snapshotName);
|
|
3917
|
+
return {
|
|
3918
|
+
name,
|
|
3919
|
+
// Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
|
|
3920
|
+
// selects the active one. See https://storybook.js.org/docs/essentials/viewport#defining-the-viewport-for-a-story
|
|
3921
|
+
// `defaultViewport` is not read by SB 10's types but our archive preview uses it as a fetch fallback.
|
|
3922
|
+
globals: {
|
|
3923
|
+
viewport: viewportToString(viewport)
|
|
3918
3924
|
},
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3925
|
+
parameters: {
|
|
3926
|
+
// Work-around for cases where "あ" in story name would cause Storybook to fail to load the story due to an invalid story ID.
|
|
3927
|
+
// See https://github.com/chromaui/chromatic-e2e/issues/365
|
|
3928
|
+
__id: toId(title, storyNameFromExport(name)),
|
|
3929
|
+
server: {
|
|
3930
|
+
id: snapshotId(title, name)
|
|
3931
|
+
},
|
|
3932
|
+
chromatic: {
|
|
3933
|
+
...chromaticStorybookParams,
|
|
3934
|
+
modes: buildStoryModesConfig([
|
|
3935
|
+
viewport
|
|
3936
|
+
])
|
|
3937
|
+
},
|
|
3938
|
+
viewport: {
|
|
3939
|
+
options: buildStoryViewportsConfig([
|
|
3940
|
+
viewport
|
|
3941
|
+
]),
|
|
3942
|
+
defaultViewport: viewportToString(findDefaultViewport([
|
|
3943
|
+
viewport
|
|
3944
|
+
]))
|
|
3945
|
+
}
|
|
3932
3946
|
}
|
|
3933
|
-
}
|
|
3934
|
-
})
|
|
3947
|
+
};
|
|
3948
|
+
})
|
|
3935
3949
|
};
|
|
3936
3950
|
}
|
|
3937
3951
|
__name(createStories, "createStories");
|
|
@@ -4200,38 +4214,21 @@ var performChromaticSnapshot = /* @__PURE__ */ __name(async ({ page, delay, diff
|
|
|
4200
4214
|
}
|
|
4201
4215
|
const resourceArchive = await completeArchive();
|
|
4202
4216
|
const snapshots = chromaticSnapshots.get(testId) || /* @__PURE__ */ new Map();
|
|
4203
|
-
const chromaticStorybookParams = {
|
|
4204
|
-
...delay && {
|
|
4205
|
-
delay
|
|
4206
|
-
},
|
|
4207
|
-
...diffIncludeAntiAliasing && {
|
|
4208
|
-
diffIncludeAntiAliasing
|
|
4209
|
-
},
|
|
4210
|
-
...diffThreshold && {
|
|
4211
|
-
diffThreshold
|
|
4212
|
-
},
|
|
4213
|
-
...forcedColors && {
|
|
4214
|
-
forcedColors
|
|
4215
|
-
},
|
|
4216
|
-
...pauseAnimationAtEnd && {
|
|
4217
|
-
pauseAnimationAtEnd
|
|
4218
|
-
},
|
|
4219
|
-
...prefersReducedMotion && {
|
|
4220
|
-
prefersReducedMotion
|
|
4221
|
-
},
|
|
4222
|
-
...cropToViewport && {
|
|
4223
|
-
cropToViewport
|
|
4224
|
-
},
|
|
4225
|
-
...ignoreSelectors && {
|
|
4226
|
-
ignoreSelectors
|
|
4227
|
-
}
|
|
4228
|
-
};
|
|
4229
4217
|
const outputDir = join(testInfo.outputDir, "..");
|
|
4230
4218
|
await writeTestResult({
|
|
4231
4219
|
...testInfo,
|
|
4232
4220
|
outputDir,
|
|
4233
4221
|
pageUrl: page.url()
|
|
4234
|
-
}, Object.fromEntries(snapshots), resourceArchive,
|
|
4222
|
+
}, Object.fromEntries(snapshots), resourceArchive, {
|
|
4223
|
+
delay,
|
|
4224
|
+
diffIncludeAntiAliasing,
|
|
4225
|
+
diffThreshold,
|
|
4226
|
+
forcedColors,
|
|
4227
|
+
pauseAnimationAtEnd,
|
|
4228
|
+
prefersReducedMotion,
|
|
4229
|
+
cropToViewport,
|
|
4230
|
+
ignoreSelectors
|
|
4231
|
+
});
|
|
4235
4232
|
trackComplete();
|
|
4236
4233
|
} finally {
|
|
4237
4234
|
chromaticSnapshots.delete(testId);
|