UNPKG

@testplane/storybook

Version:

Testplane plugin that enables runtime screenshot storybook tests autogeneration

63 lines 2.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStorybookDevServer = void 0; const child_process_1 = require("child_process"); const npm_which_1 = __importDefault(require("npm-which")); const logger_1 = __importDefault(require("../../logger")); const pipe_with_prefix_1 = require("./pipe-with-prefix"); const is_port_busy_1 = require("./is-port-busy"); const getStorybookCliPath = () => { try { const startStorybookPath = npm_which_1.default.sync("start-storybook", { cwd: process.cwd() }); logger_1.default.warn("found 'start-storybook' binary, launching storybook@6 dev server"); return startStorybookPath; } catch (_) { try { return npm_which_1.default.sync("storybook", { cwd: process.cwd() }); } catch (_) { const errorMessage = [ "'storybook' and 'start-storybook' binaries are not found", "Please make sure you are launching Testplane tests from project root directory", ].join("\n"); throw new Error(errorMessage); } } }; const getStorybookDevServerArgs = (port, storybookConfigDir) => [ "dev", "-p", String(port), "-c", String(storybookConfigDir), "--ci", "--quiet", "--disable-telemetry", ]; const getStorybookDevServer = async (testplane, port, storybookConfigDir) => { if (await (0, is_port_busy_1.isPortBusy)(port)) { throw new Error(`Can't launch storybook dev server: port '${port}' is already in use`); } const storybookCliPath = getStorybookCliPath(); const devServer = (0, child_process_1.spawn)(storybookCliPath, getStorybookDevServerArgs(port, storybookConfigDir), { cwd: process.cwd(), }); logger_1.default.log(`Started storybook dev server at http://localhost:${port}`); (0, pipe_with_prefix_1.pipeWithPrefix)(devServer, "[storybook dev server] "); devServer.once("exit", (code, signal) => { if (signal !== "SIGKILL") { const errorMessage = [ "An error occured while launching storybook dev server", `Dev server failed with code '${code}' (signal: ${signal})`, ].join("\n"); testplane.halt(new Error(errorMessage), 5000); } }); return devServer; }; exports.getStorybookDevServer = getStorybookDevServer; //# sourceMappingURL=index.js.map