@storybook/test-runner
Version:
Test runner for Storybook stories
100 lines (93 loc) • 3.22 kB
JavaScript
import ESM_COMPAT_Module from "node:module";
import { fileURLToPath as ESM_COMPAT_fileURLToPath } from 'node:url';
const __filename = ESM_COMPAT_fileURLToPath(import.meta.url);
const require = ESM_COMPAT_Module.createRequire(import.meta.url);
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined") return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
// src/jest-playwright-preset/global.ts
import { setup as setupServer, teardown as teardownServer } from "jest-process-manager";
// src/jest-playwright-preset/utils.ts
import fs from "fs";
import path from "path";
// src/jest-playwright-preset/constants.ts
var CONFIG_ENVIRONMENT_NAME = "jest-playwright";
var CHROMIUM = "chromium";
var SERVER = "SERVER";
var DEFAULT_CONFIG = {
launchType: SERVER,
launchOptions: {},
connectOptions: {},
contextOptions: {},
browsers: [
CHROMIUM
],
exitOnPageError: true,
collectCoverage: false
};
var DEBUG_TIMEOUT = 4 * 24 * 60 * 60 * 1e3;
var PACKAGE_NAME = "@storybook/test-runner";
// src/jest-playwright-preset/utils.ts
var fsPromises = fs.promises;
var PlaywrightError = class PlaywrightError2 extends Error {
static {
__name(this, "PlaywrightError");
}
constructor(message) {
super(formatError(message));
this.name = "PlaywrightError";
}
};
var readConfig = /* @__PURE__ */ __name(async (rootDir = process.cwd(), jestEnvConfig) => {
if (jestEnvConfig) {
return {
...DEFAULT_CONFIG,
...jestEnvConfig
};
}
const { JEST_PLAYWRIGHT_CONFIG, npm_package_type } = process.env;
const fileExtension = npm_package_type === "module" ? "cjs" : "js";
const configPath = JEST_PLAYWRIGHT_CONFIG || `${CONFIG_ENVIRONMENT_NAME}.config.${fileExtension}`;
const absConfigPath = path.resolve(rootDir, configPath);
try {
await fsPromises.access(absConfigPath);
} catch (e) {
if (JEST_PLAYWRIGHT_CONFIG) {
throw new PlaywrightError(`Can't find a root directory while resolving a config file path.
Provided path to resolve: ${configPath}`);
} else {
return DEFAULT_CONFIG;
}
}
const localConfig = await __require(absConfigPath);
if (typeof localConfig === "function") {
const config = await localConfig();
return {
...DEFAULT_CONFIG,
...config
};
}
return {
...DEFAULT_CONFIG,
...localConfig
};
}, "readConfig");
var formatError = /* @__PURE__ */ __name((error) => `${PACKAGE_NAME}: ${error}`, "formatError");
// src/jest-playwright-preset/global.ts
async function teardown(jestConfig) {
const { serverOptions } = await readConfig(jestConfig.rootDir);
if (!jestConfig.watch && !jestConfig.watchAll) {
await teardownServer(serverOptions?.teardown);
}
}
__name(teardown, "teardown");
// src/jest-playwright-entries/teardown.ts
var teardown_default = teardown;
export {
teardown_default as default
};