@chromatic-com/vitest 0.1.3 → 0.1.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/plugin.js
CHANGED
|
@@ -3674,6 +3674,10 @@ var ArchiveFile = class {
|
|
|
3674
3674
|
if (!queryString)
|
|
3675
3675
|
return pathname;
|
|
3676
3676
|
const safeQueryString = this.hash(queryString);
|
|
3677
|
+
const extension = path2.extname(pathname);
|
|
3678
|
+
if (extension) {
|
|
3679
|
+
return `${pathname.substring(0, pathname.length - extension.length)}-${safeQueryString}${extension}`;
|
|
3680
|
+
}
|
|
3677
3681
|
return `${pathname}-${safeQueryString}`;
|
|
3678
3682
|
}
|
|
3679
3683
|
truncateFileName(pathname) {
|
|
@@ -3916,9 +3920,13 @@ var STORIES_FILE_EXT = "stories.json";
|
|
|
3916
3920
|
var uniqueId = {
|
|
3917
3921
|
value: 1
|
|
3918
3922
|
};
|
|
3919
|
-
function storiesFileName(testTitle) {
|
|
3923
|
+
function storiesFileName(testTitle, overwriteDuplicateNames = true) {
|
|
3924
|
+
let title = sanitize(testTitle);
|
|
3925
|
+
if (!overwriteDuplicateNames) {
|
|
3926
|
+
title += "-" + uniqueId.value++;
|
|
3927
|
+
}
|
|
3920
3928
|
const fileName = [
|
|
3921
|
-
|
|
3929
|
+
title,
|
|
3922
3930
|
STORIES_FILE_EXT
|
|
3923
3931
|
].join(".");
|
|
3924
3932
|
const maxByteLength = MAX_FILE_NAME_BYTE_LENGTH - 25;
|
|
@@ -4019,7 +4027,7 @@ function findDefaultViewport(viewports) {
|
|
|
4019
4027
|
__name(findDefaultViewport, "findDefaultViewport");
|
|
4020
4028
|
|
|
4021
4029
|
// ../shared/src/write-archive/index.ts
|
|
4022
|
-
async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams) {
|
|
4030
|
+
async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams, testRunner) {
|
|
4023
4031
|
const { titlePath, outputDir, pageUrl } = e2eTestInfo;
|
|
4024
4032
|
const titlePathWithoutFileExtensions = titlePath.map((pathPart) => (
|
|
4025
4033
|
// make sure we remove file extensions, even if the file name doesn't have .spec or .test or.cy
|
|
@@ -4054,7 +4062,7 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
4054
4062
|
const snapshotFile = snapshotFileName(snapshotId(title, name), domSnapshot.viewport);
|
|
4055
4063
|
await outputFile(join(archiveDir, snapshotFile), mappedSnapshot);
|
|
4056
4064
|
}));
|
|
4057
|
-
const storiesFile = storiesFileName(title);
|
|
4065
|
+
const storiesFile = storiesFileName(title, testRunner !== "vitest");
|
|
4058
4066
|
const storiesJson = createStories(title, domSnapshots, chromaticStorybookParams);
|
|
4059
4067
|
await outputJSONFile(join(finalOutputDir, storiesFile), storiesJson);
|
|
4060
4068
|
const errors = Object.entries(archive).filter(([, r]) => "error" in r);
|
|
@@ -4079,6 +4087,7 @@ var DEFAULT_GLOBAL_RESOURCE_ARCHIVE_TIMEOUT_MS = 1e4;
|
|
|
4079
4087
|
// src/node/commands.ts
|
|
4080
4088
|
import assert from "node:assert";
|
|
4081
4089
|
import { resolve as resolve2 } from "node:path";
|
|
4090
|
+
import { storyNameFromExport as storyNameFromExport2, toId as toId2 } from "storybook/internal/csf";
|
|
4082
4091
|
|
|
4083
4092
|
// src/node/NetworkIdleTracker.ts
|
|
4084
4093
|
var NetworkIdleTimeoutError = class NetworkIdleTimeoutError2 extends Error {
|
|
@@ -4287,6 +4296,7 @@ __name(pluralize, "pluralize");
|
|
|
4287
4296
|
function createCommands(options) {
|
|
4288
4297
|
const resourceArchivers = /* @__PURE__ */ new Map();
|
|
4289
4298
|
const networkIdleTrackers = /* @__PURE__ */ new Map();
|
|
4299
|
+
const savedResults = /* @__PURE__ */ new Set();
|
|
4290
4300
|
const snapshots = /* @__PURE__ */ new Map();
|
|
4291
4301
|
return {
|
|
4292
4302
|
/**
|
|
@@ -4363,8 +4373,14 @@ function createCommands(options) {
|
|
|
4363
4373
|
const { archive, sessionSnapshots } = await onTestCleanup(context, id);
|
|
4364
4374
|
assert(sessionSnapshots, `No snapshots found for test ${id}`);
|
|
4365
4375
|
const snapshotBuffers = {};
|
|
4376
|
+
const titlePath = testOptions.title ? [
|
|
4377
|
+
testOptions.title
|
|
4378
|
+
] : getTitle(entity);
|
|
4366
4379
|
for (const [name, { snapshot, viewport, pseudoClassIds }] of sessionSnapshots) {
|
|
4367
|
-
const names =
|
|
4380
|
+
const names = generateUniqueSnapshotName({
|
|
4381
|
+
snapshotName: getSnapshotPrefix(entity).concat(name),
|
|
4382
|
+
titlePath
|
|
4383
|
+
});
|
|
4368
4384
|
snapshotBuffers[names] = {
|
|
4369
4385
|
snapshot: Buffer.from(JSON.stringify(snapshot)),
|
|
4370
4386
|
viewport,
|
|
@@ -4383,9 +4399,7 @@ function createCommands(options) {
|
|
|
4383
4399
|
await writeTestResult({
|
|
4384
4400
|
outputDir: resolve2(context.project.vitest.config.root, options.outputDirectory),
|
|
4385
4401
|
pageUrl: context.page.url(),
|
|
4386
|
-
titlePath
|
|
4387
|
-
testOptions.title
|
|
4388
|
-
] : getTitle(entity)
|
|
4402
|
+
titlePath
|
|
4389
4403
|
}, snapshotBuffers, archive, {
|
|
4390
4404
|
delay: testOptions.delay ?? options.delay,
|
|
4391
4405
|
diffIncludeAntiAliasing: testOptions.diffIncludeAntiAliasing ?? options.diffIncludeAntiAliasing,
|
|
@@ -4395,7 +4409,7 @@ function createCommands(options) {
|
|
|
4395
4409
|
prefersReducedMotion: testOptions.prefersReducedMotion ?? options.prefersReducedMotion,
|
|
4396
4410
|
cropToViewport: testOptions.cropToViewport ?? options.cropToViewport,
|
|
4397
4411
|
ignoreSelectors: testOptions.ignoreSelectors ?? options.ignoreSelectors
|
|
4398
|
-
});
|
|
4412
|
+
}, "vitest");
|
|
4399
4413
|
},
|
|
4400
4414
|
/**
|
|
4401
4415
|
* Clear test state without writing test results.
|
|
@@ -4413,6 +4427,7 @@ function createCommands(options) {
|
|
|
4413
4427
|
resourceArchivers.clear();
|
|
4414
4428
|
networkIdleTrackers.clear();
|
|
4415
4429
|
snapshots.clear();
|
|
4430
|
+
savedResults.clear();
|
|
4416
4431
|
},
|
|
4417
4432
|
/**
|
|
4418
4433
|
* Get currently save snapshots. Used only during testing.
|
|
@@ -4437,6 +4452,21 @@ function createCommands(options) {
|
|
|
4437
4452
|
};
|
|
4438
4453
|
}
|
|
4439
4454
|
__name(onTestCleanup, "onTestCleanup");
|
|
4455
|
+
function generateUniqueSnapshotName(options2) {
|
|
4456
|
+
const names = options2.snapshotName.join(" / ");
|
|
4457
|
+
const base = toId2(options2.titlePath.join(" / "), storyNameFromExport2(names));
|
|
4458
|
+
let key = base;
|
|
4459
|
+
let count = 1;
|
|
4460
|
+
while (savedResults.has(key)) {
|
|
4461
|
+
key = `${base} (${count++})`;
|
|
4462
|
+
}
|
|
4463
|
+
savedResults.add(key);
|
|
4464
|
+
if (count > 1) {
|
|
4465
|
+
return `${names} (${count})`;
|
|
4466
|
+
}
|
|
4467
|
+
return names;
|
|
4468
|
+
}
|
|
4469
|
+
__name(generateUniqueSnapshotName, "generateUniqueSnapshotName");
|
|
4440
4470
|
}
|
|
4441
4471
|
__name(createCommands, "createCommands");
|
|
4442
4472
|
function getTitle(test) {
|
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
managerEntries: string[];
|
|
5
|
-
previewAnnotations: string[];
|
|
6
|
-
framework: {
|
|
7
|
-
name: string;
|
|
8
|
-
options: {};
|
|
9
|
-
};
|
|
10
|
-
core: {
|
|
11
|
-
builder: string;
|
|
12
|
-
renderer: string;
|
|
13
|
-
};
|
|
14
|
-
staticDirs: string[];
|
|
15
|
-
features: {
|
|
16
|
-
sidebarOnboardingChecklist: boolean;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
1
|
+
import { StorybookConfig } from '@storybook/server-webpack5';
|
|
2
|
+
|
|
3
|
+
declare const _default: StorybookConfig;
|
|
19
4
|
|
|
20
5
|
export { _default as default };
|