@storybook/addon-vitest 0.0.0-pr-32799-sha-2fd404cf → 0.0.0-pr-32717-sha-47ba2989
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-TZI2AHX2.js → chunk-26QD4KIO.js} +7 -7
- package/dist/_node-chunks/chunk-2JQWJGRS.js +60 -0
- package/dist/_node-chunks/chunk-45MCYOUJ.js +40 -0
- package/dist/_node-chunks/chunk-4H2GO2UY.js +260 -0
- package/dist/_node-chunks/{chunk-LIA3N4HE.js → chunk-BRIC3JT4.js} +6 -18
- package/dist/_node-chunks/{chunk-HQVHOASY.js → chunk-C2FSHTUD.js} +6 -6
- package/dist/_node-chunks/{chunk-AJ2WUJGZ.js → chunk-FXNIGN3F.js} +7 -7
- package/dist/_node-chunks/{chunk-4WN4QQI7.js → chunk-L2XD2AHB.js} +29 -8
- package/dist/_node-chunks/chunk-MYOIMEAF.js +69 -0
- package/dist/manager.js +117 -146
- package/dist/node/coverage-reporter.js +8 -8
- package/dist/node/vitest.js +26 -15
- package/dist/postinstall.js +184 -408
- package/dist/preset.js +30 -24
- package/dist/vitest-plugin/global-setup.js +8 -9
- package/dist/vitest-plugin/index.js +14 -11
- package/dist/vitest-plugin/setup-file.js +1 -1
- package/package.json +3 -7
- package/dist/_node-chunks/chunk-4PO6FO6L.js +0 -98
- package/dist/_node-chunks/chunk-VM7LYAZL.js +0 -37
- package/dist/_node-chunks/chunk-WQUQR2JF.js +0 -2574
- /package/dist/_browser-chunks/{chunk-CAYLRBRX.js → chunk-RPDOPHZX.js} +0 -0
package/dist/postinstall.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_2jsf5jhwlj6 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_2jsf5jhwlj6 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_2jsf5jhwlj6 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_2jsf5jhwlj6.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_2jsf5jhwlj6.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_2jsf5jhwlj6.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,
|
|
14
13
|
resolvePackageDir
|
|
15
|
-
} from "./_node-chunks/chunk-
|
|
14
|
+
} from "./_node-chunks/chunk-4H2GO2UY.js";
|
|
16
15
|
import {
|
|
17
|
-
any
|
|
18
|
-
|
|
19
|
-
up
|
|
20
|
-
} from "./_node-chunks/chunk-4PO6FO6L.js";
|
|
16
|
+
any
|
|
17
|
+
} from "./_node-chunks/chunk-2JQWJGRS.js";
|
|
21
18
|
import {
|
|
22
|
-
DOCUMENTATION_LINK
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
DOCUMENTATION_LINK
|
|
20
|
+
} from "./_node-chunks/chunk-BRIC3JT4.js";
|
|
21
|
+
import {
|
|
22
|
+
require_dist
|
|
23
|
+
} from "./_node-chunks/chunk-MYOIMEAF.js";
|
|
25
24
|
import {
|
|
26
25
|
dirname,
|
|
27
26
|
join,
|
|
28
27
|
relative,
|
|
29
28
|
resolve
|
|
30
|
-
} from "./_node-chunks/chunk-
|
|
29
|
+
} from "./_node-chunks/chunk-26QD4KIO.js";
|
|
31
30
|
import {
|
|
32
31
|
require_compare,
|
|
33
32
|
require_constants,
|
|
@@ -37,12 +36,12 @@ import {
|
|
|
37
36
|
require_parse_options,
|
|
38
37
|
require_re,
|
|
39
38
|
require_semver
|
|
40
|
-
} from "./_node-chunks/chunk-
|
|
39
|
+
} from "./_node-chunks/chunk-L2XD2AHB.js";
|
|
41
40
|
import {
|
|
42
41
|
__commonJS,
|
|
43
42
|
__name,
|
|
44
43
|
__toESM
|
|
45
|
-
} from "./_node-chunks/chunk-
|
|
44
|
+
} from "./_node-chunks/chunk-C2FSHTUD.js";
|
|
46
45
|
|
|
47
46
|
// ../../node_modules/semver/functions/parse.js
|
|
48
47
|
var require_parse = __commonJS({
|
|
@@ -364,7 +363,7 @@ var require_coerce = __commonJS({
|
|
|
364
363
|
var SemVer = require_semver();
|
|
365
364
|
var parse = require_parse();
|
|
366
365
|
var { safeRe: re, t } = require_re();
|
|
367
|
-
var
|
|
366
|
+
var coerce = /* @__PURE__ */ __name((version, options) => {
|
|
368
367
|
if (version instanceof SemVer) {
|
|
369
368
|
return version;
|
|
370
369
|
}
|
|
@@ -399,7 +398,7 @@ var require_coerce = __commonJS({
|
|
|
399
398
|
const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
|
|
400
399
|
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
|
|
401
400
|
}, "coerce");
|
|
402
|
-
module.exports =
|
|
401
|
+
module.exports = coerce;
|
|
403
402
|
}
|
|
404
403
|
});
|
|
405
404
|
|
|
@@ -620,6 +619,7 @@ var require_range = __commonJS({
|
|
|
620
619
|
return result;
|
|
621
620
|
}, "isSatisfiable");
|
|
622
621
|
var parseComparator = /* @__PURE__ */ __name((comp, options) => {
|
|
622
|
+
comp = comp.replace(re[t.BUILD], "");
|
|
623
623
|
debug("comp", comp, options);
|
|
624
624
|
comp = replaceCarets(comp, options);
|
|
625
625
|
debug("caret", comp);
|
|
@@ -1444,7 +1444,7 @@ var require_semver2 = __commonJS({
|
|
|
1444
1444
|
var gte = require_gte();
|
|
1445
1445
|
var lte = require_lte();
|
|
1446
1446
|
var cmp = require_cmp();
|
|
1447
|
-
var
|
|
1447
|
+
var coerce = require_coerce();
|
|
1448
1448
|
var Comparator = require_comparator();
|
|
1449
1449
|
var Range = require_range();
|
|
1450
1450
|
var satisfies2 = require_satisfies();
|
|
@@ -1482,7 +1482,7 @@ var require_semver2 = __commonJS({
|
|
|
1482
1482
|
gte,
|
|
1483
1483
|
lte,
|
|
1484
1484
|
cmp,
|
|
1485
|
-
coerce
|
|
1485
|
+
coerce,
|
|
1486
1486
|
Comparator,
|
|
1487
1487
|
Range,
|
|
1488
1488
|
satisfies: satisfies2,
|
|
@@ -1513,55 +1513,22 @@ var require_semver2 = __commonJS({
|
|
|
1513
1513
|
import { existsSync } from "node:fs";
|
|
1514
1514
|
import * as fs2 from "node:fs/promises";
|
|
1515
1515
|
import { writeFile } from "node:fs/promises";
|
|
1516
|
-
import {
|
|
1517
|
-
import {
|
|
1518
|
-
import { babelParse, generate, traverse } from "storybook/internal/babel";
|
|
1516
|
+
import { babelParse, generate } from "storybook/internal/babel";
|
|
1517
|
+
import { AddonVitestService } from "storybook/internal/cli";
|
|
1519
1518
|
import {
|
|
1520
1519
|
JsPackageManagerFactory,
|
|
1521
1520
|
formatFileContent,
|
|
1522
|
-
getInterpretedFile,
|
|
1523
1521
|
getProjectRoot,
|
|
1524
|
-
|
|
1525
|
-
loadMainConfig,
|
|
1526
|
-
scanAndTransformFiles,
|
|
1527
|
-
transformImportFiles
|
|
1522
|
+
getStorybookInfo
|
|
1528
1523
|
} from "storybook/internal/common";
|
|
1529
|
-
import {
|
|
1530
|
-
import {
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
return up("package.json", options);
|
|
1536
|
-
}
|
|
1537
|
-
__name(up2, "up");
|
|
1538
|
-
|
|
1539
|
-
// src/postinstall.ts
|
|
1524
|
+
import { CLI_COLORS } from "storybook/internal/node-logger";
|
|
1525
|
+
import {
|
|
1526
|
+
AddonVitestPostinstallError,
|
|
1527
|
+
AddonVitestPostinstallPrerequisiteCheckError
|
|
1528
|
+
} from "storybook/internal/server-errors";
|
|
1529
|
+
import { SupportedFramework } from "storybook/internal/types";
|
|
1540
1530
|
var import_semver = __toESM(require_semver2(), 1);
|
|
1541
|
-
|
|
1542
|
-
import { dedent } from "ts-dedent";
|
|
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");
|
|
1531
|
+
var import_ts_dedent = __toESM(require_dist(), 1);
|
|
1565
1532
|
|
|
1566
1533
|
// src/updateVitestFile.ts
|
|
1567
1534
|
import * as fs from "node:fs/promises";
|
|
@@ -1771,274 +1738,134 @@ var updateWorkspaceFile = /* @__PURE__ */ __name((source, target) => {
|
|
|
1771
1738
|
var ADDON_NAME = "@storybook/addon-vitest";
|
|
1772
1739
|
var EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".cts", ".mts", ".cjs", ".mjs"];
|
|
1773
1740
|
var addonA11yName = "@storybook/addon-a11y";
|
|
1774
|
-
var hasErrors = false;
|
|
1775
|
-
function nameMatches(name, pattern) {
|
|
1776
|
-
if (name === pattern) {
|
|
1777
|
-
return true;
|
|
1778
|
-
}
|
|
1779
|
-
if (name.includes(`${pattern}${sep}`)) {
|
|
1780
|
-
return true;
|
|
1781
|
-
}
|
|
1782
|
-
if (name.includes(`${pattern}${posix.sep}`)) {
|
|
1783
|
-
return true;
|
|
1784
|
-
}
|
|
1785
|
-
return false;
|
|
1786
|
-
}
|
|
1787
|
-
__name(nameMatches, "nameMatches");
|
|
1788
|
-
var logErrors = /* @__PURE__ */ __name((...args) => {
|
|
1789
|
-
hasErrors = true;
|
|
1790
|
-
printError(...args);
|
|
1791
|
-
}, "logErrors");
|
|
1792
|
-
var findFile = /* @__PURE__ */ __name((basename, extensions = EXTENSIONS) => any(
|
|
1793
|
-
extensions.map((ext) => basename + ext),
|
|
1794
|
-
{ last: getProjectRoot() }
|
|
1795
|
-
), "findFile");
|
|
1796
1741
|
async function postInstall(options) {
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
dedent`
|
|
1800
|
-
I'm the installation helper for ${ADDON_NAME}
|
|
1801
|
-
|
|
1802
|
-
Hold on for a moment while I look at your project and get it set up...
|
|
1803
|
-
`
|
|
1804
|
-
);
|
|
1742
|
+
const errors = [];
|
|
1743
|
+
const { logger, prompt } = options;
|
|
1805
1744
|
const packageManager = JsPackageManagerFactory.getPackageManager({
|
|
1806
1745
|
force: options.packageManager
|
|
1807
1746
|
});
|
|
1747
|
+
const findFile = /* @__PURE__ */ __name((basename, extensions = EXTENSIONS) => any(
|
|
1748
|
+
extensions.map((ext) => basename + ext),
|
|
1749
|
+
{ last: getProjectRoot(), cwd: options.configDir }
|
|
1750
|
+
), "findFile");
|
|
1808
1751
|
const vitestVersionSpecifier = await packageManager.getInstalledVersion("vitest");
|
|
1809
|
-
|
|
1752
|
+
logger.debug(`Vitest version specifier: ${vitestVersionSpecifier}`);
|
|
1810
1753
|
const isVitest3_2To4 = vitestVersionSpecifier ? (0, import_semver.satisfies)(vitestVersionSpecifier, ">=3.2.0 <4.0.0") : false;
|
|
1811
1754
|
const isVitest4OrNewer = vitestVersionSpecifier ? (0, import_semver.satisfies)(vitestVersionSpecifier, ">=4.0.0") : true;
|
|
1812
|
-
const
|
|
1755
|
+
const info = await getStorybookInfo(options.configDir);
|
|
1813
1756
|
const allDeps = packageManager.getAllDependencies();
|
|
1814
|
-
const
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1757
|
+
const addonVitestService = new AddonVitestService();
|
|
1758
|
+
const compatibilityResult = await addonVitestService.validateCompatibility({
|
|
1759
|
+
packageManager,
|
|
1760
|
+
framework: info.framework,
|
|
1761
|
+
builder: info.builder
|
|
1762
|
+
});
|
|
1763
|
+
let result = null;
|
|
1764
|
+
if (!compatibilityResult.compatible && compatibilityResult.reasons) {
|
|
1765
|
+
const reasons = compatibilityResult.reasons.map((r) => `\u2022 ${CLI_COLORS.error(r)}`);
|
|
1766
|
+
reasons.unshift(import_ts_dedent.dedent`
|
|
1767
|
+
Automated setup failed
|
|
1768
|
+
The following packages have incompatibilities that prevent automated setup:
|
|
1769
|
+
`);
|
|
1770
|
+
reasons.push(
|
|
1771
|
+
import_ts_dedent.dedent`
|
|
1772
|
+
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
|
|
1773
|
+
in your main Storybook config file and remove the dependency from your package.json file.
|
|
1831
1774
|
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1775
|
+
Please check the documentation for more information about its requirements and installation:
|
|
1776
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}
|
|
1777
|
+
`
|
|
1778
|
+
);
|
|
1779
|
+
result = reasons.map((r) => r.trim()).join("\n\n");
|
|
1780
|
+
}
|
|
1781
|
+
if (result) {
|
|
1782
|
+
logger.error(result);
|
|
1783
|
+
throw new AddonVitestPostinstallPrerequisiteCheckError({
|
|
1784
|
+
reasons: compatibilityResult.reasons
|
|
1835
1785
|
});
|
|
1836
|
-
if (out.migrateToNextjsVite) {
|
|
1837
|
-
await packageManager.addDependencies({ type: "devDependencies", skipInstall: true }, [
|
|
1838
|
-
"@storybook/nextjs-vite"
|
|
1839
|
-
]);
|
|
1840
|
-
await packageManager.removeDependencies(["@storybook/nextjs"]);
|
|
1841
|
-
traverse(config._ast, {
|
|
1842
|
-
StringLiteral(path) {
|
|
1843
|
-
if (path.node.value === "@storybook/nextjs") {
|
|
1844
|
-
path.node.value = "@storybook/nextjs-vite";
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
});
|
|
1848
|
-
await writeConfig(config, mainJsPath);
|
|
1849
|
-
info2.frameworkPackageName = "@storybook/nextjs-vite";
|
|
1850
|
-
info2.builderPackageName = "@storybook/builder-vite";
|
|
1851
|
-
await scanAndTransformFiles({
|
|
1852
|
-
promptMessage: "Enter a glob to scan for all @storybook/nextjs imports to substitute with @storybook/nextjs-vite:",
|
|
1853
|
-
force: options.yes,
|
|
1854
|
-
dryRun: false,
|
|
1855
|
-
transformFn: /* @__PURE__ */ __name((files, options2, dryRun) => transformImportFiles(files, options2, dryRun), "transformFn"),
|
|
1856
|
-
transformOptions: {
|
|
1857
|
-
"@storybook/nextjs": "@storybook/nextjs-vite"
|
|
1858
|
-
}
|
|
1859
|
-
});
|
|
1860
|
-
}
|
|
1861
1786
|
}
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
const reasons = [];
|
|
1868
|
-
if (hasCustomWebpackConfig) {
|
|
1869
|
-
reasons.push("\u2022 The addon can not be used with a custom Webpack configuration.");
|
|
1870
|
-
}
|
|
1871
|
-
if (!nameMatches(info2.frameworkPackageName, "@storybook/nextjs") && !nameMatches(info2.builderPackageName, "@storybook/builder-vite")) {
|
|
1872
|
-
reasons.push(
|
|
1873
|
-
"\u2022 The addon can only be used with a Vite-based Storybook framework or Next.js."
|
|
1874
|
-
);
|
|
1875
|
-
}
|
|
1876
|
-
if (!isRendererSupported) {
|
|
1877
|
-
reasons.push(dedent`
|
|
1878
|
-
• The addon cannot yet be used with ${info2.frameworkPackageName}
|
|
1879
|
-
`);
|
|
1880
|
-
}
|
|
1881
|
-
if (coercedVitestVersion && !(0, import_semver.satisfies)(coercedVitestVersion, ">=3.0.0")) {
|
|
1882
|
-
reasons.push(dedent`
|
|
1883
|
-
• The addon requires Vitest 3.0.0 or higher. You are currently using ${vitestVersionSpecifier}.
|
|
1884
|
-
Please update all of your Vitest dependencies and try again.
|
|
1885
|
-
`);
|
|
1886
|
-
}
|
|
1887
|
-
const mswVersionSpecifier = await packageManager.getInstalledVersion("msw");
|
|
1888
|
-
const coercedMswVersion = mswVersionSpecifier ? (0, import_semver.coerce)(mswVersionSpecifier) : null;
|
|
1889
|
-
if (coercedMswVersion && !(0, import_semver.satisfies)(coercedMswVersion, ">=2.0.0")) {
|
|
1890
|
-
reasons.push(dedent`
|
|
1891
|
-
• 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.
|
|
1892
|
-
Please update the 'msw' package and try again.
|
|
1893
|
-
`);
|
|
1894
|
-
}
|
|
1895
|
-
if (nameMatches(info2.frameworkPackageName, "@storybook/nextjs")) {
|
|
1896
|
-
const nextVersion = await packageManager.getInstalledVersion("next");
|
|
1897
|
-
if (!nextVersion) {
|
|
1898
|
-
reasons.push(dedent`
|
|
1899
|
-
• You are using @storybook/nextjs without having "next" installed.
|
|
1900
|
-
Please install "next" or use a different Storybook framework integration and try again.
|
|
1901
|
-
`);
|
|
1787
|
+
if (!options.skipDependencyManagement) {
|
|
1788
|
+
const versionedDependencies = await addonVitestService.collectDependencies(packageManager);
|
|
1789
|
+
if (info.framework === SupportedFramework.NEXTJS) {
|
|
1790
|
+
const allDeps2 = packageManager.getAllDependencies();
|
|
1791
|
+
if (!allDeps2["@storybook/nextjs-vite"]) {
|
|
1902
1792
|
}
|
|
1903
1793
|
}
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1794
|
+
const v8Version = await packageManager.getInstalledVersion("@vitest/coverage-v8");
|
|
1795
|
+
const istanbulVersion = await packageManager.getInstalledVersion("@vitest/coverage-istanbul");
|
|
1796
|
+
if (!v8Version && !istanbulVersion) {
|
|
1797
|
+
logger.step(
|
|
1798
|
+
import_ts_dedent.dedent`
|
|
1799
|
+
You don't seem to have a coverage reporter installed. Vitest needs either V8 or Istanbul to generate coverage reports.
|
|
1800
|
+
|
|
1801
|
+
Adding "@vitest/coverage-v8" to enable coverage reporting.
|
|
1802
|
+
Read more about Vitest coverage providers at https://vitest.dev/guide/coverage.html#coverage-providers
|
|
1913
1803
|
`
|
|
1914
1804
|
);
|
|
1915
|
-
if (!isRendererSupported) {
|
|
1916
|
-
reasons.push(
|
|
1917
|
-
dedent`
|
|
1918
|
-
Please check the documentation for more information about its requirements and installation:
|
|
1919
|
-
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}
|
|
1920
|
-
`
|
|
1921
|
-
);
|
|
1922
|
-
} else {
|
|
1923
|
-
reasons.push(
|
|
1924
|
-
dedent`
|
|
1925
|
-
Fear not, however, you can follow the manual installation process instead at:
|
|
1926
|
-
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1927
|
-
`
|
|
1928
|
-
);
|
|
1929
|
-
}
|
|
1930
|
-
return reasons.map((r) => r.trim()).join("\n\n");
|
|
1931
1805
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
}
|
|
1940
|
-
if (info2.frameworkPackageName === "@storybook/nextjs") {
|
|
1941
|
-
printInfo(
|
|
1942
|
-
"\u{1F37F} Just so you know...",
|
|
1943
|
-
dedent`
|
|
1944
|
-
It looks like you're using Next.js.
|
|
1945
|
-
|
|
1946
|
-
Adding "@storybook/nextjs-vite/vite-plugin" so you can use it with Vitest.
|
|
1947
|
-
|
|
1948
|
-
More info about the plugin at https://github.com/storybookjs/vite-plugin-storybook-nextjs
|
|
1949
|
-
`
|
|
1950
|
-
);
|
|
1951
|
-
try {
|
|
1952
|
-
const storybookVersion = await packageManager.getInstalledVersion("storybook");
|
|
1953
|
-
uniqueDependencies.push(`@storybook/nextjs-vite@^${storybookVersion}`);
|
|
1954
|
-
} catch (e) {
|
|
1955
|
-
console.error("Failed to install @storybook/nextjs-vite. Please install it manually");
|
|
1806
|
+
if (versionedDependencies.length > 0) {
|
|
1807
|
+
logger.step("Adding dependencies to your package.json");
|
|
1808
|
+
logger.log(" " + versionedDependencies.join(", "));
|
|
1809
|
+
await packageManager.addDependencies(
|
|
1810
|
+
{ type: "devDependencies", skipInstall: true },
|
|
1811
|
+
versionedDependencies
|
|
1812
|
+
);
|
|
1956
1813
|
}
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
const istanbulVersion = await packageManager.getInstalledVersion("@vitest/coverage-istanbul");
|
|
1960
|
-
if (!v8Version && !istanbulVersion) {
|
|
1961
|
-
printInfo(
|
|
1962
|
-
"\u{1F648} Let me cover this for you",
|
|
1963
|
-
dedent`
|
|
1964
|
-
You don't seem to have a coverage reporter installed. Vitest needs either V8 or Istanbul to generate coverage reports.
|
|
1965
|
-
|
|
1966
|
-
Adding "@vitest/coverage-v8" to enable coverage reporting.
|
|
1967
|
-
Read more about Vitest coverage providers at https://vitest.dev/guide/coverage.html#coverage-providers
|
|
1968
|
-
`
|
|
1969
|
-
);
|
|
1970
|
-
uniqueDependencies.push(`@vitest/coverage-v8`);
|
|
1971
|
-
}
|
|
1972
|
-
const versionedDependencies = uniqueDependencies.map((p) => {
|
|
1973
|
-
if (p.includes("vitest")) {
|
|
1974
|
-
return vitestVersionSpecifier ? `${p}@${vitestVersionSpecifier}` : p;
|
|
1814
|
+
if (!options.skipInstall) {
|
|
1815
|
+
await packageManager.installDependencies();
|
|
1975
1816
|
}
|
|
1976
|
-
return p;
|
|
1977
|
-
});
|
|
1978
|
-
if (versionedDependencies.length > 0) {
|
|
1979
|
-
await packageManager.addDependencies(
|
|
1980
|
-
{ type: "devDependencies", skipInstall: true },
|
|
1981
|
-
versionedDependencies
|
|
1982
|
-
);
|
|
1983
|
-
logger2.line(1);
|
|
1984
|
-
logger2.plain(`${step} Installing dependencies:`);
|
|
1985
|
-
logger2.plain(" " + versionedDependencies.join(", "));
|
|
1986
1817
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
logger2.plain(" npx playwright install chromium --with-deps");
|
|
1992
|
-
} else {
|
|
1993
|
-
logger2.plain(`${step} Configuring Playwright with Chromium (this might take some time):`);
|
|
1994
|
-
logger2.plain(" npx playwright install chromium --with-deps");
|
|
1995
|
-
try {
|
|
1996
|
-
await packageManager.executeCommand({
|
|
1997
|
-
command: "npx",
|
|
1998
|
-
args: ["playwright", "install", "chromium", "--with-deps"]
|
|
1818
|
+
if (!options.skipDependencyManagement) {
|
|
1819
|
+
if (!options.skipInstall) {
|
|
1820
|
+
const playwrightErrors = await addonVitestService.installPlaywright(packageManager, {
|
|
1821
|
+
yes: options.yes
|
|
1999
1822
|
});
|
|
2000
|
-
|
|
2001
|
-
|
|
1823
|
+
errors.push(...playwrightErrors);
|
|
1824
|
+
} else {
|
|
1825
|
+
logger.warn(import_ts_dedent.dedent`
|
|
1826
|
+
Playwright browser binaries installation skipped. Please run the following command manually later:
|
|
1827
|
+
${CLI_COLORS.cta("npx playwright install chromium --with-deps")}
|
|
1828
|
+
`);
|
|
2002
1829
|
}
|
|
2003
1830
|
}
|
|
2004
1831
|
const fileExtension = allDeps.typescript || findFile("tsconfig", [...EXTENSIONS, ".json"]) ? "ts" : "js";
|
|
2005
1832
|
const vitestSetupFile = resolve(options.configDir, `vitest.setup.${fileExtension}`);
|
|
2006
1833
|
if (existsSync(vitestSetupFile)) {
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
1834
|
+
const errorMessage = import_ts_dedent.dedent`
|
|
1835
|
+
Found an existing Vitest setup file:
|
|
1836
|
+
${vitestSetupFile}
|
|
1837
|
+
Please refer to the documentation to complete the setup manually:
|
|
1838
|
+
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
1839
|
+
`;
|
|
1840
|
+
logger.line();
|
|
1841
|
+
logger.error(`${errorMessage}
|
|
1842
|
+
`);
|
|
1843
|
+
errors.push("Found existing Vitest setup file");
|
|
1844
|
+
} else {
|
|
1845
|
+
logger.step(`Creating a Vitest setup file for Storybook:`);
|
|
1846
|
+
logger.log(`${vitestSetupFile}
|
|
1847
|
+
`);
|
|
1848
|
+
const previewExists = EXTENSIONS.map((ext) => resolve(options.configDir, `preview${ext}`)).some(
|
|
1849
|
+
existsSync
|
|
2016
1850
|
);
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
const projectAnnotations = [];
|
|
2028
|
-
if (previewExists) {
|
|
2029
|
-
imports.push(`import * as projectAnnotations from './preview';`);
|
|
2030
|
-
projectAnnotations.push("projectAnnotations");
|
|
2031
|
-
}
|
|
2032
|
-
await writeFile(
|
|
2033
|
-
vitestSetupFile,
|
|
2034
|
-
dedent`
|
|
1851
|
+
const annotationsImport = info.frameworkPackage;
|
|
1852
|
+
const imports = [`import { setProjectAnnotations } from '${annotationsImport}';`];
|
|
1853
|
+
const projectAnnotations = [];
|
|
1854
|
+
if (previewExists) {
|
|
1855
|
+
imports.push(`import * as projectAnnotations from './preview';`);
|
|
1856
|
+
projectAnnotations.push("projectAnnotations");
|
|
1857
|
+
}
|
|
1858
|
+
await writeFile(
|
|
1859
|
+
vitestSetupFile,
|
|
1860
|
+
import_ts_dedent.dedent`
|
|
2035
1861
|
${imports.join("\n")}
|
|
2036
1862
|
|
|
2037
1863
|
// This is an important step to apply the right configuration when testing your stories.
|
|
2038
1864
|
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
|
|
2039
1865
|
setProjectAnnotations([${projectAnnotations.join(", ")}]);
|
|
2040
1866
|
`
|
|
2041
|
-
|
|
1867
|
+
);
|
|
1868
|
+
}
|
|
2042
1869
|
const vitestWorkspaceFile = findFile("vitest.workspace", [".ts", ".js", ".json"]);
|
|
2043
1870
|
const viteConfigFile = findFile("vite.config");
|
|
2044
1871
|
const vitestConfigFile = findFile("vitest.config");
|
|
@@ -2070,15 +1897,13 @@ async function postInstall(options) {
|
|
|
2070
1897
|
const target = babelParse(workspaceFile);
|
|
2071
1898
|
const updated = updateWorkspaceFile(source, target);
|
|
2072
1899
|
if (updated) {
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
logger2.plain(` ${vitestWorkspaceFile}`);
|
|
1900
|
+
logger.step(`Updating your Vitest workspace file...`);
|
|
1901
|
+
logger.log(`${vitestWorkspaceFile}`);
|
|
2076
1902
|
const formattedContent = await formatFileContent(vitestWorkspaceFile, generate(target).code);
|
|
2077
1903
|
await writeFile(vitestWorkspaceFile, formattedContent);
|
|
2078
1904
|
} else {
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
dedent`
|
|
1905
|
+
logger.error(
|
|
1906
|
+
import_ts_dedent.dedent`
|
|
2082
1907
|
Could not update existing Vitest workspace file:
|
|
2083
1908
|
${vitestWorkspaceFile}
|
|
2084
1909
|
|
|
@@ -2089,8 +1914,7 @@ async function postInstall(options) {
|
|
|
2089
1914
|
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
2090
1915
|
`
|
|
2091
1916
|
);
|
|
2092
|
-
|
|
2093
|
-
return;
|
|
1917
|
+
errors.push("Unable to update existing Vitest workspace file");
|
|
2094
1918
|
}
|
|
2095
1919
|
} else if (rootConfig) {
|
|
2096
1920
|
let target, updated;
|
|
@@ -2109,9 +1933,8 @@ async function postInstall(options) {
|
|
|
2109
1933
|
updated = updateConfigFile(source, target);
|
|
2110
1934
|
}
|
|
2111
1935
|
if (target && updated) {
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
logger2.plain(` ${rootConfig}`);
|
|
1936
|
+
logger.step(`Updating your ${vitestConfigFile ? "Vitest" : "Vite"} config file:`);
|
|
1937
|
+
logger.log(` ${rootConfig}`);
|
|
2115
1938
|
const formattedContent = await formatFileContent(rootConfig, generate(target).code);
|
|
2116
1939
|
const shouldAddReference = !configFileHasTypeReference && !vitestConfigFile;
|
|
2117
1940
|
await writeFile(
|
|
@@ -2119,139 +1942,92 @@ async function postInstall(options) {
|
|
|
2119
1942
|
shouldAddReference ? '/// <reference types="vitest/config" />\n' + formattedContent : formattedContent
|
|
2120
1943
|
);
|
|
2121
1944
|
} else {
|
|
2122
|
-
|
|
2123
|
-
"\u{1F6A8} Oh no!",
|
|
2124
|
-
dedent`
|
|
1945
|
+
logger.error(import_ts_dedent.dedent`
|
|
2125
1946
|
We were unable to update your existing ${vitestConfigFile ? "Vitest" : "Vite"} config file.
|
|
2126
1947
|
|
|
2127
1948
|
Please refer to the documentation to complete the setup manually:
|
|
2128
1949
|
https://storybook.js.org/docs/writing-tests/integrations/vitest-addon#manual-setup
|
|
2129
|
-
`
|
|
2130
|
-
);
|
|
1950
|
+
`);
|
|
1951
|
+
errors.push("Unable to update existing Vitest config file");
|
|
2131
1952
|
}
|
|
2132
1953
|
} else {
|
|
2133
|
-
const
|
|
1954
|
+
const parentDir = dirname(options.configDir);
|
|
1955
|
+
const newConfigFile = resolve(parentDir, `vitest.config.${fileExtension}`);
|
|
2134
1956
|
const configTemplate = await loadTemplate(getTemplateName(), {
|
|
2135
1957
|
CONFIG_DIR: options.configDir,
|
|
2136
1958
|
SETUP_FILE: relative(dirname(newConfigFile), vitestSetupFile)
|
|
2137
1959
|
});
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
logger2.plain(` ${newConfigFile}`);
|
|
1960
|
+
logger.step(`Creating a Vitest config file:`);
|
|
1961
|
+
logger.log(`${newConfigFile}`);
|
|
2141
1962
|
const formattedContent = await formatFileContent(newConfigFile, configTemplate);
|
|
2142
1963
|
await writeFile(newConfigFile, formattedContent);
|
|
2143
1964
|
}
|
|
2144
|
-
const a11yAddon =
|
|
1965
|
+
const a11yAddon = info.addons.find((addon) => addon.includes(addonA11yName));
|
|
2145
1966
|
if (a11yAddon) {
|
|
2146
1967
|
try {
|
|
2147
|
-
|
|
2148
|
-
await execa(
|
|
1968
|
+
const command = [
|
|
2149
1969
|
"storybook",
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
1970
|
+
"automigrate",
|
|
1971
|
+
"addon-a11y-addon-test",
|
|
1972
|
+
"--loglevel",
|
|
1973
|
+
"silent",
|
|
1974
|
+
"--yes",
|
|
1975
|
+
"--skip-doctor"
|
|
1976
|
+
];
|
|
1977
|
+
if (options.packageManager) {
|
|
1978
|
+
command.push("--package-manager", options.packageManager);
|
|
1979
|
+
}
|
|
1980
|
+
if (options.skipInstall) {
|
|
1981
|
+
command.push("--skip-install");
|
|
1982
|
+
}
|
|
1983
|
+
if (options.configDir !== ".storybook") {
|
|
1984
|
+
command.push("--config-dir", options.configDir);
|
|
1985
|
+
}
|
|
1986
|
+
await prompt.executeTask(
|
|
1987
|
+
// TODO: Remove stdio: 'ignore' once we have a way to log the output of the command properly
|
|
1988
|
+
() => packageManager.runPackageCommand({ args: command, stdio: "ignore" }),
|
|
2161
1989
|
{
|
|
2162
|
-
|
|
1990
|
+
intro: "Setting up a11y addon for @storybook/addon-vitest",
|
|
1991
|
+
error: "Failed to setup a11y addon for @storybook/addon-vitest",
|
|
1992
|
+
success: "a11y addon setup successfully"
|
|
2163
1993
|
}
|
|
2164
1994
|
);
|
|
2165
1995
|
} catch (e) {
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
dedent`
|
|
2169
|
-
We have detected that you have ${addonA11yName} installed but could not automatically set it up for @storybook/addon-vitest:
|
|
2170
|
-
|
|
2171
|
-
${e instanceof Error ? e.message : String(e)}
|
|
2172
|
-
|
|
1996
|
+
logger.error(import_ts_dedent.dedent`
|
|
1997
|
+
Could not automatically set up ${addonA11yName} for @storybook/addon-vitest.
|
|
2173
1998
|
Please refer to the documentation to complete the setup manually:
|
|
2174
1999
|
https://storybook.js.org/docs/writing-tests/accessibility-testing#test-addon-integration
|
|
2175
|
-
`
|
|
2000
|
+
`);
|
|
2001
|
+
errors.push(
|
|
2002
|
+
"The @storybook/addon-a11y couldn't be set up for the Vitest addon" + (e instanceof Error ? e.stack : String(e))
|
|
2176
2003
|
);
|
|
2177
2004
|
}
|
|
2178
2005
|
}
|
|
2179
2006
|
const runCommand = rootConfig ? `npx vitest --project=storybook` : `npx vitest`;
|
|
2180
|
-
if (
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
dedent`
|
|
2007
|
+
if (errors.length === 0) {
|
|
2008
|
+
logger.step(CLI_COLORS.success("@storybook/addon-vitest setup completed successfully"));
|
|
2009
|
+
logger.log(import_ts_dedent.dedent`
|
|
2184
2010
|
@storybook/addon-vitest is now configured and you're ready to run your tests!
|
|
2185
|
-
|
|
2186
2011
|
Here are a couple of tips to get you started:
|
|
2187
|
-
|
|
2188
|
-
•
|
|
2189
|
-
|
|
2012
|
+
|
|
2013
|
+
• You can run tests with "${CLI_COLORS.cta(runCommand)}"
|
|
2014
|
+
• Vitest IDE extension shows all stories as tests in your editor!
|
|
2015
|
+
|
|
2190
2016
|
Check the documentation for more information about its features and options at:
|
|
2191
2017
|
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}
|
|
2192
|
-
`
|
|
2193
|
-
);
|
|
2018
|
+
`);
|
|
2194
2019
|
} else {
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
@storybook/addon-vitest was installed successfully, but there were some errors during the setup process.
|
|
2199
|
-
|
|
2200
|
-
Please refer to the documentation to complete the setup manually and check the errors above:
|
|
2020
|
+
logger.warn(
|
|
2021
|
+
import_ts_dedent.dedent`
|
|
2022
|
+
Done, but with errors!
|
|
2023
|
+
@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:
|
|
2201
2024
|
https://storybook.js.org/docs/next/${DOCUMENTATION_LINK}#manual-setup
|
|
2202
2025
|
`
|
|
2203
2026
|
);
|
|
2027
|
+
throw new AddonVitestPostinstallError({ errors });
|
|
2204
2028
|
}
|
|
2205
|
-
logger2.line(1);
|
|
2206
2029
|
}
|
|
2207
2030
|
__name(postInstall, "postInstall");
|
|
2208
|
-
async function getPackageNameFromPath(input) {
|
|
2209
|
-
const path = input.startsWith("file://") ? fileURLToPath(input) : input;
|
|
2210
|
-
if (!isAbsolute(path)) {
|
|
2211
|
-
return path;
|
|
2212
|
-
}
|
|
2213
|
-
const packageJsonPath = up2({ cwd: path });
|
|
2214
|
-
if (!packageJsonPath) {
|
|
2215
|
-
throw new Error(`Could not find package.json in path: ${path}`);
|
|
2216
|
-
}
|
|
2217
|
-
const { default: packageJson } = await import(pathToFileURL(packageJsonPath).href, {
|
|
2218
|
-
with: { type: "json" }
|
|
2219
|
-
});
|
|
2220
|
-
return packageJson.name;
|
|
2221
|
-
}
|
|
2222
|
-
__name(getPackageNameFromPath, "getPackageNameFromPath");
|
|
2223
|
-
async function getStorybookInfo({ configDir, packageManager: pkgMgr }) {
|
|
2224
|
-
const packageManager = JsPackageManagerFactory.getPackageManager({ force: pkgMgr, configDir });
|
|
2225
|
-
const { packageJson } = packageManager.primaryPackageJson;
|
|
2226
|
-
const config = await loadMainConfig({ configDir });
|
|
2227
|
-
const { presets } = await experimental_loadStorybook({
|
|
2228
|
-
configDir,
|
|
2229
|
-
packageJson
|
|
2230
|
-
});
|
|
2231
|
-
const framework = await presets.apply("framework", {});
|
|
2232
|
-
const core = await presets.apply("core", {});
|
|
2233
|
-
const { builder, renderer } = core;
|
|
2234
|
-
if (!builder) {
|
|
2235
|
-
throw new Error("Could not detect your Storybook builder.");
|
|
2236
|
-
}
|
|
2237
|
-
const frameworkPackageName = await getPackageNameFromPath(
|
|
2238
|
-
typeof framework === "string" ? framework : framework.name
|
|
2239
|
-
);
|
|
2240
|
-
const builderPackageName = await getPackageNameFromPath(
|
|
2241
|
-
typeof builder === "string" ? builder : builder.name
|
|
2242
|
-
);
|
|
2243
|
-
let rendererPackageName;
|
|
2244
|
-
if (renderer) {
|
|
2245
|
-
rendererPackageName = await getPackageNameFromPath(renderer);
|
|
2246
|
-
}
|
|
2247
|
-
return {
|
|
2248
|
-
frameworkPackageName,
|
|
2249
|
-
builderPackageName,
|
|
2250
|
-
rendererPackageName,
|
|
2251
|
-
addons: getAddonNames(config)
|
|
2252
|
-
};
|
|
2253
|
-
}
|
|
2254
|
-
__name(getStorybookInfo, "getStorybookInfo");
|
|
2255
2031
|
export {
|
|
2256
2032
|
postInstall as default
|
|
2257
2033
|
};
|