@storybook/addon-vitest 0.0.0-pr-32717-sha-8803ec2c → 0.0.0-pr-32855-sha-40c0476b
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/_browser-chunks/{chunk-RPDOPHZX.js → chunk-PMYV6BH2.js} +0 -1
- package/dist/_node-chunks/{chunk-HTINZ3Y3.js → chunk-4IBOHAVX.js} +7 -7
- package/dist/_node-chunks/chunk-DUW3TYJ7.js +2574 -0
- package/dist/_node-chunks/chunk-EFOL2UA6.js +37 -0
- package/dist/_node-chunks/chunk-HIQOROO5.js +98 -0
- package/dist/_node-chunks/{chunk-RC52X23D.js → chunk-IE54DXY6.js} +7 -7
- package/dist/_node-chunks/{chunk-J3TMKAGQ.js → chunk-MCJGU4HJ.js} +18 -7
- package/dist/_node-chunks/{chunk-WODMNDRC.js → chunk-R3S4FX6D.js} +6 -6
- package/dist/_node-chunks/{chunk-UGJMNNQB.js → chunk-UD3FE66F.js} +7 -7
- package/dist/manager.js +1 -1
- package/dist/node/coverage-reporter.js +8 -8
- package/dist/node/vitest.js +14 -25
- package/dist/postinstall.js +414 -179
- package/dist/preset.js +15 -2239
- package/dist/vitest-plugin/global-setup.js +7 -7
- package/dist/vitest-plugin/index.js +9 -9
- package/dist/vitest-plugin/setup-file.js +1 -1
- package/package.json +4 -2
- package/dist/_node-chunks/chunk-NXAZJQMW.js +0 -40
- package/dist/_node-chunks/chunk-X5TW6UQ6.js +0 -348
- package/dist/_node-chunks/chunk-ZUDGK5GP.js +0 -60
package/dist/postinstall.js
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_ud8ru9cmgt from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_ud8ru9cmgt from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_ud8ru9cmgt from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_ud8ru9cmgt.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_ud8ru9cmgt.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_ud8ru9cmgt.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-DUW3TYJ7.js";
|
|
15
16
|
import {
|
|
16
|
-
any
|
|
17
|
-
|
|
17
|
+
any,
|
|
18
|
+
getAddonNames,
|
|
19
|
+
up
|
|
20
|
+
} from "./_node-chunks/chunk-HIQOROO5.js";
|
|
18
21
|
import {
|
|
19
|
-
DOCUMENTATION_LINK
|
|
20
|
-
|
|
22
|
+
DOCUMENTATION_LINK,
|
|
23
|
+
SUPPORTED_FRAMEWORKS
|
|
24
|
+
} from "./_node-chunks/chunk-MCJGU4HJ.js";
|
|
21
25
|
import {
|
|
22
26
|
dirname,
|
|
23
27
|
join,
|
|
24
28
|
relative,
|
|
25
29
|
resolve
|
|
26
|
-
} from "./_node-chunks/chunk-
|
|
30
|
+
} from "./_node-chunks/chunk-4IBOHAVX.js";
|
|
27
31
|
import {
|
|
28
32
|
require_compare,
|
|
29
33
|
require_constants,
|
|
@@ -33,12 +37,12 @@ import {
|
|
|
33
37
|
require_parse_options,
|
|
34
38
|
require_re,
|
|
35
39
|
require_semver
|
|
36
|
-
} from "./_node-chunks/chunk-
|
|
40
|
+
} from "./_node-chunks/chunk-IE54DXY6.js";
|
|
37
41
|
import {
|
|
38
42
|
__commonJS,
|
|
39
43
|
__name,
|
|
40
44
|
__toESM
|
|
41
|
-
} from "./_node-chunks/chunk-
|
|
45
|
+
} from "./_node-chunks/chunk-R3S4FX6D.js";
|
|
42
46
|
|
|
43
47
|
// ../../node_modules/semver/functions/parse.js
|
|
44
48
|
var require_parse = __commonJS({
|
|
@@ -360,7 +364,7 @@ var require_coerce = __commonJS({
|
|
|
360
364
|
var SemVer = require_semver();
|
|
361
365
|
var parse = require_parse();
|
|
362
366
|
var { safeRe: re, t } = require_re();
|
|
363
|
-
var
|
|
367
|
+
var coerce2 = /* @__PURE__ */ __name((version, options) => {
|
|
364
368
|
if (version instanceof SemVer) {
|
|
365
369
|
return version;
|
|
366
370
|
}
|
|
@@ -395,7 +399,7 @@ var require_coerce = __commonJS({
|
|
|
395
399
|
const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
|
|
396
400
|
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
|
|
397
401
|
}, "coerce");
|
|
398
|
-
module.exports =
|
|
402
|
+
module.exports = coerce2;
|
|
399
403
|
}
|
|
400
404
|
});
|
|
401
405
|
|
|
@@ -968,7 +972,7 @@ var require_max_satisfying = __commonJS({
|
|
|
968
972
|
"use strict";
|
|
969
973
|
var SemVer = require_semver();
|
|
970
974
|
var Range = require_range();
|
|
971
|
-
var maxSatisfying = /* @__PURE__ */ __name((
|
|
975
|
+
var maxSatisfying = /* @__PURE__ */ __name((versions, range, options) => {
|
|
972
976
|
let max = null;
|
|
973
977
|
let maxSV = null;
|
|
974
978
|
let rangeObj = null;
|
|
@@ -977,7 +981,7 @@ var require_max_satisfying = __commonJS({
|
|
|
977
981
|
} catch (er) {
|
|
978
982
|
return null;
|
|
979
983
|
}
|
|
980
|
-
|
|
984
|
+
versions.forEach((v) => {
|
|
981
985
|
if (rangeObj.test(v)) {
|
|
982
986
|
if (!max || maxSV.compare(v) === -1) {
|
|
983
987
|
max = v;
|
|
@@ -997,7 +1001,7 @@ var require_min_satisfying = __commonJS({
|
|
|
997
1001
|
"use strict";
|
|
998
1002
|
var SemVer = require_semver();
|
|
999
1003
|
var Range = require_range();
|
|
1000
|
-
var minSatisfying = /* @__PURE__ */ __name((
|
|
1004
|
+
var minSatisfying = /* @__PURE__ */ __name((versions, range, options) => {
|
|
1001
1005
|
let min = null;
|
|
1002
1006
|
let minSV = null;
|
|
1003
1007
|
let rangeObj = null;
|
|
@@ -1006,7 +1010,7 @@ var require_min_satisfying = __commonJS({
|
|
|
1006
1010
|
} catch (er) {
|
|
1007
1011
|
return null;
|
|
1008
1012
|
}
|
|
1009
|
-
|
|
1013
|
+
versions.forEach((v) => {
|
|
1010
1014
|
if (rangeObj.test(v)) {
|
|
1011
1015
|
if (!min || minSV.compare(v) === 1) {
|
|
1012
1016
|
min = v;
|
|
@@ -1204,11 +1208,11 @@ var require_simplify = __commonJS({
|
|
|
1204
1208
|
"use strict";
|
|
1205
1209
|
var satisfies2 = require_satisfies();
|
|
1206
1210
|
var compare = require_compare();
|
|
1207
|
-
module.exports = (
|
|
1211
|
+
module.exports = (versions, range, options) => {
|
|
1208
1212
|
const set = [];
|
|
1209
1213
|
let first = null;
|
|
1210
1214
|
let prev = null;
|
|
1211
|
-
const v =
|
|
1215
|
+
const v = versions.sort((a, b) => compare(a, b, options));
|
|
1212
1216
|
for (const version of v) {
|
|
1213
1217
|
const included = satisfies2(version, range, options);
|
|
1214
1218
|
if (included) {
|
|
@@ -1440,7 +1444,7 @@ var require_semver2 = __commonJS({
|
|
|
1440
1444
|
var gte = require_gte();
|
|
1441
1445
|
var lte = require_lte();
|
|
1442
1446
|
var cmp = require_cmp();
|
|
1443
|
-
var
|
|
1447
|
+
var coerce2 = require_coerce();
|
|
1444
1448
|
var Comparator = require_comparator();
|
|
1445
1449
|
var Range = require_range();
|
|
1446
1450
|
var satisfies2 = require_satisfies();
|
|
@@ -1478,7 +1482,7 @@ var require_semver2 = __commonJS({
|
|
|
1478
1482
|
gte,
|
|
1479
1483
|
lte,
|
|
1480
1484
|
cmp,
|
|
1481
|
-
coerce,
|
|
1485
|
+
coerce: coerce2,
|
|
1482
1486
|
Comparator,
|
|
1483
1487
|
Range,
|
|
1484
1488
|
satisfies: satisfies2,
|
|
@@ -1509,24 +1513,56 @@ var require_semver2 = __commonJS({
|
|
|
1509
1513
|
import { existsSync } from "node:fs";
|
|
1510
1514
|
import * as fs2 from "node:fs/promises";
|
|
1511
1515
|
import { writeFile } from "node:fs/promises";
|
|
1512
|
-
import {
|
|
1513
|
-
import {
|
|
1516
|
+
import { isAbsolute, posix, sep } from "node:path";
|
|
1517
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
1518
|
+
import { babelParse, generate, traverse } from "storybook/internal/babel";
|
|
1514
1519
|
import {
|
|
1515
1520
|
JsPackageManagerFactory,
|
|
1516
1521
|
formatFileContent,
|
|
1522
|
+
getInterpretedFile,
|
|
1517
1523
|
getProjectRoot,
|
|
1518
|
-
|
|
1519
|
-
|
|
1524
|
+
isCI as isCI2,
|
|
1525
|
+
loadMainConfig,
|
|
1526
|
+
scanAndTransformFiles,
|
|
1527
|
+
transformImportFiles
|
|
1520
1528
|
} from "storybook/internal/common";
|
|
1521
|
-
import {
|
|
1522
|
-
import {
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1529
|
+
import { experimental_loadStorybook } from "storybook/internal/core-server";
|
|
1530
|
+
import { readConfig, writeConfig } from "storybook/internal/csf-tools";
|
|
1531
|
+
import { logger as logger2 } from "storybook/internal/node-logger";
|
|
1532
|
+
|
|
1533
|
+
// ../../node_modules/empathic/package.mjs
|
|
1534
|
+
function up2(options) {
|
|
1535
|
+
return up("package.json", options);
|
|
1536
|
+
}
|
|
1537
|
+
__name(up2, "up");
|
|
1538
|
+
|
|
1539
|
+
// src/postinstall.ts
|
|
1527
1540
|
var import_semver = __toESM(require_semver2(), 1);
|
|
1541
|
+
import prompts from "prompts";
|
|
1528
1542
|
import { dedent } from "ts-dedent";
|
|
1529
1543
|
|
|
1544
|
+
// src/postinstall-logger.ts
|
|
1545
|
+
import { isCI } from "storybook/internal/common";
|
|
1546
|
+
import { colors, logger } from "storybook/internal/node-logger";
|
|
1547
|
+
var fancy = process.platform !== "win32" || isCI() || process.env.TERM === "xterm-256color";
|
|
1548
|
+
var step = colors.gray("\u203A");
|
|
1549
|
+
var info = colors.blue(fancy ? "\u2139" : "i");
|
|
1550
|
+
var success = colors.green(fancy ? "\u2714" : "\u221A");
|
|
1551
|
+
var warning = colors.orange(fancy ? "\u26A0" : "\u203C");
|
|
1552
|
+
var error = colors.red(fancy ? "\u2716" : "\xD7");
|
|
1553
|
+
var baseOptions = {
|
|
1554
|
+
borderStyle: "round",
|
|
1555
|
+
padding: 1
|
|
1556
|
+
};
|
|
1557
|
+
var print = /* @__PURE__ */ __name((message, options) => {
|
|
1558
|
+
logger.line(1);
|
|
1559
|
+
logger.logBox(message, { ...baseOptions, ...options });
|
|
1560
|
+
}, "print");
|
|
1561
|
+
var printInfo = /* @__PURE__ */ __name((title, message, options) => print(message, { borderColor: "blue", title, ...options }), "printInfo");
|
|
1562
|
+
var printWarning = /* @__PURE__ */ __name((title, message, options) => print(message, { borderColor: "yellow", title, ...options }), "printWarning");
|
|
1563
|
+
var printError = /* @__PURE__ */ __name((title, message, options) => print(message, { borderColor: "red", title, ...options }), "printError");
|
|
1564
|
+
var printSuccess = /* @__PURE__ */ __name((title, message, options) => print(message, { borderColor: "green", title, ...options }), "printSuccess");
|
|
1565
|
+
|
|
1530
1566
|
// src/updateVitestFile.ts
|
|
1531
1567
|
import * as fs from "node:fs/promises";
|
|
1532
1568
|
var loadTemplate = /* @__PURE__ */ __name(async (name, replacements) => {
|
|
@@ -1721,126 +1757,274 @@ var updateWorkspaceFile = /* @__PURE__ */ __name((source, target) => {
|
|
|
1721
1757
|
var ADDON_NAME = "@storybook/addon-vitest";
|
|
1722
1758
|
var EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".cts", ".mts", ".cjs", ".mjs"];
|
|
1723
1759
|
var addonA11yName = "@storybook/addon-a11y";
|
|
1760
|
+
var hasErrors = false;
|
|
1761
|
+
function nameMatches(name, pattern) {
|
|
1762
|
+
if (name === pattern) {
|
|
1763
|
+
return true;
|
|
1764
|
+
}
|
|
1765
|
+
if (name.includes(`${pattern}${sep}`)) {
|
|
1766
|
+
return true;
|
|
1767
|
+
}
|
|
1768
|
+
if (name.includes(`${pattern}${posix.sep}`)) {
|
|
1769
|
+
return true;
|
|
1770
|
+
}
|
|
1771
|
+
return false;
|
|
1772
|
+
}
|
|
1773
|
+
__name(nameMatches, "nameMatches");
|
|
1774
|
+
var logErrors = /* @__PURE__ */ __name((...args) => {
|
|
1775
|
+
hasErrors = true;
|
|
1776
|
+
printError(...args);
|
|
1777
|
+
}, "logErrors");
|
|
1778
|
+
var findFile = /* @__PURE__ */ __name((basename, extensions = EXTENSIONS) => any(
|
|
1779
|
+
extensions.map((ext) => basename + ext),
|
|
1780
|
+
{ last: getProjectRoot() }
|
|
1781
|
+
), "findFile");
|
|
1724
1782
|
async function postInstall(options) {
|
|
1725
|
-
|
|
1726
|
-
|
|
1783
|
+
printSuccess(
|
|
1784
|
+
"\u{1F44B} Howdy!",
|
|
1785
|
+
dedent`
|
|
1786
|
+
I'm the installation helper for ${ADDON_NAME}
|
|
1787
|
+
|
|
1788
|
+
Hold on for a moment while I look at your project and get it set up...
|
|
1789
|
+
`
|
|
1790
|
+
);
|
|
1727
1791
|
const packageManager = JsPackageManagerFactory.getPackageManager({
|
|
1728
1792
|
force: options.packageManager
|
|
1729
1793
|
});
|
|
1730
|
-
const findFile = /* @__PURE__ */ __name((basename, extensions = EXTENSIONS) => any(
|
|
1731
|
-
extensions.map((ext) => basename + ext),
|
|
1732
|
-
{ last: getProjectRoot(), cwd: options.configDir }
|
|
1733
|
-
), "findFile");
|
|
1734
1794
|
const vitestVersionSpecifier = await packageManager.getInstalledVersion("vitest");
|
|
1795
|
+
const coercedVitestVersion = vitestVersionSpecifier ? (0, import_semver.coerce)(vitestVersionSpecifier) : null;
|
|
1735
1796
|
const isVitest3_2To4 = vitestVersionSpecifier ? (0, import_semver.satisfies)(vitestVersionSpecifier, ">=3.2.0 <4.0.0") : false;
|
|
1736
1797
|
const isVitest4OrNewer = vitestVersionSpecifier ? (0, import_semver.satisfies)(vitestVersionSpecifier, ">=4.0.0") : true;
|
|
1737
|
-
const
|
|
1798
|
+
const info2 = await getStorybookInfo(options);
|
|
1738
1799
|
const allDeps = packageManager.getAllDependencies();
|
|
1739
|
-
const
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
dedent`
|
|
1754
|
-
|
|
1755
|
-
|
|
1800
|
+
const dependencies = [
|
|
1801
|
+
"vitest",
|
|
1802
|
+
"playwright",
|
|
1803
|
+
isVitest4OrNewer ? "@vitest/browser-playwright" : "@vitest/browser"
|
|
1804
|
+
];
|
|
1805
|
+
const uniqueDependencies = dependencies.filter((p) => !allDeps[p]);
|
|
1806
|
+
const mainJsPath = getInterpretedFile(resolve(options.configDir, "main"));
|
|
1807
|
+
const config = await readConfig(mainJsPath);
|
|
1808
|
+
const hasCustomWebpackConfig = !!config.getFieldNode(["webpackFinal"]);
|
|
1809
|
+
const isInteractive = process.stdout.isTTY && !isCI2();
|
|
1810
|
+
if (nameMatches(info2.frameworkPackageName, "@storybook/nextjs") && !hasCustomWebpackConfig) {
|
|
1811
|
+
const out = options.yes || !isInteractive ? { migrateToNextjsVite: !!options.yes } : await prompts({
|
|
1812
|
+
type: "confirm",
|
|
1813
|
+
name: "migrateToNextjsVite",
|
|
1814
|
+
message: dedent`
|
|
1815
|
+
The addon requires the use of @storybook/nextjs-vite to work with Next.js.
|
|
1816
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#install-and-set-up
|
|
1756
1817
|
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
);
|
|
1761
|
-
result = reasons.map((r) => r.trim()).join("\n\n");
|
|
1762
|
-
}
|
|
1763
|
-
if (result) {
|
|
1764
|
-
logger.error(result);
|
|
1765
|
-
throw new AddonVitestPostinstallPrerequisiteCheckError({
|
|
1766
|
-
reasons: compatibilityResult.reasons
|
|
1818
|
+
Do you want to migrate?
|
|
1819
|
+
`,
|
|
1820
|
+
initial: true
|
|
1767
1821
|
});
|
|
1822
|
+
if (out.migrateToNextjsVite) {
|
|
1823
|
+
await packageManager.addDependencies({ type: "devDependencies", skipInstall: true }, [
|
|
1824
|
+
"@storybook/nextjs-vite"
|
|
1825
|
+
]);
|
|
1826
|
+
await packageManager.removeDependencies(["@storybook/nextjs"]);
|
|
1827
|
+
traverse(config._ast, {
|
|
1828
|
+
StringLiteral(path) {
|
|
1829
|
+
if (path.node.value === "@storybook/nextjs") {
|
|
1830
|
+
path.node.value = "@storybook/nextjs-vite";
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
});
|
|
1834
|
+
await writeConfig(config, mainJsPath);
|
|
1835
|
+
info2.frameworkPackageName = "@storybook/nextjs-vite";
|
|
1836
|
+
info2.builderPackageName = "@storybook/builder-vite";
|
|
1837
|
+
await scanAndTransformFiles({
|
|
1838
|
+
promptMessage: "Enter a glob to scan for all @storybook/nextjs imports to substitute with @storybook/nextjs-vite:",
|
|
1839
|
+
force: options.yes,
|
|
1840
|
+
dryRun: false,
|
|
1841
|
+
transformFn: /* @__PURE__ */ __name((files, options2, dryRun) => transformImportFiles(files, options2, dryRun), "transformFn"),
|
|
1842
|
+
transformOptions: {
|
|
1843
|
+
"@storybook/nextjs": "@storybook/nextjs-vite"
|
|
1844
|
+
}
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1768
1847
|
}
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1848
|
+
const annotationsImport = SUPPORTED_FRAMEWORKS.find(
|
|
1849
|
+
(f) => nameMatches(info2.frameworkPackageName, f)
|
|
1850
|
+
) ? info2.frameworkPackageName === "@storybook/nextjs" ? "@storybook/nextjs-vite" : info2.frameworkPackageName : null;
|
|
1851
|
+
const isRendererSupported = !!annotationsImport;
|
|
1852
|
+
const prerequisiteCheck = /* @__PURE__ */ __name(async () => {
|
|
1853
|
+
const reasons = [];
|
|
1854
|
+
if (hasCustomWebpackConfig) {
|
|
1855
|
+
reasons.push("\u2022 The addon can not be used with a custom Webpack configuration.");
|
|
1856
|
+
}
|
|
1857
|
+
if (!nameMatches(info2.frameworkPackageName, "@storybook/nextjs") && !nameMatches(info2.builderPackageName, "@storybook/builder-vite")) {
|
|
1858
|
+
reasons.push(
|
|
1859
|
+
"\u2022 The addon can only be used with a Vite-based Storybook framework or Next.js."
|
|
1860
|
+
);
|
|
1861
|
+
}
|
|
1862
|
+
if (!isRendererSupported) {
|
|
1863
|
+
reasons.push(dedent`
|
|
1864
|
+
• The addon cannot yet be used with ${info2.frameworkPackageName}
|
|
1865
|
+
`);
|
|
1866
|
+
}
|
|
1867
|
+
if (coercedVitestVersion && !(0, import_semver.satisfies)(coercedVitestVersion, ">=3.0.0")) {
|
|
1868
|
+
reasons.push(dedent`
|
|
1869
|
+
• The addon requires Vitest 3.0.0 or higher. You are currently using ${vitestVersionSpecifier}.
|
|
1870
|
+
Please update all of your Vitest dependencies and try again.
|
|
1871
|
+
`);
|
|
1872
|
+
}
|
|
1873
|
+
const mswVersionSpecifier = await packageManager.getInstalledVersion("msw");
|
|
1874
|
+
const coercedMswVersion = mswVersionSpecifier ? (0, import_semver.coerce)(mswVersionSpecifier) : null;
|
|
1875
|
+
if (coercedMswVersion && !(0, import_semver.satisfies)(coercedMswVersion, ">=2.0.0")) {
|
|
1876
|
+
reasons.push(dedent`
|
|
1877
|
+
• 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.
|
|
1878
|
+
Please update the 'msw' package and try again.
|
|
1879
|
+
`);
|
|
1880
|
+
}
|
|
1881
|
+
if (nameMatches(info2.frameworkPackageName, "@storybook/nextjs")) {
|
|
1882
|
+
const nextVersion = await packageManager.getInstalledVersion("next");
|
|
1883
|
+
if (!nextVersion) {
|
|
1884
|
+
reasons.push(dedent`
|
|
1885
|
+
• You are using @storybook/nextjs without having "next" installed.
|
|
1886
|
+
Please install "next" or use a different Storybook framework integration and try again.
|
|
1887
|
+
`);
|
|
1774
1888
|
}
|
|
1775
1889
|
}
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1890
|
+
if (reasons.length > 0) {
|
|
1891
|
+
reasons.unshift(
|
|
1892
|
+
`@storybook/addon-vitest's automated setup failed due to the following package incompatibilities:`
|
|
1893
|
+
);
|
|
1894
|
+
reasons.push("--------------------------------");
|
|
1895
|
+
reasons.push(
|
|
1780
1896
|
dedent`
|
|
1781
|
-
You
|
|
1782
|
-
|
|
1783
|
-
Adding "@vitest/coverage-v8" to enable coverage reporting.
|
|
1784
|
-
Read more about Vitest coverage providers at https://vitest.dev/guide/coverage.html#coverage-providers
|
|
1897
|
+
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
|
|
1898
|
+
in your main Storybook config file and remove the dependency from your package.json file.
|
|
1785
1899
|
`
|
|
1786
1900
|
);
|
|
1901
|
+
if (!isRendererSupported) {
|
|
1902
|
+
reasons.push(
|
|
1903
|
+
dedent`
|
|
1904
|
+
Please check the documentation for more information about its requirements and installation:
|
|
1905
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}
|
|
1906
|
+
`
|
|
1907
|
+
);
|
|
1908
|
+
} else {
|
|
1909
|
+
reasons.push(
|
|
1910
|
+
dedent`
|
|
1911
|
+
Fear not, however, you can follow the manual installation process instead at:
|
|
1912
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1913
|
+
`
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
return reasons.map((r) => r.trim()).join("\n\n");
|
|
1787
1917
|
}
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1918
|
+
return null;
|
|
1919
|
+
}, "prerequisiteCheck");
|
|
1920
|
+
const result = await prerequisiteCheck();
|
|
1921
|
+
if (result) {
|
|
1922
|
+
logErrors("\u26D4\uFE0F Sorry!", result);
|
|
1923
|
+
logger2.line(1);
|
|
1924
|
+
return;
|
|
1925
|
+
}
|
|
1926
|
+
if (info2.frameworkPackageName === "@storybook/nextjs") {
|
|
1927
|
+
printInfo(
|
|
1928
|
+
"\u{1F37F} Just so you know...",
|
|
1929
|
+
dedent`
|
|
1930
|
+
It looks like you're using Next.js.
|
|
1931
|
+
|
|
1932
|
+
Adding "@storybook/nextjs-vite/vite-plugin" so you can use it with Vitest.
|
|
1933
|
+
|
|
1934
|
+
More info about the plugin at https://github.com/storybookjs/vite-plugin-storybook-nextjs
|
|
1935
|
+
`
|
|
1936
|
+
);
|
|
1937
|
+
try {
|
|
1938
|
+
const storybookVersion = await packageManager.getInstalledVersion("storybook");
|
|
1939
|
+
uniqueDependencies.push(`@storybook/nextjs-vite@^${storybookVersion}`);
|
|
1940
|
+
} catch (e) {
|
|
1941
|
+
console.error("Failed to install @storybook/nextjs-vite. Please install it manually");
|
|
1795
1942
|
}
|
|
1796
|
-
|
|
1797
|
-
|
|
1943
|
+
}
|
|
1944
|
+
const v8Version = await packageManager.getInstalledVersion("@vitest/coverage-v8");
|
|
1945
|
+
const istanbulVersion = await packageManager.getInstalledVersion("@vitest/coverage-istanbul");
|
|
1946
|
+
if (!v8Version && !istanbulVersion) {
|
|
1947
|
+
printInfo(
|
|
1948
|
+
"\u{1F648} Let me cover this for you",
|
|
1949
|
+
dedent`
|
|
1950
|
+
You don't seem to have a coverage reporter installed. Vitest needs either V8 or Istanbul to generate coverage reports.
|
|
1951
|
+
|
|
1952
|
+
Adding "@vitest/coverage-v8" to enable coverage reporting.
|
|
1953
|
+
Read more about Vitest coverage providers at https://vitest.dev/guide/coverage.html#coverage-providers
|
|
1954
|
+
`
|
|
1955
|
+
);
|
|
1956
|
+
uniqueDependencies.push(`@vitest/coverage-v8`);
|
|
1957
|
+
}
|
|
1958
|
+
const versionedDependencies = uniqueDependencies.map((p) => {
|
|
1959
|
+
if (p.includes("vitest")) {
|
|
1960
|
+
return vitestVersionSpecifier ? `${p}@${vitestVersionSpecifier}` : p;
|
|
1798
1961
|
}
|
|
1962
|
+
return p;
|
|
1963
|
+
});
|
|
1964
|
+
if (versionedDependencies.length > 0) {
|
|
1965
|
+
await packageManager.addDependencies(
|
|
1966
|
+
{ type: "devDependencies", skipInstall: true },
|
|
1967
|
+
versionedDependencies
|
|
1968
|
+
);
|
|
1969
|
+
logger2.line(1);
|
|
1970
|
+
logger2.plain(`${step} Installing dependencies:`);
|
|
1971
|
+
logger2.plain(" " + versionedDependencies.join(", "));
|
|
1799
1972
|
}
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1973
|
+
await packageManager.installDependencies();
|
|
1974
|
+
logger2.line(1);
|
|
1975
|
+
if (options.skipInstall) {
|
|
1976
|
+
logger2.plain("Skipping Playwright installation, please run this command manually:");
|
|
1977
|
+
logger2.plain(" npx playwright install chromium --with-deps");
|
|
1978
|
+
} else {
|
|
1979
|
+
logger2.plain(`${step} Configuring Playwright with Chromium (this might take some time):`);
|
|
1980
|
+
logger2.plain(" npx playwright install chromium --with-deps");
|
|
1981
|
+
try {
|
|
1982
|
+
await packageManager.executeCommand({
|
|
1983
|
+
command: "npx",
|
|
1984
|
+
args: ["playwright", "install", "chromium", "--with-deps"]
|
|
1985
|
+
});
|
|
1986
|
+
} catch (e) {
|
|
1987
|
+
console.error("Failed to install Playwright. Please install it manually");
|
|
1988
|
+
}
|
|
1805
1989
|
}
|
|
1806
1990
|
const fileExtension = allDeps.typescript || findFile("tsconfig", [...EXTENSIONS, ".json"]) ? "ts" : "js";
|
|
1807
1991
|
const vitestSetupFile = resolve(options.configDir, `vitest.setup.${fileExtension}`);
|
|
1808
1992
|
if (existsSync(vitestSetupFile)) {
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
${vitestSetupFile}
|
|
1812
|
-
Please refer to the documentation to complete the setup manually:
|
|
1813
|
-
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1814
|
-
`;
|
|
1815
|
-
logger.line();
|
|
1816
|
-
logger.error(`${errorMessage}
|
|
1817
|
-
`);
|
|
1818
|
-
errors.push("Found existing Vitest setup file");
|
|
1819
|
-
} else {
|
|
1820
|
-
logger.step(`Creating a Vitest setup file for Storybook:`);
|
|
1821
|
-
logger.log(`${vitestSetupFile}
|
|
1822
|
-
`);
|
|
1823
|
-
const previewExists = EXTENSIONS.map((ext) => resolve(options.configDir, `preview${ext}`)).some(
|
|
1824
|
-
existsSync
|
|
1825
|
-
);
|
|
1826
|
-
const annotationsImport = info.frameworkPackage;
|
|
1827
|
-
const imports = [`import { setProjectAnnotations } from '${annotationsImport}';`];
|
|
1828
|
-
const projectAnnotations = [];
|
|
1829
|
-
if (previewExists) {
|
|
1830
|
-
imports.push(`import * as projectAnnotations from './preview';`);
|
|
1831
|
-
projectAnnotations.push("projectAnnotations");
|
|
1832
|
-
}
|
|
1833
|
-
await writeFile(
|
|
1834
|
-
vitestSetupFile,
|
|
1993
|
+
logErrors(
|
|
1994
|
+
"\u{1F6A8} Oh no!",
|
|
1835
1995
|
dedent`
|
|
1996
|
+
Found an existing Vitest setup file:
|
|
1997
|
+
${vitestSetupFile}
|
|
1998
|
+
|
|
1999
|
+
Please refer to the documentation to complete the setup manually:
|
|
2000
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
2001
|
+
`
|
|
2002
|
+
);
|
|
2003
|
+
logger2.line(1);
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
2006
|
+
logger2.line(1);
|
|
2007
|
+
logger2.plain(`${step} Creating a Vitest setup file for Storybook:`);
|
|
2008
|
+
logger2.plain(` ${vitestSetupFile}`);
|
|
2009
|
+
const previewExists = EXTENSIONS.map((ext) => resolve(options.configDir, `preview${ext}`)).some(
|
|
2010
|
+
existsSync
|
|
2011
|
+
);
|
|
2012
|
+
const imports = [`import { setProjectAnnotations } from '${annotationsImport}';`];
|
|
2013
|
+
const projectAnnotations = [];
|
|
2014
|
+
if (previewExists) {
|
|
2015
|
+
imports.push(`import * as projectAnnotations from './preview';`);
|
|
2016
|
+
projectAnnotations.push("projectAnnotations");
|
|
2017
|
+
}
|
|
2018
|
+
await writeFile(
|
|
2019
|
+
vitestSetupFile,
|
|
2020
|
+
dedent`
|
|
1836
2021
|
${imports.join("\n")}
|
|
1837
2022
|
|
|
1838
2023
|
// This is an important step to apply the right configuration when testing your stories.
|
|
1839
2024
|
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
|
|
1840
2025
|
setProjectAnnotations([${projectAnnotations.join(", ")}]);
|
|
1841
2026
|
`
|
|
1842
|
-
|
|
1843
|
-
}
|
|
2027
|
+
);
|
|
1844
2028
|
const vitestWorkspaceFile = findFile("vitest.workspace", [".ts", ".js", ".json"]);
|
|
1845
2029
|
const viteConfigFile = findFile("vite.config");
|
|
1846
2030
|
const vitestConfigFile = findFile("vitest.config");
|
|
@@ -1872,12 +2056,14 @@ async function postInstall(options) {
|
|
|
1872
2056
|
const target = babelParse(workspaceFile);
|
|
1873
2057
|
const updated = updateWorkspaceFile(source, target);
|
|
1874
2058
|
if (updated) {
|
|
1875
|
-
|
|
1876
|
-
|
|
2059
|
+
logger2.line(1);
|
|
2060
|
+
logger2.plain(`${step} Updating your Vitest workspace file:`);
|
|
2061
|
+
logger2.plain(` ${vitestWorkspaceFile}`);
|
|
1877
2062
|
const formattedContent = await formatFileContent(vitestWorkspaceFile, generate(target).code);
|
|
1878
2063
|
await writeFile(vitestWorkspaceFile, formattedContent);
|
|
1879
2064
|
} else {
|
|
1880
|
-
|
|
2065
|
+
logErrors(
|
|
2066
|
+
"\u{1F6A8} Oh no!",
|
|
1881
2067
|
dedent`
|
|
1882
2068
|
Could not update existing Vitest workspace file:
|
|
1883
2069
|
${vitestWorkspaceFile}
|
|
@@ -1889,7 +2075,8 @@ async function postInstall(options) {
|
|
|
1889
2075
|
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1890
2076
|
`
|
|
1891
2077
|
);
|
|
1892
|
-
|
|
2078
|
+
logger2.line(1);
|
|
2079
|
+
return;
|
|
1893
2080
|
}
|
|
1894
2081
|
} else if (rootConfig) {
|
|
1895
2082
|
let target, updated;
|
|
@@ -1908,100 +2095,148 @@ async function postInstall(options) {
|
|
|
1908
2095
|
updated = updateConfigFile(source, target);
|
|
1909
2096
|
}
|
|
1910
2097
|
if (target && updated) {
|
|
1911
|
-
|
|
1912
|
-
|
|
2098
|
+
logger2.line(1);
|
|
2099
|
+
logger2.plain(`${step} Updating your ${vitestConfigFile ? "Vitest" : "Vite"} config file:`);
|
|
2100
|
+
logger2.plain(` ${rootConfig}`);
|
|
1913
2101
|
const formattedContent = await formatFileContent(rootConfig, generate(target).code);
|
|
1914
2102
|
await writeFile(
|
|
1915
2103
|
rootConfig,
|
|
1916
2104
|
configFileHasTypeReference ? formattedContent : '/// <reference types="vitest/config" />\n' + formattedContent
|
|
1917
2105
|
);
|
|
1918
2106
|
} else {
|
|
1919
|
-
|
|
2107
|
+
logErrors(
|
|
2108
|
+
"\u{1F6A8} Oh no!",
|
|
2109
|
+
dedent`
|
|
1920
2110
|
We were unable to update your existing ${vitestConfigFile ? "Vitest" : "Vite"} config file.
|
|
1921
2111
|
|
|
1922
2112
|
Please refer to the documentation to complete the setup manually:
|
|
1923
2113
|
https://storybook.js.org/docs/writing-tests/integrations/vitest-addon#manual-setup
|
|
1924
|
-
`
|
|
1925
|
-
|
|
2114
|
+
`
|
|
2115
|
+
);
|
|
1926
2116
|
}
|
|
1927
2117
|
} else {
|
|
1928
|
-
const
|
|
1929
|
-
const newConfigFile = resolve(parentDir, `vitest.config.${fileExtension}`);
|
|
2118
|
+
const newConfigFile = resolve(`vitest.config.${fileExtension}`);
|
|
1930
2119
|
const configTemplate = await loadTemplate(getTemplateName(), {
|
|
1931
2120
|
CONFIG_DIR: options.configDir,
|
|
1932
2121
|
SETUP_FILE: relative(dirname(newConfigFile), vitestSetupFile)
|
|
1933
2122
|
});
|
|
1934
|
-
|
|
1935
|
-
|
|
2123
|
+
logger2.line(1);
|
|
2124
|
+
logger2.plain(`${step} Creating a Vitest config file:`);
|
|
2125
|
+
logger2.plain(` ${newConfigFile}`);
|
|
1936
2126
|
const formattedContent = await formatFileContent(newConfigFile, configTemplate);
|
|
1937
2127
|
await writeFile(newConfigFile, formattedContent);
|
|
1938
2128
|
}
|
|
1939
|
-
const a11yAddon =
|
|
2129
|
+
const a11yAddon = info2.addons.find((addon) => addon.includes(addonA11yName));
|
|
1940
2130
|
if (a11yAddon) {
|
|
1941
2131
|
try {
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
command.push("--yes", "--skip-doctor");
|
|
1945
|
-
if (options.packageManager) {
|
|
1946
|
-
command.push("--package-manager", options.packageManager);
|
|
1947
|
-
}
|
|
1948
|
-
if (options.skipInstall) {
|
|
1949
|
-
command.push("--skip-install");
|
|
1950
|
-
}
|
|
1951
|
-
if (options.configDir !== ".storybook") {
|
|
1952
|
-
command.push("--config-dir", `"${options.configDir}"`);
|
|
1953
|
-
}
|
|
1954
|
-
const remoteCommand = packageManager.getRemoteRunCommand(
|
|
2132
|
+
logger2.plain(`${step} Setting up ${addonA11yName} for @storybook/addon-vitest:`);
|
|
2133
|
+
await execa(
|
|
1955
2134
|
"storybook",
|
|
1956
|
-
|
|
1957
|
-
|
|
2135
|
+
[
|
|
2136
|
+
"automigrate",
|
|
2137
|
+
"addon-a11y-addon-test",
|
|
2138
|
+
"--loglevel",
|
|
2139
|
+
"silent",
|
|
2140
|
+
"--yes",
|
|
2141
|
+
"--skip-doctor",
|
|
2142
|
+
...options.packageManager ? ["--package-manager", options.packageManager] : [],
|
|
2143
|
+
...options.skipInstall ? ["--skip-install"] : [],
|
|
2144
|
+
...options.configDir !== ".storybook" ? ["--config-dir", `"${options.configDir}"`] : []
|
|
2145
|
+
],
|
|
2146
|
+
{
|
|
2147
|
+
stdio: "inherit"
|
|
2148
|
+
}
|
|
1958
2149
|
);
|
|
1959
|
-
const [cmd, ...args] = remoteCommand.split(" ");
|
|
1960
|
-
await prompt.executeTask(() => packageManager.executeCommand({ command: cmd, args }), {
|
|
1961
|
-
id: "a11y-addon-setup",
|
|
1962
|
-
intro: "Setting up a11y addon for @storybook/addon-vitest",
|
|
1963
|
-
error: "Failed to setup a11y addon for @storybook/addon-vitest",
|
|
1964
|
-
success: "a11y addon setup successfully"
|
|
1965
|
-
});
|
|
1966
2150
|
} catch (e) {
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
2151
|
+
logErrors(
|
|
2152
|
+
"\u{1F6A8} Oh no!",
|
|
2153
|
+
dedent`
|
|
2154
|
+
We have detected that you have ${addonA11yName} installed but could not automatically set it up for @storybook/addon-vitest:
|
|
2155
|
+
|
|
2156
|
+
${e instanceof Error ? e.message : String(e)}
|
|
2157
|
+
|
|
1971
2158
|
Please refer to the documentation to complete the setup manually:
|
|
1972
2159
|
https://storybook.js.org/docs/writing-tests/accessibility-testing#test-addon-integration
|
|
1973
|
-
`
|
|
1974
|
-
errors.push(
|
|
1975
|
-
"The @storybook/addon-a11y couldn't be set up for the Vitest addon" + (e instanceof Error ? e.stack : String(e))
|
|
2160
|
+
`
|
|
1976
2161
|
);
|
|
1977
2162
|
}
|
|
1978
2163
|
}
|
|
1979
2164
|
const runCommand = rootConfig ? `npx vitest --project=storybook` : `npx vitest`;
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
2165
|
+
if (!hasErrors) {
|
|
2166
|
+
printSuccess(
|
|
2167
|
+
"\u{1F389} All done!",
|
|
2168
|
+
dedent`
|
|
1984
2169
|
@storybook/addon-vitest is now configured and you're ready to run your tests!
|
|
2170
|
+
|
|
1985
2171
|
Here are a couple of tips to get you started:
|
|
1986
|
-
|
|
1987
|
-
•
|
|
1988
|
-
|
|
1989
|
-
|
|
2172
|
+
• You can run tests with "${runCommand}"
|
|
2173
|
+
• When using the Vitest extension in your editor, all of your stories will be shown as tests!
|
|
2174
|
+
|
|
1990
2175
|
Check the documentation for more information about its features and options at:
|
|
1991
2176
|
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}
|
|
1992
|
-
`
|
|
2177
|
+
`
|
|
2178
|
+
);
|
|
1993
2179
|
} else {
|
|
1994
|
-
|
|
2180
|
+
printWarning(
|
|
2181
|
+
"\u26A0\uFE0F Done, but with errors!",
|
|
1995
2182
|
dedent`
|
|
1996
|
-
|
|
1997
|
-
|
|
2183
|
+
@storybook/addon-vitest was installed successfully, but there were some errors during the setup process.
|
|
2184
|
+
|
|
2185
|
+
Please refer to the documentation to complete the setup manually and check the errors above:
|
|
1998
2186
|
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1999
2187
|
`
|
|
2000
2188
|
);
|
|
2001
|
-
throw new AddonVitestPostinstallError({ errors });
|
|
2002
2189
|
}
|
|
2190
|
+
logger2.line(1);
|
|
2003
2191
|
}
|
|
2004
2192
|
__name(postInstall, "postInstall");
|
|
2193
|
+
async function getPackageNameFromPath(input) {
|
|
2194
|
+
const path = input.startsWith("file://") ? fileURLToPath(input) : input;
|
|
2195
|
+
if (!isAbsolute(path)) {
|
|
2196
|
+
return path;
|
|
2197
|
+
}
|
|
2198
|
+
const packageJsonPath = up2({ cwd: path });
|
|
2199
|
+
if (!packageJsonPath) {
|
|
2200
|
+
throw new Error(`Could not find package.json in path: ${path}`);
|
|
2201
|
+
}
|
|
2202
|
+
const { default: packageJson } = await import(pathToFileURL(packageJsonPath).href, {
|
|
2203
|
+
with: { type: "json" }
|
|
2204
|
+
});
|
|
2205
|
+
return packageJson.name;
|
|
2206
|
+
}
|
|
2207
|
+
__name(getPackageNameFromPath, "getPackageNameFromPath");
|
|
2208
|
+
async function getStorybookInfo({ configDir, packageManager: pkgMgr }) {
|
|
2209
|
+
const packageManager = JsPackageManagerFactory.getPackageManager({ force: pkgMgr, configDir });
|
|
2210
|
+
const { packageJson } = packageManager.primaryPackageJson;
|
|
2211
|
+
const config = await loadMainConfig({ configDir });
|
|
2212
|
+
const { presets } = await experimental_loadStorybook({
|
|
2213
|
+
configDir,
|
|
2214
|
+
packageJson
|
|
2215
|
+
});
|
|
2216
|
+
const framework = await presets.apply("framework", {});
|
|
2217
|
+
const core = await presets.apply("core", {});
|
|
2218
|
+
const { builder, renderer } = core;
|
|
2219
|
+
if (!builder) {
|
|
2220
|
+
throw new Error("Could not detect your Storybook builder.");
|
|
2221
|
+
}
|
|
2222
|
+
const frameworkPackageName = await getPackageNameFromPath(
|
|
2223
|
+
typeof framework === "string" ? framework : framework.name
|
|
2224
|
+
);
|
|
2225
|
+
const builderPackageName = await getPackageNameFromPath(
|
|
2226
|
+
typeof builder === "string" ? builder : builder.name
|
|
2227
|
+
);
|
|
2228
|
+
let rendererPackageName;
|
|
2229
|
+
if (renderer) {
|
|
2230
|
+
rendererPackageName = await getPackageNameFromPath(renderer);
|
|
2231
|
+
}
|
|
2232
|
+
return {
|
|
2233
|
+
frameworkPackageName,
|
|
2234
|
+
builderPackageName,
|
|
2235
|
+
rendererPackageName,
|
|
2236
|
+
addons: getAddonNames(config)
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
__name(getStorybookInfo, "getStorybookInfo");
|
|
2005
2240
|
export {
|
|
2006
2241
|
postInstall as default
|
|
2007
2242
|
};
|