ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / common / fixtures.js
Source Blame History 302 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __create = Object.create;
f7eb47b… lmata 3 var __defProp = Object.defineProperty;
f7eb47b… lmata 4 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 5 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 6 var __getProtoOf = Object.getPrototypeOf;
f7eb47b… lmata 7 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 8 var __export = (target, all) => {
f7eb47b… lmata 9 for (var name in all)
f7eb47b… lmata 10 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 11 };
f7eb47b… lmata 12 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 13 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 14 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 15 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 17 }
f7eb47b… lmata 18 return to;
f7eb47b… lmata 19 };
f7eb47b… lmata 20 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
f7eb47b… lmata 21 // If the importer is in node compatibility mode or this is not an ESM
f7eb47b… lmata 22 // file that has been converted to a CommonJS file using a Babel-
f7eb47b… lmata 23 // compatible transform (i.e. "__esModule" has not been set), then set
f7eb47b… lmata 24 // "default" to the CommonJS "module.exports" for node compatibility.
f7eb47b… lmata 25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
f7eb47b… lmata 26 mod
f7eb47b… lmata 27 ));
f7eb47b… lmata 28 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 29 var fixtures_exports = {};
f7eb47b… lmata 30 __export(fixtures_exports, {
f7eb47b… lmata 31 FixturePool: () => FixturePool,
f7eb47b… lmata 32 fixtureParameterNames: () => fixtureParameterNames,
f7eb47b… lmata 33 formatPotentiallyInternalLocation: () => formatPotentiallyInternalLocation,
f7eb47b… lmata 34 inheritFixtureNames: () => inheritFixtureNames
f7eb47b… lmata 35 });
f7eb47b… lmata 36 module.exports = __toCommonJS(fixtures_exports);
f7eb47b… lmata 37 var import_crypto = __toESM(require("crypto"));
f7eb47b… lmata 38 var import_util = require("../util");
f7eb47b… lmata 39 const kScopeOrder = ["test", "worker"];
f7eb47b… lmata 40 function isFixtureTuple(value) {
f7eb47b… lmata 41 return Array.isArray(value) && typeof value[1] === "object";
f7eb47b… lmata 42 }
f7eb47b… lmata 43 function isFixtureOption(value) {
f7eb47b… lmata 44 return isFixtureTuple(value) && !!value[1].option;
f7eb47b… lmata 45 }
f7eb47b… lmata 46 class FixturePool {
f7eb47b… lmata 47 constructor(fixturesList, onLoadError, parentPool, disallowWorkerFixtures, optionOverrides) {
f7eb47b… lmata 48 this._registrations = new Map(parentPool ? parentPool._registrations : []);
f7eb47b… lmata 49 this._onLoadError = onLoadError;
f7eb47b… lmata 50 const allOverrides = optionOverrides?.overrides ?? {};
f7eb47b… lmata 51 const overrideKeys = new Set(Object.keys(allOverrides));
f7eb47b… lmata 52 for (const list of fixturesList) {
f7eb47b… lmata 53 this._appendFixtureList(list, !!disallowWorkerFixtures, false);
f7eb47b… lmata 54 const selectedOverrides = {};
f7eb47b… lmata 55 for (const [key, value] of Object.entries(list.fixtures)) {
f7eb47b… lmata 56 if (isFixtureOption(value) && overrideKeys.has(key))
f7eb47b… lmata 57 selectedOverrides[key] = [allOverrides[key], value[1]];
f7eb47b… lmata 58 }
f7eb47b… lmata 59 if (Object.entries(selectedOverrides).length)
f7eb47b… lmata 60 this._appendFixtureList({ fixtures: selectedOverrides, location: optionOverrides.location }, !!disallowWorkerFixtures, true);
f7eb47b… lmata 61 }
f7eb47b… lmata 62 this.digest = this.validate();
f7eb47b… lmata 63 }
f7eb47b… lmata 64 _appendFixtureList(list, disallowWorkerFixtures, isOptionsOverride) {
f7eb47b… lmata 65 const { fixtures, location } = list;
f7eb47b… lmata 66 for (const entry of Object.entries(fixtures)) {
f7eb47b… lmata 67 const name = entry[0];
f7eb47b… lmata 68 let value = entry[1];
f7eb47b… lmata 69 let options;
f7eb47b… lmata 70 if (isFixtureTuple(value)) {
f7eb47b… lmata 71 options = {
f7eb47b… lmata 72 auto: value[1].auto ?? false,
f7eb47b… lmata 73 scope: value[1].scope || "test",
f7eb47b… lmata 74 option: !!value[1].option,
f7eb47b… lmata 75 timeout: value[1].timeout,
f7eb47b… lmata 76 customTitle: value[1].title,
f7eb47b… lmata 77 box: value[1].box
f7eb47b… lmata 78 };
f7eb47b… lmata 79 value = value[0];
f7eb47b… lmata 80 }
f7eb47b… lmata 81 let fn = value;
f7eb47b… lmata 82 const previous = this._registrations.get(name);
f7eb47b… lmata 83 if (previous && options) {
f7eb47b… lmata 84 if (previous.scope !== options.scope) {
f7eb47b… lmata 85 this._addLoadError(`Fixture "${name}" has already been registered as a { scope: '${previous.scope}' } fixture defined in ${(0, import_util.formatLocation)(previous.location)}.`, location);
f7eb47b… lmata 86 continue;
f7eb47b… lmata 87 }
f7eb47b… lmata 88 if (previous.auto !== options.auto) {
f7eb47b… lmata 89 this._addLoadError(`Fixture "${name}" has already been registered as a { auto: '${previous.scope}' } fixture defined in ${(0, import_util.formatLocation)(previous.location)}.`, location);
f7eb47b… lmata 90 continue;
f7eb47b… lmata 91 }
f7eb47b… lmata 92 } else if (previous) {
f7eb47b… lmata 93 options = { auto: previous.auto, scope: previous.scope, option: previous.option, timeout: previous.timeout, customTitle: previous.customTitle };
f7eb47b… lmata 94 } else if (!options) {
f7eb47b… lmata 95 options = { auto: false, scope: "test", option: false, timeout: void 0 };
f7eb47b… lmata 96 }
f7eb47b… lmata 97 if (!kScopeOrder.includes(options.scope)) {
f7eb47b… lmata 98 this._addLoadError(`Fixture "${name}" has unknown { scope: '${options.scope}' }.`, location);
f7eb47b… lmata 99 continue;
f7eb47b… lmata 100 }
f7eb47b… lmata 101 if (options.scope === "worker" && disallowWorkerFixtures) {
f7eb47b… lmata 102 this._addLoadError(`Cannot use({ ${name} }) in a describe group, because it forces a new worker.
f7eb47b… lmata 103 Make it top-level in the test file or put in the configuration file.`, location);
f7eb47b… lmata 104 continue;
f7eb47b… lmata 105 }
f7eb47b… lmata 106 if (fn === void 0 && options.option && previous) {
f7eb47b… lmata 107 let original = previous;
f7eb47b… lmata 108 while (!original.optionOverride && original.super)
f7eb47b… lmata 109 original = original.super;
f7eb47b… lmata 110 fn = original.fn;
f7eb47b… lmata 111 }
f7eb47b… lmata 112 const deps = fixtureParameterNames(fn, location, (e) => this._onLoadError(e));
f7eb47b… lmata 113 const registration = { id: "", name, location, scope: options.scope, fn, auto: options.auto, option: options.option, timeout: options.timeout, customTitle: options.customTitle, box: options.box, deps, super: previous, optionOverride: isOptionsOverride };
f7eb47b… lmata 114 registrationId(registration);
f7eb47b… lmata 115 this._registrations.set(name, registration);
f7eb47b… lmata 116 }
f7eb47b… lmata 117 }
f7eb47b… lmata 118 validate() {
f7eb47b… lmata 119 const markers = /* @__PURE__ */ new Map();
f7eb47b… lmata 120 const stack = [];
f7eb47b… lmata 121 let hasDependencyErrors = false;
f7eb47b… lmata 122 const addDependencyError = (message, location) => {
f7eb47b… lmata 123 hasDependencyErrors = true;
f7eb47b… lmata 124 this._addLoadError(message, location);
f7eb47b… lmata 125 };
f7eb47b… lmata 126 const visit = (registration, boxedOnly) => {
f7eb47b… lmata 127 markers.set(registration, "visiting");
f7eb47b… lmata 128 stack.push(registration);
f7eb47b… lmata 129 for (const name of registration.deps) {
f7eb47b… lmata 130 const dep = this.resolve(name, registration);
f7eb47b… lmata 131 if (!dep) {
f7eb47b… lmata 132 if (name === registration.name)
f7eb47b… lmata 133 addDependencyError(`Fixture "${registration.name}" references itself, but does not have a base implementation.`, registration.location);
f7eb47b… lmata 134 else
f7eb47b… lmata 135 addDependencyError(`Fixture "${registration.name}" has unknown parameter "${name}".`, registration.location);
f7eb47b… lmata 136 continue;
f7eb47b… lmata 137 }
f7eb47b… lmata 138 if (kScopeOrder.indexOf(registration.scope) > kScopeOrder.indexOf(dep.scope)) {
f7eb47b… lmata 139 addDependencyError(`${registration.scope} fixture "${registration.name}" cannot depend on a ${dep.scope} fixture "${name}" defined in ${formatPotentiallyInternalLocation(dep.location)}.`, registration.location);
f7eb47b… lmata 140 continue;
f7eb47b… lmata 141 }
f7eb47b… lmata 142 if (!markers.has(dep)) {
f7eb47b… lmata 143 visit(dep, boxedOnly);
f7eb47b… lmata 144 } else if (markers.get(dep) === "visiting") {
f7eb47b… lmata 145 const index = stack.indexOf(dep);
f7eb47b… lmata 146 const allRegs = stack.slice(index, stack.length);
f7eb47b… lmata 147 const filteredRegs = allRegs.filter((r) => !r.box);
f7eb47b… lmata 148 const regs = boxedOnly ? filteredRegs : allRegs;
f7eb47b… lmata 149 const names2 = regs.map((r) => `"${r.name}"`);
f7eb47b… lmata 150 addDependencyError(`Fixtures ${names2.join(" -> ")} -> "${dep.name}" form a dependency cycle: ${regs.map((r) => formatPotentiallyInternalLocation(r.location)).join(" -> ")} -> ${formatPotentiallyInternalLocation(dep.location)}`, dep.location);
f7eb47b… lmata 151 continue;
f7eb47b… lmata 152 }
f7eb47b… lmata 153 }
f7eb47b… lmata 154 markers.set(registration, "visited");
f7eb47b… lmata 155 stack.pop();
f7eb47b… lmata 156 };
f7eb47b… lmata 157 const names = Array.from(this._registrations.keys()).sort();
f7eb47b… lmata 158 for (const name of names) {
f7eb47b… lmata 159 const registration = this._registrations.get(name);
f7eb47b… lmata 160 if (!registration.box)
f7eb47b… lmata 161 visit(registration, true);
f7eb47b… lmata 162 }
f7eb47b… lmata 163 if (!hasDependencyErrors) {
f7eb47b… lmata 164 for (const name of names) {
f7eb47b… lmata 165 const registration = this._registrations.get(name);
f7eb47b… lmata 166 if (registration.box)
f7eb47b… lmata 167 visit(registration, false);
f7eb47b… lmata 168 }
f7eb47b… lmata 169 }
f7eb47b… lmata 170 const hash = import_crypto.default.createHash("sha1");
f7eb47b… lmata 171 for (const name of names) {
f7eb47b… lmata 172 const registration = this._registrations.get(name);
f7eb47b… lmata 173 if (registration.scope === "worker")
f7eb47b… lmata 174 hash.update(registration.id + ";");
f7eb47b… lmata 175 }
f7eb47b… lmata 176 return hash.digest("hex");
f7eb47b… lmata 177 }
f7eb47b… lmata 178 validateFunction(fn, prefix, location) {
f7eb47b… lmata 179 for (const name of fixtureParameterNames(fn, location, (e) => this._onLoadError(e))) {
f7eb47b… lmata 180 const registration = this._registrations.get(name);
f7eb47b… lmata 181 if (!registration)
f7eb47b… lmata 182 this._addLoadError(`${prefix} has unknown parameter "${name}".`, location);
f7eb47b… lmata 183 }
f7eb47b… lmata 184 }
f7eb47b… lmata 185 resolve(name, forFixture) {
f7eb47b… lmata 186 if (name === forFixture?.name)
f7eb47b… lmata 187 return forFixture.super;
f7eb47b… lmata 188 return this._registrations.get(name);
f7eb47b… lmata 189 }
f7eb47b… lmata 190 autoFixtures() {
f7eb47b… lmata 191 return [...this._registrations.values()].filter((r) => r.auto !== false);
f7eb47b… lmata 192 }
f7eb47b… lmata 193 _addLoadError(message, location) {
f7eb47b… lmata 194 this._onLoadError({ message, location });
f7eb47b… lmata 195 }
f7eb47b… lmata 196 }
f7eb47b… lmata 197 const signatureSymbol = Symbol("signature");
f7eb47b… lmata 198 function formatPotentiallyInternalLocation(location) {
f7eb47b… lmata 199 const isUserFixture = location && (0, import_util.filterStackFile)(location.file);
f7eb47b… lmata 200 return isUserFixture ? (0, import_util.formatLocation)(location) : "<builtin>";
f7eb47b… lmata 201 }
f7eb47b… lmata 202 function fixtureParameterNames(fn, location, onError) {
f7eb47b… lmata 203 if (typeof fn !== "function")
f7eb47b… lmata 204 return [];
f7eb47b… lmata 205 if (!fn[signatureSymbol])
f7eb47b… lmata 206 fn[signatureSymbol] = innerFixtureParameterNames(fn, location, onError);
f7eb47b… lmata 207 return fn[signatureSymbol];
f7eb47b… lmata 208 }
f7eb47b… lmata 209 function inheritFixtureNames(from, to) {
f7eb47b… lmata 210 to[signatureSymbol] = from[signatureSymbol];
f7eb47b… lmata 211 }
f7eb47b… lmata 212 function innerFixtureParameterNames(fn, location, onError) {
f7eb47b… lmata 213 const text = filterOutComments(fn.toString());
f7eb47b… lmata 214 const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
f7eb47b… lmata 215 if (!match)
f7eb47b… lmata 216 return [];
f7eb47b… lmata 217 const trimmedParams = match[1].trim();
f7eb47b… lmata 218 if (!trimmedParams)
f7eb47b… lmata 219 return [];
f7eb47b… lmata 220 const [firstParam] = splitByComma(trimmedParams);
f7eb47b… lmata 221 if (firstParam[0] !== "{" || firstParam[firstParam.length - 1] !== "}") {
f7eb47b… lmata 222 onError({ message: "First argument must use the object destructuring pattern: " + firstParam, location });
f7eb47b… lmata 223 return [];
f7eb47b… lmata 224 }
f7eb47b… lmata 225 const props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map((prop) => {
f7eb47b… lmata 226 const colon = prop.indexOf(":");
f7eb47b… lmata 227 return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
f7eb47b… lmata 228 });
f7eb47b… lmata 229 const restProperty = props.find((prop) => prop.startsWith("..."));
f7eb47b… lmata 230 if (restProperty) {
f7eb47b… lmata 231 onError({ message: `Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma.`, location });
f7eb47b… lmata 232 return [];
f7eb47b… lmata 233 }
f7eb47b… lmata 234 return props;
f7eb47b… lmata 235 }
f7eb47b… lmata 236 function filterOutComments(s) {
f7eb47b… lmata 237 const result = [];
f7eb47b… lmata 238 let commentState = "none";
f7eb47b… lmata 239 for (let i = 0; i < s.length; ++i) {
f7eb47b… lmata 240 if (commentState === "singleline") {
f7eb47b… lmata 241 if (s[i] === "\n")
f7eb47b… lmata 242 commentState = "none";
f7eb47b… lmata 243 } else if (commentState === "multiline") {
f7eb47b… lmata 244 if (s[i - 1] === "*" && s[i] === "/")
f7eb47b… lmata 245 commentState = "none";
f7eb47b… lmata 246 } else if (commentState === "none") {
f7eb47b… lmata 247 if (s[i] === "/" && s[i + 1] === "/") {
f7eb47b… lmata 248 commentState = "singleline";
f7eb47b… lmata 249 } else if (s[i] === "/" && s[i + 1] === "*") {
f7eb47b… lmata 250 commentState = "multiline";
f7eb47b… lmata 251 i += 2;
f7eb47b… lmata 252 } else {
f7eb47b… lmata 253 result.push(s[i]);
f7eb47b… lmata 254 }
f7eb47b… lmata 255 }
f7eb47b… lmata 256 }
f7eb47b… lmata 257 return result.join("");
f7eb47b… lmata 258 }
f7eb47b… lmata 259 function splitByComma(s) {
f7eb47b… lmata 260 const result = [];
f7eb47b… lmata 261 const stack = [];
f7eb47b… lmata 262 let start = 0;
f7eb47b… lmata 263 for (let i = 0; i < s.length; i++) {
f7eb47b… lmata 264 if (s[i] === "{" || s[i] === "[") {
f7eb47b… lmata 265 stack.push(s[i] === "{" ? "}" : "]");
f7eb47b… lmata 266 } else if (s[i] === stack[stack.length - 1]) {
f7eb47b… lmata 267 stack.pop();
f7eb47b… lmata 268 } else if (!stack.length && s[i] === ",") {
f7eb47b… lmata 269 const token = s.substring(start, i).trim();
f7eb47b… lmata 270 if (token)
f7eb47b… lmata 271 result.push(token);
f7eb47b… lmata 272 start = i + 1;
f7eb47b… lmata 273 }
f7eb47b… lmata 274 }
f7eb47b… lmata 275 const lastToken = s.substring(start).trim();
f7eb47b… lmata 276 if (lastToken)
f7eb47b… lmata 277 result.push(lastToken);
f7eb47b… lmata 278 return result;
f7eb47b… lmata 279 }
f7eb47b… lmata 280 const registrationIdMap = /* @__PURE__ */ new Map();
f7eb47b… lmata 281 let lastId = 0;
f7eb47b… lmata 282 function registrationId(registration) {
f7eb47b… lmata 283 if (registration.id)
f7eb47b… lmata 284 return registration.id;
f7eb47b… lmata 285 const key = registration.name + "@@@" + (registration.super ? registrationId(registration.super) : "");
f7eb47b… lmata 286 let map = registrationIdMap.get(key);
f7eb47b… lmata 287 if (!map) {
f7eb47b… lmata 288 map = /* @__PURE__ */ new Map();
f7eb47b… lmata 289 registrationIdMap.set(key, map);
f7eb47b… lmata 290 }
f7eb47b… lmata 291 if (!map.has(registration.fn))
f7eb47b… lmata 292 map.set(registration.fn, String(lastId++));
f7eb47b… lmata 293 registration.id = map.get(registration.fn);
f7eb47b… lmata 294 return registration.id;
f7eb47b… lmata 295 }
f7eb47b… lmata 296 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 297 0 && (module.exports = {
f7eb47b… lmata 298 FixturePool,
f7eb47b… lmata 299 fixtureParameterNames,
f7eb47b… lmata 300 formatPotentiallyInternalLocation,
f7eb47b… lmata 301 inheritFixtureNames
f7eb47b… lmata 302 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button