@chromatic-com/vitest 1.0.2 → 1.0.3
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { n as archivesDir, t as DEFAULT_OUTPUT_DIR } from "../constants-Dos4OOMt.mjs";
|
|
3
|
-
import { a as flushTelemetry, n as trackCliEvent } from "../telemetry-
|
|
3
|
+
import { a as flushTelemetry, n as trackCliEvent } from "../telemetry-Db1MVI-S.mjs";
|
|
4
4
|
import { t as archiveStorybook } from "../archive-storybook-Bqn7D3Ez.mjs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { n as archivesDir, t as DEFAULT_OUTPUT_DIR } from "../constants-Dos4OOMt.mjs";
|
|
3
|
-
import { a as flushTelemetry, n as trackCliEvent } from "../telemetry-
|
|
3
|
+
import { a as flushTelemetry, n as trackCliEvent } from "../telemetry-Db1MVI-S.mjs";
|
|
4
4
|
import { n as buildArchiveStorybook } from "../archive-storybook-Bqn7D3Ez.mjs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as outputFile, c as truncateFileName, i as ensureDir, o as outputJSONFile, s as removeLocalhostFromBaseUrl, t as DEFAULT_OUTPUT_DIR } from "./constants-Dos4OOMt.mjs";
|
|
2
|
-
import { c as TELEMETRY_LOG_FILE, i as cleanTelemetryLogFiles, o as setupTelemetryCleanup, r as trackEvent, s as resolveTelemetryOptions, t as TelemetryReporter } from "./telemetry-
|
|
2
|
+
import { c as TELEMETRY_LOG_FILE, i as cleanTelemetryLogFiles, o as setupTelemetryCleanup, r as trackEvent, s as resolveTelemetryOptions, t as TelemetryReporter } from "./telemetry-Db1MVI-S.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { existsSync, readFileSync, readdirSync, rmSync } from "node:fs";
|
|
5
5
|
import path, { dirname, join, relative, resolve, sep } from "node:path";
|
|
@@ -1756,11 +1756,8 @@ function snapshotFileName(snapshotId, viewport) {
|
|
|
1756
1756
|
//#endregion
|
|
1757
1757
|
//#region ../shared/src/write-archive/stories-files.ts
|
|
1758
1758
|
const STORIES_FILE_EXT = "stories.json";
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
let title = sanitize(testTitle);
|
|
1762
|
-
if (!overwriteDuplicateNames) title += "-" + uniqueId.value++;
|
|
1763
|
-
const fileName = [title, STORIES_FILE_EXT].join(".");
|
|
1759
|
+
function storiesFileName(testTitle, uniqueId) {
|
|
1760
|
+
const fileName = [sanitize([testTitle, uniqueId].filter(Boolean).join("-")), STORIES_FILE_EXT].join(".");
|
|
1764
1761
|
const maxByteLength = 255 - 25;
|
|
1765
1762
|
return truncateFileName(fileName, maxByteLength);
|
|
1766
1763
|
}
|
|
@@ -1831,8 +1828,8 @@ function findDefaultViewport(viewports) {
|
|
|
1831
1828
|
|
|
1832
1829
|
//#endregion
|
|
1833
1830
|
//#region ../shared/src/write-archive/index.ts
|
|
1834
|
-
async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams
|
|
1835
|
-
const { titlePath, outputDir, pageUrl } = e2eTestInfo;
|
|
1831
|
+
async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams) {
|
|
1832
|
+
const { titlePath, outputDir, pageUrl, storiesFileId } = e2eTestInfo;
|
|
1836
1833
|
const title = titlePath.map((pathPart) => pathPart.replace(/\.(ts|js|mjs|cjs|tsx|jsx|cjsx|coffee)$/, "").replace(/\.(spec|test|cy)$/, "")).join("/").replace(/\/([ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\]+)\//gi, "$1/");
|
|
1837
1834
|
const finalOutputDir = join(outputDir, "chromatic-archives");
|
|
1838
1835
|
const archiveDir = join(finalOutputDir, "archive");
|
|
@@ -1853,7 +1850,7 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
1853
1850
|
const snapshotFile = snapshotFileName(snapshotId(title, name), domSnapshot.viewport);
|
|
1854
1851
|
await outputFile(join(archiveDir, snapshotFile), mappedSnapshot);
|
|
1855
1852
|
}));
|
|
1856
|
-
const storiesFile = join(finalOutputDir, storiesFileName(title,
|
|
1853
|
+
const storiesFile = join(finalOutputDir, storiesFileName(title, storiesFileId));
|
|
1857
1854
|
const storiesJson = createStories(title, domSnapshots, chromaticStorybookParams);
|
|
1858
1855
|
await outputJSONFile(storiesFile, storiesJson);
|
|
1859
1856
|
const errors = Object.entries(archive).filter(([, r]) => "error" in r);
|
|
@@ -2029,6 +2026,8 @@ function pluralize(count, text) {
|
|
|
2029
2026
|
//#region src/node/webpack-stats-reporter.ts
|
|
2030
2027
|
const REPORTER_NAME = "chromatic-webpack-stats-reporter";
|
|
2031
2028
|
const VIRTUAL_MODULE_PREFIX = "\0";
|
|
2029
|
+
const VITE_APP_FILE = "/virtual:/@storybook/builder-vite/vite-app.js";
|
|
2030
|
+
const VITE_STORIES_FILE = "/virtual:/@storybook/builder-vite/storybook-stories.js";
|
|
2032
2031
|
var WebpackStatsReporter = class WebpackStatsReporter {
|
|
2033
2032
|
ctx;
|
|
2034
2033
|
options;
|
|
@@ -2086,6 +2085,11 @@ var WebpackStatsReporter = class WebpackStatsReporter {
|
|
|
2086
2085
|
}
|
|
2087
2086
|
async writePreviewStats(testModules) {
|
|
2088
2087
|
const statsMap = /* @__PURE__ */ new Map();
|
|
2088
|
+
if (this.moduleIdsToStoryFiles.size > 0) statsMap.set(VITE_STORIES_FILE, {
|
|
2089
|
+
id: VITE_STORIES_FILE,
|
|
2090
|
+
name: VITE_STORIES_FILE,
|
|
2091
|
+
reasons: [{ moduleName: VITE_APP_FILE }]
|
|
2092
|
+
});
|
|
2089
2093
|
for (const testModule of testModules) {
|
|
2090
2094
|
const storyFiles = this.moduleIdsToStoryFiles.get(testModule.moduleId);
|
|
2091
2095
|
if (!storyFiles || storyFiles.size === 0) continue;
|
|
@@ -2094,8 +2098,18 @@ var WebpackStatsReporter = class WebpackStatsReporter {
|
|
|
2094
2098
|
const id = this.normalize(testModule.moduleId);
|
|
2095
2099
|
const additionalModules = [];
|
|
2096
2100
|
statsMap.set(id, this.createStatsMapModule(id, [...storyFiles]));
|
|
2097
|
-
|
|
2098
|
-
|
|
2101
|
+
for (const storyFile of storyFiles) {
|
|
2102
|
+
const name = this.normalize(storyFile);
|
|
2103
|
+
const storyFileId = `./${name}`;
|
|
2104
|
+
statsMap.set(storyFileId, {
|
|
2105
|
+
id: storyFileId,
|
|
2106
|
+
name,
|
|
2107
|
+
reasons: [{ moduleName: VITE_STORIES_FILE }]
|
|
2108
|
+
});
|
|
2109
|
+
}
|
|
2110
|
+
const configFile = testModule.project.vite.config.configFile;
|
|
2111
|
+
if (configFile) additionalModules.push({
|
|
2112
|
+
id: configFile,
|
|
2099
2113
|
isInModuleGraph: false
|
|
2100
2114
|
});
|
|
2101
2115
|
for (const setupFile of testModule.project.config.setupFiles) additionalModules.push({
|
|
@@ -2154,7 +2168,7 @@ var WebpackStatsReporter = class WebpackStatsReporter {
|
|
|
2154
2168
|
};
|
|
2155
2169
|
}
|
|
2156
2170
|
normalize(filePath) {
|
|
2157
|
-
return relative(
|
|
2171
|
+
return relative(process.cwd(), filePath).replaceAll(sep, "/").split("?")[0];
|
|
2158
2172
|
}
|
|
2159
2173
|
};
|
|
2160
2174
|
function isWebpackStatsReporter(reporter) {
|
|
@@ -2310,7 +2324,8 @@ function createCommands(options) {
|
|
|
2310
2324
|
const { storiesFile } = await writeTestResult({
|
|
2311
2325
|
outputDir: resolve(context.project.vitest.config.root, options.outputDirectory),
|
|
2312
2326
|
pageUrl: context.page.url(),
|
|
2313
|
-
titlePath
|
|
2327
|
+
titlePath,
|
|
2328
|
+
storiesFileId: getStoriesFileId(entity, testOptions)
|
|
2314
2329
|
}, snapshotBuffers, archive, {
|
|
2315
2330
|
delay: testOptions.delay ?? options.delay,
|
|
2316
2331
|
diffIncludeAntiAliasing: testOptions.diffIncludeAntiAliasing ?? options.diffIncludeAntiAliasing,
|
|
@@ -2320,7 +2335,7 @@ function createCommands(options) {
|
|
|
2320
2335
|
prefersReducedMotion: testOptions.prefersReducedMotion ?? options.prefersReducedMotion,
|
|
2321
2336
|
cropToViewport: testOptions.cropToViewport ?? options.cropToViewport,
|
|
2322
2337
|
ignoreSelectors: testOptions.ignoreSelectors ?? options.ignoreSelectors
|
|
2323
|
-
}
|
|
2338
|
+
});
|
|
2324
2339
|
if (options.turboSnap) WebpackStatsReporter.onStoryFileWrite(context.project.vitest, entity, storiesFile);
|
|
2325
2340
|
trackEvent({
|
|
2326
2341
|
eventType: "archives_created",
|
|
@@ -2402,6 +2417,19 @@ function getTitle(test) {
|
|
|
2402
2417
|
if (test.project.vitest.projects.filter((project) => project.config.browser.name === "chromium").length > 1 && test.project.name) names.unshift(test.project.name);
|
|
2403
2418
|
return names;
|
|
2404
2419
|
}
|
|
2420
|
+
function getStoriesFileId(test, testOptions) {
|
|
2421
|
+
const position = getTestPosition(test);
|
|
2422
|
+
if (testOptions.title) return [...getTitle(test), position].join("-");
|
|
2423
|
+
return position;
|
|
2424
|
+
}
|
|
2425
|
+
function getTestPosition(test) {
|
|
2426
|
+
let index = 0;
|
|
2427
|
+
for (const entry of test.module.children.allTests()) {
|
|
2428
|
+
if (entry.id === test.id) return String(index);
|
|
2429
|
+
index++;
|
|
2430
|
+
}
|
|
2431
|
+
throw new Error(`Test "${test.fullName}" not found from its test module ${test.module.moduleId}`);
|
|
2432
|
+
}
|
|
2405
2433
|
function getSnapshotPrefix(test) {
|
|
2406
2434
|
const names = [test.name];
|
|
2407
2435
|
let current = test;
|
|
@@ -47,11 +47,12 @@ var VitestStatsPlugin = class {
|
|
|
47
47
|
if (existsSync(previewStats)) compiler.hooks.done.tap("Vitest Stats Plugin", (stats) => {
|
|
48
48
|
const { modules } = JSON.parse(readFileSync(previewStats, "utf-8"));
|
|
49
49
|
const toJson = stats.toJson.bind(stats);
|
|
50
|
+
const testModules = modules.filter((mod) => !mod.name.endsWith(".stories.json") && mod.name !== "/virtual:/@storybook/builder-vite/storybook-stories.js");
|
|
50
51
|
stats.toJson = (...args) => {
|
|
51
52
|
const json = toJson(...args);
|
|
52
53
|
return {
|
|
53
54
|
...json,
|
|
54
|
-
modules: [...json.modules || [], ...
|
|
55
|
+
modules: [...json.modules || [], ...testModules]
|
|
55
56
|
};
|
|
56
57
|
};
|
|
57
58
|
});
|