@storybook/addon-vitest 0.0.0-pr-33084-sha-cad8b371 → 0.0.0-pr-33090-sha-f6174c82
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/_node-chunks/{chunk-UVNWEKXU.js → chunk-2KF2VISY.js} +6 -6
- package/dist/_node-chunks/{chunk-DHBLIYPM.js → chunk-C27EWYAE.js} +7 -7
- package/dist/_node-chunks/chunk-JDY32SOO.js +35 -0
- package/dist/_node-chunks/{chunk-IWSMEVJY.js → chunk-KAKLJ54A.js} +6 -6
- package/dist/_node-chunks/{chunk-FGHKXVYO.js → chunk-KR7B4BKU.js} +7 -7
- package/dist/_node-chunks/chunk-LSQEC7U2.js +69 -0
- package/dist/_node-chunks/chunk-UFZVJPFP.js +1697 -0
- package/dist/_node-chunks/{chunk-XUPZVVFE.js → chunk-UO6Q7EWR.js} +19 -7
- package/dist/manager.js +1 -1
- package/dist/node/coverage-reporter.js +8 -8
- package/dist/node/vitest.js +14 -24
- package/dist/postinstall.js +290 -152
- package/dist/preset.js +25 -30
- package/dist/vitest-plugin/global-setup.js +9 -8
- package/dist/vitest-plugin/index.js +12 -14
- package/dist/vitest-plugin/setup-file.js +1 -1
- package/package.json +7 -3
- package/dist/_node-chunks/chunk-FJ5HQKB2.js +0 -38
- package/dist/_node-chunks/chunk-IGKOEQMS.js +0 -61
- package/dist/_node-chunks/chunk-XTACI747.js +0 -44
- package/dist/_node-chunks/chunk-YP4PEG4E.js +0 -158
- /package/dist/_browser-chunks/{chunk-TYJENCK5.js → chunk-ULSHVN74.js} +0 -0
package/dist/postinstall.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_gak4y1elpfo from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_gak4y1elpfo from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_gak4y1elpfo from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_gak4y1elpfo.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_gak4y1elpfo.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_gak4y1elpfo.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
import {
|
|
13
|
+
execa,
|
|
13
14
|
resolvePackageDir
|
|
14
|
-
} from "./_node-chunks/chunk-
|
|
15
|
+
} from "./_node-chunks/chunk-UFZVJPFP.js";
|
|
15
16
|
import {
|
|
16
|
-
any
|
|
17
|
-
|
|
17
|
+
any,
|
|
18
|
+
getAddonNames,
|
|
19
|
+
up
|
|
20
|
+
} from "./_node-chunks/chunk-LSQEC7U2.js";
|
|
18
21
|
import {
|
|
19
|
-
DOCUMENTATION_LINK
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
require_dist
|
|
23
|
-
} from "./_node-chunks/chunk-IGKOEQMS.js";
|
|
22
|
+
DOCUMENTATION_LINK,
|
|
23
|
+
SUPPORTED_FRAMEWORKS
|
|
24
|
+
} from "./_node-chunks/chunk-UO6Q7EWR.js";
|
|
24
25
|
import {
|
|
25
26
|
dirname,
|
|
26
27
|
join,
|
|
27
28
|
relative,
|
|
28
29
|
resolve
|
|
29
|
-
} from "./_node-chunks/chunk-
|
|
30
|
+
} from "./_node-chunks/chunk-2KF2VISY.js";
|
|
30
31
|
import {
|
|
31
32
|
require_compare,
|
|
32
33
|
require_constants,
|
|
@@ -36,11 +37,11 @@ import {
|
|
|
36
37
|
require_parse_options,
|
|
37
38
|
require_re,
|
|
38
39
|
require_semver
|
|
39
|
-
} from "./_node-chunks/chunk-
|
|
40
|
+
} from "./_node-chunks/chunk-KR7B4BKU.js";
|
|
40
41
|
import {
|
|
41
42
|
__commonJS,
|
|
42
43
|
__toESM
|
|
43
|
-
} from "./_node-chunks/chunk-
|
|
44
|
+
} from "./_node-chunks/chunk-KAKLJ54A.js";
|
|
44
45
|
|
|
45
46
|
// ../../node_modules/semver/functions/parse.js
|
|
46
47
|
var require_parse = __commonJS({
|
|
@@ -294,7 +295,7 @@ var require_cmp = __commonJS({
|
|
|
294
295
|
var require_coerce = __commonJS({
|
|
295
296
|
"../../node_modules/semver/functions/coerce.js"(exports, module) {
|
|
296
297
|
"use strict";
|
|
297
|
-
var SemVer = require_semver(), parse = require_parse(), { safeRe: re, t } = require_re(),
|
|
298
|
+
var SemVer = require_semver(), parse = require_parse(), { safeRe: re, t } = require_re(), coerce2 = (version, options) => {
|
|
298
299
|
if (version instanceof SemVer)
|
|
299
300
|
return version;
|
|
300
301
|
if (typeof version == "number" && (version = String(version)), typeof version != "string")
|
|
@@ -314,7 +315,7 @@ var require_coerce = __commonJS({
|
|
|
314
315
|
let major = match[2], minor = match[3] || "0", patch = match[4] || "0", prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : "", build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
|
|
315
316
|
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
|
|
316
317
|
};
|
|
317
|
-
module.exports =
|
|
318
|
+
module.exports = coerce2;
|
|
318
319
|
}
|
|
319
320
|
});
|
|
320
321
|
|
|
@@ -819,7 +820,7 @@ var require_subset = __commonJS({
|
|
|
819
820
|
var require_semver2 = __commonJS({
|
|
820
821
|
"../../node_modules/semver/index.js"(exports, module) {
|
|
821
822
|
"use strict";
|
|
822
|
-
var internalRe = require_re(), constants = require_constants(), SemVer = require_semver(), identifiers = require_identifiers(), parse = require_parse(), valid = require_valid(), clean = require_clean(), inc = require_inc(), diff = require_diff(), major = require_major(), minor = require_minor(), patch = require_patch(), prerelease = require_prerelease(), compare = require_compare(), rcompare = require_rcompare(), compareLoose = require_compare_loose(), compareBuild = require_compare_build(), sort = require_sort(), rsort = require_rsort(), gt = require_gt(), lt = require_lt(), eq = require_eq(), neq = require_neq(), gte = require_gte(), lte = require_lte(), cmp = require_cmp(),
|
|
823
|
+
var internalRe = require_re(), constants = require_constants(), SemVer = require_semver(), identifiers = require_identifiers(), parse = require_parse(), valid = require_valid(), clean = require_clean(), inc = require_inc(), diff = require_diff(), major = require_major(), minor = require_minor(), patch = require_patch(), prerelease = require_prerelease(), compare = require_compare(), rcompare = require_rcompare(), compareLoose = require_compare_loose(), compareBuild = require_compare_build(), sort = require_sort(), rsort = require_rsort(), gt = require_gt(), lt = require_lt(), eq = require_eq(), neq = require_neq(), gte = require_gte(), lte = require_lte(), cmp = require_cmp(), coerce2 = require_coerce(), Comparator = require_comparator(), Range = require_range(), satisfies2 = require_satisfies(), toComparators = require_to_comparators(), maxSatisfying = require_max_satisfying(), minSatisfying = require_min_satisfying(), minVersion = require_min_version(), validRange = require_valid2(), outside = require_outside(), gtr = require_gtr(), ltr = require_ltr(), intersects = require_intersects(), simplifyRange = require_simplify(), subset = require_subset();
|
|
823
824
|
module.exports = {
|
|
824
825
|
parse,
|
|
825
826
|
valid,
|
|
@@ -843,7 +844,7 @@ var require_semver2 = __commonJS({
|
|
|
843
844
|
gte,
|
|
844
845
|
lte,
|
|
845
846
|
cmp,
|
|
846
|
-
coerce,
|
|
847
|
+
coerce: coerce2,
|
|
847
848
|
Comparator,
|
|
848
849
|
Range,
|
|
849
850
|
satisfies: satisfies2,
|
|
@@ -874,21 +875,42 @@ var require_semver2 = __commonJS({
|
|
|
874
875
|
import { existsSync } from "node:fs";
|
|
875
876
|
import * as fs2 from "node:fs/promises";
|
|
876
877
|
import { writeFile } from "node:fs/promises";
|
|
877
|
-
import {
|
|
878
|
-
import {
|
|
878
|
+
import { isAbsolute, posix, sep } from "node:path";
|
|
879
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
880
|
+
import { babelParse, generate, traverse } from "storybook/internal/babel";
|
|
879
881
|
import {
|
|
880
882
|
JsPackageManagerFactory,
|
|
881
883
|
formatFileContent,
|
|
884
|
+
getInterpretedFile,
|
|
882
885
|
getProjectRoot,
|
|
883
|
-
|
|
886
|
+
isCI as isCI2,
|
|
887
|
+
loadMainConfig,
|
|
888
|
+
scanAndTransformFiles,
|
|
889
|
+
transformImportFiles
|
|
884
890
|
} from "storybook/internal/common";
|
|
885
|
-
import {
|
|
886
|
-
import {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
891
|
+
import { experimental_loadStorybook } from "storybook/internal/core-server";
|
|
892
|
+
import { readConfig, writeConfig } from "storybook/internal/csf-tools";
|
|
893
|
+
import { logger as logger2 } from "storybook/internal/node-logger";
|
|
894
|
+
|
|
895
|
+
// ../../node_modules/empathic/package.mjs
|
|
896
|
+
function up2(options) {
|
|
897
|
+
return up("package.json", options);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// src/postinstall.ts
|
|
901
|
+
var import_semver = __toESM(require_semver2(), 1);
|
|
902
|
+
import prompts from "prompts";
|
|
903
|
+
import { dedent } from "ts-dedent";
|
|
904
|
+
|
|
905
|
+
// src/postinstall-logger.ts
|
|
906
|
+
import { isCI } from "storybook/internal/common";
|
|
907
|
+
import { colors, logger } from "storybook/internal/node-logger";
|
|
908
|
+
var fancy = process.platform !== "win32" || isCI() || process.env.TERM === "xterm-256color", step = colors.gray("\u203A"), info = colors.blue(fancy ? "\u2139" : "i"), success = colors.green(fancy ? "\u2714" : "\u221A"), warning = colors.orange(fancy ? "\u26A0" : "\u203C"), error = colors.red(fancy ? "\u2716" : "\xD7"), baseOptions = {
|
|
909
|
+
borderStyle: "round",
|
|
910
|
+
padding: 1
|
|
911
|
+
}, print = (message, options) => {
|
|
912
|
+
logger.line(1), logger.logBox(message, { ...baseOptions, ...options });
|
|
913
|
+
}, printInfo = (title, message, options) => print(message, { borderColor: "blue", title, ...options }), printWarning = (title, message, options) => print(message, { borderColor: "yellow", title, ...options }), printError = (title, message, options) => print(message, { borderColor: "red", title, ...options }), printSuccess = (title, message, options) => print(message, { borderColor: "green", title, ...options });
|
|
892
914
|
|
|
893
915
|
// src/updateVitestFile.ts
|
|
894
916
|
import * as fs from "node:fs/promises";
|
|
@@ -1038,91 +1060,167 @@ var loadTemplate = async (name, replacements) => {
|
|
|
1038
1060
|
};
|
|
1039
1061
|
|
|
1040
1062
|
// src/postinstall.ts
|
|
1041
|
-
var ADDON_NAME = "@storybook/addon-vitest", EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".cts", ".mts", ".cjs", ".mjs"], addonA11yName = "@storybook/addon-a11y";
|
|
1063
|
+
var ADDON_NAME = "@storybook/addon-vitest", EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".cts", ".mts", ".cjs", ".mjs"], addonA11yName = "@storybook/addon-a11y", hasErrors = !1;
|
|
1064
|
+
function nameMatches(name, pattern) {
|
|
1065
|
+
return !!(name === pattern || name.includes(`${pattern}${sep}`) || name.includes(`${pattern}${posix.sep}`));
|
|
1066
|
+
}
|
|
1067
|
+
var logErrors = (...args) => {
|
|
1068
|
+
hasErrors = !0, printError(...args);
|
|
1069
|
+
}, findFile = (basename, extensions = EXTENSIONS) => any(
|
|
1070
|
+
extensions.map((ext) => basename + ext),
|
|
1071
|
+
{ last: getProjectRoot() }
|
|
1072
|
+
);
|
|
1042
1073
|
async function postInstall(options) {
|
|
1043
|
-
|
|
1074
|
+
printSuccess(
|
|
1075
|
+
"\u{1F44B} Howdy!",
|
|
1076
|
+
dedent`
|
|
1077
|
+
I'm the installation helper for ${ADDON_NAME}
|
|
1078
|
+
|
|
1079
|
+
Hold on for a moment while I look at your project and get it set up...
|
|
1080
|
+
`
|
|
1081
|
+
);
|
|
1082
|
+
let packageManager = JsPackageManagerFactory.getPackageManager({
|
|
1044
1083
|
force: options.packageManager
|
|
1045
|
-
}),
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
let reasons = compatibilityResult.reasons.map((r) => `\u2022 ${CLI_COLORS.error(r)}`);
|
|
1057
|
-
reasons.unshift(import_ts_dedent.dedent`
|
|
1058
|
-
Automated setup failed
|
|
1059
|
-
The following packages have incompatibilities that prevent automated setup:
|
|
1060
|
-
`), reasons.push(
|
|
1061
|
-
import_ts_dedent.dedent`
|
|
1062
|
-
You can fix these issues and rerun the command to reinstall. If you wish to roll back the installation, remove ${ADDON_NAME} from the "addons" array
|
|
1063
|
-
in your main Storybook config file and remove the dependency from your package.json file.
|
|
1084
|
+
}), vitestVersionSpecifier = await packageManager.getInstalledVersion("vitest"), coercedVitestVersion = vitestVersionSpecifier ? (0, import_semver.coerce)(vitestVersionSpecifier) : null, isVitest3_2To4 = vitestVersionSpecifier ? (0, import_semver.satisfies)(vitestVersionSpecifier, ">=3.2.0 <4.0.0") : !1, isVitest4OrNewer = vitestVersionSpecifier ? (0, import_semver.satisfies)(vitestVersionSpecifier, ">=4.0.0") : !0, info2 = await getStorybookInfo(options), allDeps = packageManager.getAllDependencies(), uniqueDependencies = [
|
|
1085
|
+
"vitest",
|
|
1086
|
+
"playwright",
|
|
1087
|
+
isVitest4OrNewer ? "@vitest/browser-playwright" : "@vitest/browser"
|
|
1088
|
+
].filter((p) => !allDeps[p]), mainJsPath = getInterpretedFile(resolve(options.configDir, "main")), config = await readConfig(mainJsPath), hasCustomWebpackConfig = !!config.getFieldNode(["webpackFinal"]), isInteractive = process.stdout.isTTY && !isCI2();
|
|
1089
|
+
nameMatches(info2.frameworkPackageName, "@storybook/nextjs") && !hasCustomWebpackConfig && (options.yes || !isInteractive ? { migrateToNextjsVite: !!options.yes } : await prompts({
|
|
1090
|
+
type: "confirm",
|
|
1091
|
+
name: "migrateToNextjsVite",
|
|
1092
|
+
message: dedent`
|
|
1093
|
+
The addon requires the use of @storybook/nextjs-vite to work with Next.js.
|
|
1094
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#install-and-set-up
|
|
1064
1095
|
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1096
|
+
Do you want to migrate?
|
|
1097
|
+
`,
|
|
1098
|
+
initial: !0
|
|
1099
|
+
})).migrateToNextjsVite && (await packageManager.addDependencies({ type: "devDependencies", skipInstall: !0 }, [
|
|
1100
|
+
"@storybook/nextjs-vite"
|
|
1101
|
+
]), await packageManager.removeDependencies(["@storybook/nextjs"]), traverse(config._ast, {
|
|
1102
|
+
StringLiteral(path) {
|
|
1103
|
+
path.node.value === "@storybook/nextjs" && (path.node.value = "@storybook/nextjs-vite");
|
|
1104
|
+
}
|
|
1105
|
+
}), await writeConfig(config, mainJsPath), info2.frameworkPackageName = "@storybook/nextjs-vite", info2.builderPackageName = "@storybook/builder-vite", await scanAndTransformFiles({
|
|
1106
|
+
promptMessage: "Enter a glob to scan for all @storybook/nextjs imports to substitute with @storybook/nextjs-vite:",
|
|
1107
|
+
force: options.yes,
|
|
1108
|
+
dryRun: !1,
|
|
1109
|
+
transformFn: (files, options2, dryRun) => transformImportFiles(files, options2, dryRun),
|
|
1110
|
+
transformOptions: {
|
|
1111
|
+
"@storybook/nextjs": "@storybook/nextjs-vite"
|
|
1112
|
+
}
|
|
1113
|
+
}));
|
|
1114
|
+
let annotationsImport = SUPPORTED_FRAMEWORKS.find(
|
|
1115
|
+
(f) => nameMatches(info2.frameworkPackageName, f)
|
|
1116
|
+
) ? info2.frameworkPackageName === "@storybook/nextjs" ? "@storybook/nextjs-vite" : info2.frameworkPackageName : null, isRendererSupported = !!annotationsImport, result = await (async () => {
|
|
1117
|
+
let reasons = [];
|
|
1118
|
+
hasCustomWebpackConfig && reasons.push("\u2022 The addon can not be used with a custom Webpack configuration."), !nameMatches(info2.frameworkPackageName, "@storybook/nextjs") && !nameMatches(info2.builderPackageName, "@storybook/builder-vite") && reasons.push(
|
|
1119
|
+
"\u2022 The addon can only be used with a Vite-based Storybook framework or Next.js."
|
|
1120
|
+
), isRendererSupported || reasons.push(dedent`
|
|
1121
|
+
• The addon cannot yet be used with ${info2.frameworkPackageName}
|
|
1122
|
+
`), coercedVitestVersion && !(0, import_semver.satisfies)(coercedVitestVersion, ">=3.0.0") && reasons.push(dedent`
|
|
1123
|
+
• The addon requires Vitest 3.0.0 or higher. You are currently using ${vitestVersionSpecifier}.
|
|
1124
|
+
Please update all of your Vitest dependencies and try again.
|
|
1125
|
+
`);
|
|
1126
|
+
let mswVersionSpecifier = await packageManager.getInstalledVersion("msw"), coercedMswVersion = mswVersionSpecifier ? (0, import_semver.coerce)(mswVersionSpecifier) : null;
|
|
1127
|
+
return coercedMswVersion && !(0, import_semver.satisfies)(coercedMswVersion, ">=2.0.0") && reasons.push(dedent`
|
|
1128
|
+
• The addon uses Vitest behind the scenes, which supports only version 2 and above of MSW. However, we have detected version ${coercedMswVersion.version} in this project.
|
|
1129
|
+
Please update the 'msw' package and try again.
|
|
1130
|
+
`), nameMatches(info2.frameworkPackageName, "@storybook/nextjs") && (await packageManager.getInstalledVersion("next") || reasons.push(dedent`
|
|
1131
|
+
• You are using @storybook/nextjs without having "next" installed.
|
|
1132
|
+
Please install "next" or use a different Storybook framework integration and try again.
|
|
1133
|
+
`)), reasons.length > 0 ? (reasons.unshift(
|
|
1134
|
+
"@storybook/addon-vitest's automated setup failed due to the following package incompatibilities:"
|
|
1135
|
+
), reasons.push("--------------------------------"), reasons.push(
|
|
1136
|
+
dedent`
|
|
1137
|
+
You can fix these issues and rerun the command to reinstall. If you wish to roll back the installation, remove ${ADDON_NAME} from the "addons" array
|
|
1138
|
+
in your main Storybook config file and remove the dependency from your package.json file.
|
|
1139
|
+
`
|
|
1140
|
+
), isRendererSupported ? reasons.push(
|
|
1141
|
+
dedent`
|
|
1142
|
+
Fear not, however, you can follow the manual installation process instead at:
|
|
1143
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1144
|
+
`
|
|
1145
|
+
) : reasons.push(
|
|
1146
|
+
dedent`
|
|
1147
|
+
Please check the documentation for more information about its requirements and installation:
|
|
1148
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}
|
|
1149
|
+
`
|
|
1150
|
+
), reasons.map((r) => r.trim()).join(`
|
|
1069
1151
|
|
|
1070
|
-
`);
|
|
1152
|
+
`)) : null;
|
|
1153
|
+
})();
|
|
1154
|
+
if (result) {
|
|
1155
|
+
logErrors("\u26D4\uFE0F Sorry!", result), logger2.line(1);
|
|
1156
|
+
return;
|
|
1071
1157
|
}
|
|
1072
|
-
if (
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
let versionedDependencies = await addonVitestService.collectDependencies(packageManager);
|
|
1078
|
-
info.framework === SupportedFramework.NEXTJS && packageManager.getAllDependencies()["@storybook/nextjs-vite"];
|
|
1079
|
-
let v8Version = await packageManager.getInstalledVersion("@vitest/coverage-v8"), istanbulVersion = await packageManager.getInstalledVersion("@vitest/coverage-istanbul");
|
|
1080
|
-
!v8Version && !istanbulVersion && logger.step(
|
|
1081
|
-
import_ts_dedent.dedent`
|
|
1082
|
-
You don't seem to have a coverage reporter installed. Vitest needs either V8 or Istanbul to generate coverage reports.
|
|
1158
|
+
if (info2.frameworkPackageName === "@storybook/nextjs") {
|
|
1159
|
+
printInfo(
|
|
1160
|
+
"\u{1F37F} Just so you know...",
|
|
1161
|
+
dedent`
|
|
1162
|
+
It looks like you're using Next.js.
|
|
1083
1163
|
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1164
|
+
Adding "@storybook/nextjs-vite/vite-plugin" so you can use it with Vitest.
|
|
1165
|
+
|
|
1166
|
+
More info about the plugin at https://github.com/storybookjs/vite-plugin-storybook-nextjs
|
|
1167
|
+
`
|
|
1168
|
+
);
|
|
1169
|
+
try {
|
|
1170
|
+
let storybookVersion = await packageManager.getInstalledVersion("storybook");
|
|
1171
|
+
uniqueDependencies.push(`@storybook/nextjs-vite@^${storybookVersion}`);
|
|
1172
|
+
} catch {
|
|
1173
|
+
console.error("Failed to install @storybook/nextjs-vite. Please install it manually");
|
|
1174
|
+
}
|
|
1091
1175
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1176
|
+
let v8Version = await packageManager.getInstalledVersion("@vitest/coverage-v8"), istanbulVersion = await packageManager.getInstalledVersion("@vitest/coverage-istanbul");
|
|
1177
|
+
!v8Version && !istanbulVersion && (printInfo(
|
|
1178
|
+
"\u{1F648} Let me cover this for you",
|
|
1179
|
+
dedent`
|
|
1180
|
+
You don't seem to have a coverage reporter installed. Vitest needs either V8 or Istanbul to generate coverage reports.
|
|
1181
|
+
|
|
1182
|
+
Adding "@vitest/coverage-v8" to enable coverage reporting.
|
|
1183
|
+
Read more about Vitest coverage providers at https://vitest.dev/guide/coverage.html#coverage-providers
|
|
1184
|
+
`
|
|
1185
|
+
), uniqueDependencies.push("@vitest/coverage-v8"));
|
|
1186
|
+
let versionedDependencies = uniqueDependencies.map((p) => p.includes("vitest") && vitestVersionSpecifier ? `${p}@${vitestVersionSpecifier}` : p);
|
|
1187
|
+
if (versionedDependencies.length > 0 && (await packageManager.addDependencies(
|
|
1188
|
+
{ type: "devDependencies", skipInstall: !0 },
|
|
1189
|
+
versionedDependencies
|
|
1190
|
+
), logger2.line(1), logger2.plain(`${step} Installing dependencies:`), logger2.plain(" " + versionedDependencies.join(", "))), await packageManager.installDependencies(), logger2.line(1), options.skipInstall)
|
|
1191
|
+
logger2.plain("Skipping Playwright installation, please run this command manually:"), logger2.plain(" npx playwright install chromium --with-deps");
|
|
1192
|
+
else {
|
|
1193
|
+
logger2.plain(`${step} Configuring Playwright with Chromium (this might take some time):`), logger2.plain(" npx playwright install chromium --with-deps");
|
|
1194
|
+
try {
|
|
1195
|
+
await packageManager.executeCommand({
|
|
1196
|
+
command: "npx",
|
|
1197
|
+
args: ["playwright", "install", "chromium", "--with-deps"]
|
|
1198
|
+
});
|
|
1199
|
+
} catch {
|
|
1200
|
+
console.error("Failed to install Playwright. Please install it manually");
|
|
1106
1201
|
}
|
|
1202
|
+
}
|
|
1107
1203
|
let fileExtension = allDeps.typescript || findFile("tsconfig", [...EXTENSIONS, ".json"]) ? "ts" : "js", vitestSetupFile = resolve(options.configDir, `vitest.setup.${fileExtension}`);
|
|
1108
1204
|
if (existsSync(vitestSetupFile)) {
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1205
|
+
logErrors(
|
|
1206
|
+
"\u{1F6A8} Oh no!",
|
|
1207
|
+
dedent`
|
|
1208
|
+
Found an existing Vitest setup file:
|
|
1209
|
+
${vitestSetupFile}
|
|
1210
|
+
|
|
1211
|
+
Please refer to the documentation to complete the setup manually:
|
|
1212
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1213
|
+
`
|
|
1214
|
+
), logger2.line(1);
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
logger2.line(1), logger2.plain(`${step} Creating a Vitest setup file for Storybook:`), logger2.plain(` ${vitestSetupFile}`);
|
|
1218
|
+
let previewExists = EXTENSIONS.map((ext) => resolve(options.configDir, `preview${ext}`)).some(
|
|
1219
|
+
existsSync
|
|
1220
|
+
), imports = [`import { setProjectAnnotations } from '${annotationsImport}';`], projectAnnotations = [];
|
|
1221
|
+
previewExists && (imports.push("import * as projectAnnotations from './preview';"), projectAnnotations.push("projectAnnotations")), await writeFile(
|
|
1222
|
+
vitestSetupFile,
|
|
1223
|
+
dedent`
|
|
1126
1224
|
${imports.join(`
|
|
1127
1225
|
`)}
|
|
1128
1226
|
|
|
@@ -1130,8 +1228,7 @@ async function postInstall(options) {
|
|
|
1130
1228
|
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
|
|
1131
1229
|
setProjectAnnotations([${projectAnnotations.join(", ")}]);
|
|
1132
1230
|
`
|
|
1133
|
-
|
|
1134
|
-
}
|
|
1231
|
+
);
|
|
1135
1232
|
let vitestWorkspaceFile = findFile("vitest.workspace", [".ts", ".js", ".json"]), viteConfigFile = findFile("vite.config"), vitestConfigFile = findFile("vitest.config"), vitestShimFile = findFile("vitest.shims.d"), rootConfig = vitestConfigFile || viteConfigFile;
|
|
1136
1233
|
fileExtension === "ts" && !vitestShimFile && await writeFile(
|
|
1137
1234
|
"vitest.shims.d.ts",
|
|
@@ -1146,12 +1243,13 @@ async function postInstall(options) {
|
|
|
1146
1243
|
}).then((t) => t.replace(`
|
|
1147
1244
|
'ROOT_CONFIG',`, "").replace(/\s+extends: '',/, "")), workspaceFile = await fs2.readFile(vitestWorkspaceFile, "utf8"), source = babelParse(workspaceTemplate), target = babelParse(workspaceFile);
|
|
1148
1245
|
if (updateWorkspaceFile(source, target)) {
|
|
1149
|
-
|
|
1246
|
+
logger2.line(1), logger2.plain(`${step} Updating your Vitest workspace file:`), logger2.plain(` ${vitestWorkspaceFile}`);
|
|
1150
1247
|
let formattedContent = await formatFileContent(vitestWorkspaceFile, generate(target).code);
|
|
1151
1248
|
await writeFile(vitestWorkspaceFile, formattedContent);
|
|
1152
|
-
} else
|
|
1153
|
-
|
|
1154
|
-
|
|
1249
|
+
} else {
|
|
1250
|
+
logErrors(
|
|
1251
|
+
"\u{1F6A8} Oh no!",
|
|
1252
|
+
dedent`
|
|
1155
1253
|
Could not update existing Vitest workspace file:
|
|
1156
1254
|
${vitestWorkspaceFile}
|
|
1157
1255
|
|
|
@@ -1161,7 +1259,9 @@ async function postInstall(options) {
|
|
|
1161
1259
|
Please refer to the documentation to complete the setup manually:
|
|
1162
1260
|
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1163
1261
|
`
|
|
1164
|
-
),
|
|
1262
|
+
), logger2.line(1);
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1165
1265
|
} else if (rootConfig) {
|
|
1166
1266
|
let target, updated, configFile = await fs2.readFile(rootConfig, "utf8"), configFileHasTypeReference = configFile.match(
|
|
1167
1267
|
/\/\/\/\s*<reference\s+types=["']vitest\/config["']\s*\/>/
|
|
@@ -1174,7 +1274,7 @@ async function postInstall(options) {
|
|
|
1174
1274
|
target = babelParse(configFile), updated = updateConfigFile(source, target);
|
|
1175
1275
|
}
|
|
1176
1276
|
if (target && updated) {
|
|
1177
|
-
|
|
1277
|
+
logger2.line(1), logger2.plain(`${step} Updating your ${vitestConfigFile ? "Vitest" : "Vite"} config file:`), logger2.plain(` ${rootConfig}`);
|
|
1178
1278
|
let formattedContent = await formatFileContent(rootConfig, generate(target).code);
|
|
1179
1279
|
await writeFile(
|
|
1180
1280
|
rootConfig,
|
|
@@ -1182,70 +1282,108 @@ async function postInstall(options) {
|
|
|
1182
1282
|
` + formattedContent : formattedContent
|
|
1183
1283
|
);
|
|
1184
1284
|
} else
|
|
1185
|
-
|
|
1285
|
+
logErrors(
|
|
1286
|
+
"\u{1F6A8} Oh no!",
|
|
1287
|
+
dedent`
|
|
1186
1288
|
We were unable to update your existing ${vitestConfigFile ? "Vitest" : "Vite"} config file.
|
|
1187
1289
|
|
|
1188
1290
|
Please refer to the documentation to complete the setup manually:
|
|
1189
1291
|
https://storybook.js.org/docs/writing-tests/integrations/vitest-addon#manual-setup
|
|
1190
|
-
`
|
|
1292
|
+
`
|
|
1293
|
+
);
|
|
1191
1294
|
} else {
|
|
1192
|
-
let
|
|
1295
|
+
let newConfigFile = resolve(`vitest.config.${fileExtension}`), configTemplate = await loadTemplate(getTemplateName(), {
|
|
1193
1296
|
CONFIG_DIR: options.configDir,
|
|
1194
1297
|
SETUP_FILE: relative(dirname(newConfigFile), vitestSetupFile)
|
|
1195
1298
|
});
|
|
1196
|
-
|
|
1299
|
+
logger2.line(1), logger2.plain(`${step} Creating a Vitest config file:`), logger2.plain(` ${newConfigFile}`);
|
|
1197
1300
|
let formattedContent = await formatFileContent(newConfigFile, configTemplate);
|
|
1198
1301
|
await writeFile(newConfigFile, formattedContent);
|
|
1199
1302
|
}
|
|
1200
|
-
if (
|
|
1303
|
+
if (info2.addons.find((addon) => addon.includes(addonA11yName)))
|
|
1201
1304
|
try {
|
|
1202
|
-
|
|
1305
|
+
logger2.plain(`${step} Setting up ${addonA11yName} for @storybook/addon-vitest:`), await execa(
|
|
1203
1306
|
"storybook",
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1307
|
+
[
|
|
1308
|
+
"automigrate",
|
|
1309
|
+
"addon-a11y-addon-test",
|
|
1310
|
+
"--loglevel",
|
|
1311
|
+
"silent",
|
|
1312
|
+
"--yes",
|
|
1313
|
+
"--skip-doctor",
|
|
1314
|
+
...options.packageManager ? ["--package-manager", options.packageManager] : [],
|
|
1315
|
+
...options.skipInstall ? ["--skip-install"] : [],
|
|
1316
|
+
...options.configDir !== ".storybook" ? ["--config-dir", `"${options.configDir}"`] : []
|
|
1317
|
+
],
|
|
1214
1318
|
{
|
|
1215
|
-
|
|
1216
|
-
error: "Failed to setup a11y addon for @storybook/addon-vitest",
|
|
1217
|
-
success: "a11y addon setup successfully"
|
|
1319
|
+
stdio: "inherit"
|
|
1218
1320
|
}
|
|
1219
1321
|
);
|
|
1220
1322
|
} catch (e) {
|
|
1221
|
-
|
|
1222
|
-
|
|
1323
|
+
logErrors(
|
|
1324
|
+
"\u{1F6A8} Oh no!",
|
|
1325
|
+
dedent`
|
|
1326
|
+
We have detected that you have ${addonA11yName} installed but could not automatically set it up for @storybook/addon-vitest:
|
|
1327
|
+
|
|
1328
|
+
${e instanceof Error ? e.message : String(e)}
|
|
1329
|
+
|
|
1223
1330
|
Please refer to the documentation to complete the setup manually:
|
|
1224
1331
|
https://storybook.js.org/docs/writing-tests/accessibility-testing#test-addon-integration
|
|
1225
|
-
`
|
|
1226
|
-
"The @storybook/addon-a11y couldn't be set up for the Vitest addon" + (e instanceof Error ? e.stack : String(e))
|
|
1332
|
+
`
|
|
1227
1333
|
);
|
|
1228
1334
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1335
|
+
hasErrors ? printWarning(
|
|
1336
|
+
"\u26A0\uFE0F Done, but with errors!",
|
|
1337
|
+
dedent`
|
|
1338
|
+
@storybook/addon-vitest was installed successfully, but there were some errors during the setup process.
|
|
1339
|
+
|
|
1340
|
+
Please refer to the documentation to complete the setup manually and check the errors above:
|
|
1341
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1342
|
+
`
|
|
1343
|
+
) : printSuccess(
|
|
1344
|
+
"\u{1F389} All done!",
|
|
1345
|
+
dedent`
|
|
1232
1346
|
@storybook/addon-vitest is now configured and you're ready to run your tests!
|
|
1347
|
+
|
|
1233
1348
|
Here are a couple of tips to get you started:
|
|
1234
|
-
|
|
1235
|
-
•
|
|
1236
|
-
|
|
1237
|
-
|
|
1349
|
+
• You can run tests with "${rootConfig ? "npx vitest --project=storybook" : "npx vitest"}"
|
|
1350
|
+
• When using the Vitest extension in your editor, all of your stories will be shown as tests!
|
|
1351
|
+
|
|
1238
1352
|
Check the documentation for more information about its features and options at:
|
|
1239
1353
|
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}
|
|
1240
|
-
`);
|
|
1241
|
-
else
|
|
1242
|
-
throw logger.warn(
|
|
1243
|
-
import_ts_dedent.dedent`
|
|
1244
|
-
Done, but with errors!
|
|
1245
|
-
@storybook/addon-vitest was installed successfully, but there were some errors during the setup process. Please refer to the documentation to complete the setup manually and check the errors above:
|
|
1246
|
-
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1247
1354
|
`
|
|
1248
|
-
|
|
1355
|
+
), logger2.line(1);
|
|
1356
|
+
}
|
|
1357
|
+
async function getPackageNameFromPath(input) {
|
|
1358
|
+
let path = input.startsWith("file://") ? fileURLToPath(input) : input;
|
|
1359
|
+
if (!isAbsolute(path))
|
|
1360
|
+
return path;
|
|
1361
|
+
let packageJsonPath = up2({ cwd: path });
|
|
1362
|
+
if (!packageJsonPath)
|
|
1363
|
+
throw new Error(`Could not find package.json in path: ${path}`);
|
|
1364
|
+
let { default: packageJson } = await import(pathToFileURL(packageJsonPath).href, {
|
|
1365
|
+
with: { type: "json" }
|
|
1366
|
+
});
|
|
1367
|
+
return packageJson.name;
|
|
1368
|
+
}
|
|
1369
|
+
async function getStorybookInfo({ configDir, packageManager: pkgMgr }) {
|
|
1370
|
+
let packageManager = JsPackageManagerFactory.getPackageManager({ force: pkgMgr, configDir }), { packageJson } = packageManager.primaryPackageJson, config = await loadMainConfig({ configDir }), { presets } = await experimental_loadStorybook({
|
|
1371
|
+
configDir,
|
|
1372
|
+
packageJson
|
|
1373
|
+
}), framework = await presets.apply("framework", {}), core = await presets.apply("core", {}), { builder, renderer } = core;
|
|
1374
|
+
if (!builder)
|
|
1375
|
+
throw new Error("Could not detect your Storybook builder.");
|
|
1376
|
+
let frameworkPackageName = await getPackageNameFromPath(
|
|
1377
|
+
typeof framework == "string" ? framework : framework.name
|
|
1378
|
+
), builderPackageName = await getPackageNameFromPath(
|
|
1379
|
+
typeof builder == "string" ? builder : builder.name
|
|
1380
|
+
), rendererPackageName;
|
|
1381
|
+
return renderer && (rendererPackageName = await getPackageNameFromPath(renderer)), {
|
|
1382
|
+
frameworkPackageName,
|
|
1383
|
+
builderPackageName,
|
|
1384
|
+
rendererPackageName,
|
|
1385
|
+
addons: getAddonNames(config)
|
|
1386
|
+
};
|
|
1249
1387
|
}
|
|
1250
1388
|
export {
|
|
1251
1389
|
postInstall as default
|