ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / runner / storage.js
Blame History Raw 92 lines
1
"use strict";
2
var __create = Object.create;
3
var __defProp = Object.defineProperty;
4
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
var __getOwnPropNames = Object.getOwnPropertyNames;
6
var __getProtoOf = Object.getPrototypeOf;
7
var __hasOwnProp = Object.prototype.hasOwnProperty;
8
var __export = (target, all) => {
9
for (var name in all)
10
__defProp(target, name, { get: all[name], enumerable: true });
11
};
12
var __copyProps = (to, from, except, desc) => {
13
if (from && typeof from === "object" || typeof from === "function") {
14
for (let key of __getOwnPropNames(from))
15
if (!__hasOwnProp.call(to, key) && key !== except)
16
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
}
18
return to;
19
};
20
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
// If the importer is in node compatibility mode or this is not an ESM
22
// file that has been converted to a CommonJS file using a Babel-
23
// compatible transform (i.e. "__esModule" has not been set), then set
24
// "default" to the CommonJS "module.exports" for node compatibility.
25
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
mod
27
));
28
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
var storage_exports = {};
30
__export(storage_exports, {
31
Storage: () => Storage
32
});
33
module.exports = __toCommonJS(storage_exports);
34
var import_fs = __toESM(require("fs"));
35
var import_path = __toESM(require("path"));
36
var import_utils = require("playwright-core/lib/utils");
37
class Storage {
38
static {
39
this._storages = /* @__PURE__ */ new Map();
40
}
41
static {
42
this._serializeQueue = Promise.resolve();
43
}
44
static clone(storageFile, outputDir) {
45
return Storage._withStorage(storageFile, (storage) => storage._clone(outputDir));
46
}
47
static upstream(storageFile, storageOutFile) {
48
return Storage._withStorage(storageFile, (storage) => storage._upstream(storageOutFile));
49
}
50
static _withStorage(fileName, runnable) {
51
this._serializeQueue = this._serializeQueue.then(() => {
52
let storage = Storage._storages.get(fileName);
53
if (!storage) {
54
storage = new Storage(fileName);
55
Storage._storages.set(fileName, storage);
56
}
57
return runnable(storage);
58
});
59
return this._serializeQueue;
60
}
61
constructor(fileName) {
62
this._fileName = fileName;
63
}
64
async _clone(outputDir) {
65
const entries = await this._load();
66
if (this._lastSnapshotFileName)
67
return this._lastSnapshotFileName;
68
const snapshotFile = import_path.default.join(outputDir, `pw-storage-${(0, import_utils.createGuid)()}.json`);
69
await import_fs.default.promises.writeFile(snapshotFile, JSON.stringify(entries, null, 2)).catch(() => {
70
});
71
this._lastSnapshotFileName = snapshotFile;
72
return snapshotFile;
73
}
74
async _upstream(storageOutFile) {
75
const entries = await this._load();
76
const newEntries = await import_fs.default.promises.readFile(storageOutFile, "utf8").then(JSON.parse).catch(() => ({}));
77
for (const [key, newValue] of Object.entries(newEntries))
78
entries[key] = newValue;
79
this._lastSnapshotFileName = void 0;
80
await import_fs.default.promises.writeFile(this._fileName, JSON.stringify(entries, null, 2));
81
}
82
async _load() {
83
if (!this._entriesPromise)
84
this._entriesPromise = import_fs.default.promises.readFile(this._fileName, "utf8").then(JSON.parse).catch(() => ({}));
85
return this._entriesPromise;
86
}
87
}
88
// Annotate the CommonJS export names for ESM import in node:
89
0 && (module.exports = {
90
Storage
91
});
92

Keyboard Shortcuts

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