@chromatic-com/vitest 0.1.8 → 0.1.9
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 +29 -20
- package/dist/setupFile.js +2 -2
- package/package.json +1 -2
package/dist/plugin.js
CHANGED
|
@@ -237,6 +237,7 @@ var require_srcset = __commonJS({
|
|
|
237
237
|
// src/node/plugin.ts
|
|
238
238
|
import { existsSync as existsSync4, readdirSync, rmSync } from "node:fs";
|
|
239
239
|
import { resolve as resolve4 } from "node:path";
|
|
240
|
+
import { version as vitestVersion } from "vitest/node";
|
|
240
241
|
import colors2 from "tinyrainbow";
|
|
241
242
|
|
|
242
243
|
// ../shared/src/utils/logger.ts
|
|
@@ -897,12 +898,6 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
897
898
|
return { storiesFile };
|
|
898
899
|
}
|
|
899
900
|
|
|
900
|
-
// ../shared/src/utils/analytics.ts
|
|
901
|
-
import { Analytics } from "@segment/analytics-node";
|
|
902
|
-
var analytics = new Analytics({
|
|
903
|
-
writeKey: process.env.SEGMENT_WRITE_KEY || "cwWhBWso2gwzyenW29CnCp30Kjz4DogE"
|
|
904
|
-
});
|
|
905
|
-
|
|
906
901
|
// ../shared/src/constants.ts
|
|
907
902
|
var DEFAULT_GLOBAL_RESOURCE_ARCHIVE_TIMEOUT_MS = 1e4;
|
|
908
903
|
|
|
@@ -1114,6 +1109,7 @@ function pluralize(count, text) {
|
|
|
1114
1109
|
import { existsSync as existsSync3, readFileSync } from "node:fs";
|
|
1115
1110
|
import { mkdir, readdir, readFile, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
1116
1111
|
import { dirname, relative as relative2, resolve as resolve2, sep } from "node:path";
|
|
1112
|
+
import { isCSSRequest } from "vitest/node";
|
|
1117
1113
|
var REPORTER_NAME2 = "chromatic-webpack-stats-reporter";
|
|
1118
1114
|
var VIRTUAL_MODULE_PREFIX = "\0";
|
|
1119
1115
|
var WebpackStatsReporter = class _WebpackStatsReporter {
|
|
@@ -1176,14 +1172,22 @@ var WebpackStatsReporter = class _WebpackStatsReporter {
|
|
|
1176
1172
|
continue;
|
|
1177
1173
|
}
|
|
1178
1174
|
const id = this.normalize(testModule.moduleId);
|
|
1175
|
+
const additionalModules = [];
|
|
1179
1176
|
statsMap.set(id, this.createStatsMapModule(id, [...storyFiles]));
|
|
1180
1177
|
if (testModule.project.config.config) {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1178
|
+
additionalModules.push({ id: testModule.project.config.config, isInModuleGraph: false });
|
|
1179
|
+
}
|
|
1180
|
+
for (const setupFile of testModule.project.config.setupFiles) {
|
|
1181
|
+
additionalModules.push({ id: setupFile, isInModuleGraph: true });
|
|
1185
1182
|
}
|
|
1186
|
-
this.addModule(
|
|
1183
|
+
this.addModule(
|
|
1184
|
+
testModule.moduleId,
|
|
1185
|
+
statsMap,
|
|
1186
|
+
vite.moduleGraph,
|
|
1187
|
+
vite.config.cacheDir,
|
|
1188
|
+
/* @__PURE__ */ new Set(),
|
|
1189
|
+
additionalModules
|
|
1190
|
+
);
|
|
1187
1191
|
}
|
|
1188
1192
|
if (!existsSync3(dirname(this.options.outputFile))) {
|
|
1189
1193
|
await mkdir(dirname(this.options.outputFile), { recursive: true });
|
|
@@ -1194,7 +1198,7 @@ var WebpackStatsReporter = class _WebpackStatsReporter {
|
|
|
1194
1198
|
"utf-8"
|
|
1195
1199
|
);
|
|
1196
1200
|
}
|
|
1197
|
-
addModule(id, statsMap, moduleGraph, cacheDir, visited =
|
|
1201
|
+
addModule(id, statsMap, moduleGraph, cacheDir, visited, additionalModules = []) {
|
|
1198
1202
|
if (visited.has(id)) {
|
|
1199
1203
|
return;
|
|
1200
1204
|
}
|
|
@@ -1205,10 +1209,13 @@ var WebpackStatsReporter = class _WebpackStatsReporter {
|
|
|
1205
1209
|
`[chromatic] Could not find module for id ${id}. Excluding from TurboSnap.`
|
|
1206
1210
|
);
|
|
1207
1211
|
}
|
|
1208
|
-
const importedModules = [];
|
|
1212
|
+
const importedModules = [...additionalModules];
|
|
1209
1213
|
for (const imported of mod.importedModules) {
|
|
1210
1214
|
if (imported.id == null) {
|
|
1211
1215
|
if (imported.file) {
|
|
1216
|
+
if (mod.file && isCSSRequest(mod.file) && !isCSSRequest(imported.file)) {
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1212
1219
|
importedModules.push({ id: imported.file, isInModuleGraph: false });
|
|
1213
1220
|
}
|
|
1214
1221
|
continue;
|
|
@@ -1344,13 +1351,6 @@ function createCommands(options) {
|
|
|
1344
1351
|
const savedResults = /* @__PURE__ */ new Set();
|
|
1345
1352
|
const snapshots = /* @__PURE__ */ new Map();
|
|
1346
1353
|
return {
|
|
1347
|
-
/**
|
|
1348
|
-
* Get resolved options on the client side.
|
|
1349
|
-
* All options must be serializable at this point.
|
|
1350
|
-
*/
|
|
1351
|
-
async __chromatic_getOptions() {
|
|
1352
|
-
return options;
|
|
1353
|
-
},
|
|
1354
1354
|
/**
|
|
1355
1355
|
* Store a `@rrweb` generated DOM snapshot for the test.
|
|
1356
1356
|
* Can be called multiple times during a single test case.
|
|
@@ -1587,12 +1587,21 @@ function chromaticPlugin(userOptions = {}) {
|
|
|
1587
1587
|
);
|
|
1588
1588
|
return {
|
|
1589
1589
|
name: "vitest:chromatic",
|
|
1590
|
+
enforce: "pre",
|
|
1591
|
+
resolveId(id) {
|
|
1592
|
+
if (id === "vitest/suite" && !vitestVersion.startsWith("4.0")) {
|
|
1593
|
+
return "vitest";
|
|
1594
|
+
}
|
|
1595
|
+
},
|
|
1590
1596
|
config() {
|
|
1591
1597
|
return {
|
|
1592
1598
|
optimizeDeps: {
|
|
1593
1599
|
entries: [setupFile]
|
|
1594
1600
|
},
|
|
1595
1601
|
test: {
|
|
1602
|
+
provide: {
|
|
1603
|
+
__chromatic_options: options
|
|
1604
|
+
},
|
|
1596
1605
|
browser: {
|
|
1597
1606
|
commands: createCommands(options)
|
|
1598
1607
|
}
|
package/dist/setupFile.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/browser/setupFile.ts
|
|
2
|
-
import { afterEach, beforeEach } from "vitest";
|
|
2
|
+
import { afterEach, beforeEach, inject } from "vitest";
|
|
3
3
|
import { commands as commands3 } from "vitest/browser";
|
|
4
4
|
|
|
5
5
|
// src/browser/public/takeSnapshot.ts
|
|
@@ -117,7 +117,7 @@ Make sure ${test.file.projectName || "root"} project has chromaticPlugin() enabl
|
|
|
117
117
|
|
|
118
118
|
// src/browser/setupFile.ts
|
|
119
119
|
beforeEach(async ({ task }) => {
|
|
120
|
-
const options =
|
|
120
|
+
const options = inject("__chromatic_options");
|
|
121
121
|
if (options.tags) {
|
|
122
122
|
const hasMatchingTag = task.tags?.some((tag) => options.tags?.includes(tag));
|
|
123
123
|
if (!hasMatchingTag) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chromatic-com/vitest",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Chromatic Visual Regression Testing for Vitest",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@chromaui/rrweb-snapshot": "2.0.0-alpha.19-noAbsolute",
|
|
35
|
-
"@segment/analytics-node": "2.1.3",
|
|
36
35
|
"storybook": "10.2.13",
|
|
37
36
|
"tinyrainbow": "^3.1.0"
|
|
38
37
|
},
|