@storybook/test-runner
Version:
Test runner for Storybook stories
141 lines (136 loc) • 4.41 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 });
// 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 DEBUG_TIMEOUT = 4 * 24 * 60 * 60 * 1e3;
// src/jest-playwright-preset/utils.ts
var fsPromises = fs.promises;
var isObject = /* @__PURE__ */ __name((item) => {
return item && typeof item === "object" && !Array.isArray(item);
}, "isObject");
var deepMerge = /* @__PURE__ */ __name((target, source) => {
let output = {
...target
};
const keys = Object.keys(source);
if (isObject(target) && isObject(source)) {
keys.forEach((key) => {
if (Array.isArray(source[key]) && Array.isArray(target[key])) {
output = {
...output,
[key]: [
...source[key],
...target[key]
]
};
} else if (isObject(source[key])) {
if (!(key in target)) {
output = {
...output,
[key]: source[key]
};
} else {
output[key] = deepMerge(target[key], source[key]);
}
} else {
output = {
...output,
[key]: source[key]
};
}
});
}
return output;
}, "deepMerge");
var getSkipFlag = /* @__PURE__ */ __name((skipOptions, browserName2, deviceName2) => {
const { browsers, devices } = skipOptions;
const isBrowserIncluded = browsers.includes(browserName2);
if (!devices) {
return isBrowserIncluded;
} else {
if (devices instanceof RegExp) {
return isBrowserIncluded && devices.test(deviceName2);
}
return isBrowserIncluded && devices.includes(deviceName2);
}
}, "getSkipFlag");
// src/jest-playwright-entries/extends.ts
var DEBUG_OPTIONS = {
launchOptions: {
headless: false,
devtools: true
}
};
var runDebugTest = /* @__PURE__ */ __name((jestTestType, ...args) => {
const isConfigProvided = typeof args[0] === "object";
const lastArg = args[args.length - 1];
const timer = typeof lastArg === "number" ? lastArg : DEBUG_TIMEOUT;
let options = DEBUG_OPTIONS;
if (isConfigProvided) {
options = deepMerge(DEBUG_OPTIONS, args[0]);
}
jestTestType(args[isConfigProvided ? 1 : 0], async () => {
const envArgs = await jestPlaywright.configSeparateEnv(options, true);
try {
await args[isConfigProvided ? 2 : 1](envArgs);
} finally {
await envArgs.browser.close();
}
}, timer);
}, "runDebugTest");
it.jestPlaywrightDebug = (...args) => {
runDebugTest(it, ...args);
};
it.jestPlaywrightDebug.only = (...args) => {
runDebugTest(it.only, ...args);
};
it.jestPlaywrightDebug.skip = (...args) => {
runDebugTest(it.skip, ...args);
};
var runConfigTest = /* @__PURE__ */ __name((jestTypeTest, playwrightOptions, ...args) => {
const lastArg = args[args.length - 1];
const timer = typeof lastArg === "number" ? lastArg : global[CONFIG_ENVIRONMENT_NAME].testTimeout;
jestTypeTest(args[0], async () => {
const envArgs = await jestPlaywright.configSeparateEnv(playwrightOptions);
try {
await args[1](envArgs);
} finally {
await envArgs.browser.close();
}
}, timer);
}, "runConfigTest");
it.jestPlaywrightConfig = (playwrightOptions, ...args) => {
runConfigTest(it, playwrightOptions, ...args);
};
it.jestPlaywrightConfig.only = (...args) => {
runConfigTest(it.only, ...args);
};
it.jestPlaywrightConfig.skip = (...args) => {
runConfigTest(it.skip, ...args);
};
var customSkip = /* @__PURE__ */ __name((skipOption, type, ...args) => {
const skipFlag = getSkipFlag(skipOption, browserName, deviceName);
if (skipFlag) {
global[type].skip(...args);
} else {
global[type](...args);
}
}, "customSkip");
it.jestPlaywrightSkip = (skipOption, ...args) => {
customSkip(skipOption, "it", ...args);
};
describe.jestPlaywrightSkip = (skipOption, ...args) => {
customSkip(skipOption, "describe", ...args);
};
beforeEach(async () => {
if (global[CONFIG_ENVIRONMENT_NAME].resetContextPerTest) {
await jestPlaywright.resetContext();
}
});