ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / runner / storage.js
Source Blame History 91 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 storage_exports = {};
f7eb47b… lmata 30 __export(storage_exports, {
f7eb47b… lmata 31 Storage: () => Storage
f7eb47b… lmata 32 });
f7eb47b… lmata 33 module.exports = __toCommonJS(storage_exports);
f7eb47b… lmata 34 var import_fs = __toESM(require("fs"));
f7eb47b… lmata 35 var import_path = __toESM(require("path"));
f7eb47b… lmata 36 var import_utils = require("playwright-core/lib/utils");
f7eb47b… lmata 37 class Storage {
f7eb47b… lmata 38 static {
f7eb47b… lmata 39 this._storages = /* @__PURE__ */ new Map();
f7eb47b… lmata 40 }
f7eb47b… lmata 41 static {
f7eb47b… lmata 42 this._serializeQueue = Promise.resolve();
f7eb47b… lmata 43 }
f7eb47b… lmata 44 static clone(storageFile, outputDir) {
f7eb47b… lmata 45 return Storage._withStorage(storageFile, (storage) => storage._clone(outputDir));
f7eb47b… lmata 46 }
f7eb47b… lmata 47 static upstream(storageFile, storageOutFile) {
f7eb47b… lmata 48 return Storage._withStorage(storageFile, (storage) => storage._upstream(storageOutFile));
f7eb47b… lmata 49 }
f7eb47b… lmata 50 static _withStorage(fileName, runnable) {
f7eb47b… lmata 51 this._serializeQueue = this._serializeQueue.then(() => {
f7eb47b… lmata 52 let storage = Storage._storages.get(fileName);
f7eb47b… lmata 53 if (!storage) {
f7eb47b… lmata 54 storage = new Storage(fileName);
f7eb47b… lmata 55 Storage._storages.set(fileName, storage);
f7eb47b… lmata 56 }
f7eb47b… lmata 57 return runnable(storage);
f7eb47b… lmata 58 });
f7eb47b… lmata 59 return this._serializeQueue;
f7eb47b… lmata 60 }
f7eb47b… lmata 61 constructor(fileName) {
f7eb47b… lmata 62 this._fileName = fileName;
f7eb47b… lmata 63 }
f7eb47b… lmata 64 async _clone(outputDir) {
f7eb47b… lmata 65 const entries = await this._load();
f7eb47b… lmata 66 if (this._lastSnapshotFileName)
f7eb47b… lmata 67 return this._lastSnapshotFileName;
f7eb47b… lmata 68 const snapshotFile = import_path.default.join(outputDir, `pw-storage-${(0, import_utils.createGuid)()}.json`);
f7eb47b… lmata 69 await import_fs.default.promises.writeFile(snapshotFile, JSON.stringify(entries, null, 2)).catch(() => {
f7eb47b… lmata 70 });
f7eb47b… lmata 71 this._lastSnapshotFileName = snapshotFile;
f7eb47b… lmata 72 return snapshotFile;
f7eb47b… lmata 73 }
f7eb47b… lmata 74 async _upstream(storageOutFile) {
f7eb47b… lmata 75 const entries = await this._load();
f7eb47b… lmata 76 const newEntries = await import_fs.default.promises.readFile(storageOutFile, "utf8").then(JSON.parse).catch(() => ({}));
f7eb47b… lmata 77 for (const [key, newValue] of Object.entries(newEntries))
f7eb47b… lmata 78 entries[key] = newValue;
f7eb47b… lmata 79 this._lastSnapshotFileName = void 0;
f7eb47b… lmata 80 await import_fs.default.promises.writeFile(this._fileName, JSON.stringify(entries, null, 2));
f7eb47b… lmata 81 }
f7eb47b… lmata 82 async _load() {
f7eb47b… lmata 83 if (!this._entriesPromise)
f7eb47b… lmata 84 this._entriesPromise = import_fs.default.promises.readFile(this._fileName, "utf8").then(JSON.parse).catch(() => ({}));
f7eb47b… lmata 85 return this._entriesPromise;
f7eb47b… lmata 86 }
f7eb47b… lmata 87 }
f7eb47b… lmata 88 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 89 0 && (module.exports = {
f7eb47b… lmata 90 Storage
f7eb47b… lmata 91 });

Keyboard Shortcuts

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