ScuttleBot

Source Blame History 321 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __defProp = Object.defineProperty;
f7eb47b… lmata 3 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 4 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 5 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 6 var __export = (target, all) => {
f7eb47b… lmata 7 for (var name in all)
f7eb47b… lmata 8 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 9 };
f7eb47b… lmata 10 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 11 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 12 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 13 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 15 }
f7eb47b… lmata 16 return to;
f7eb47b… lmata 17 };
f7eb47b… lmata 18 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 19 var test_exports = {};
f7eb47b… lmata 20 __export(test_exports, {
f7eb47b… lmata 21 Suite: () => Suite,
f7eb47b… lmata 22 TestCase: () => TestCase
f7eb47b… lmata 23 });
f7eb47b… lmata 24 module.exports = __toCommonJS(test_exports);
f7eb47b… lmata 25 var import_testType = require("./testType");
f7eb47b… lmata 26 var import_teleReceiver = require("../isomorphic/teleReceiver");
f7eb47b… lmata 27 class Base {
f7eb47b… lmata 28 constructor(title) {
f7eb47b… lmata 29 this._only = false;
f7eb47b… lmata 30 this._requireFile = "";
f7eb47b… lmata 31 this.title = title;
f7eb47b… lmata 32 }
f7eb47b… lmata 33 }
f7eb47b… lmata 34 class Suite extends Base {
f7eb47b… lmata 35 constructor(title, type) {
f7eb47b… lmata 36 super(title);
f7eb47b… lmata 37 this._use = [];
f7eb47b… lmata 38 this._entries = [];
f7eb47b… lmata 39 this._hooks = [];
f7eb47b… lmata 40 // Annotations known statically before running the test, e.g. `test.describe.skip()` or `test.describe({ annotation }, body)`.
f7eb47b… lmata 41 this._staticAnnotations = [];
f7eb47b… lmata 42 // Explicitly declared tags that are not a part of the title.
f7eb47b… lmata 43 this._tags = [];
f7eb47b… lmata 44 this._modifiers = [];
f7eb47b… lmata 45 this._parallelMode = "none";
f7eb47b… lmata 46 this._type = type;
f7eb47b… lmata 47 }
f7eb47b… lmata 48 get type() {
f7eb47b… lmata 49 return this._type;
f7eb47b… lmata 50 }
f7eb47b… lmata 51 entries() {
f7eb47b… lmata 52 return this._entries;
f7eb47b… lmata 53 }
f7eb47b… lmata 54 get suites() {
f7eb47b… lmata 55 return this._entries.filter((entry) => entry instanceof Suite);
f7eb47b… lmata 56 }
f7eb47b… lmata 57 get tests() {
f7eb47b… lmata 58 return this._entries.filter((entry) => entry instanceof TestCase);
f7eb47b… lmata 59 }
f7eb47b… lmata 60 _addTest(test) {
f7eb47b… lmata 61 test.parent = this;
f7eb47b… lmata 62 this._entries.push(test);
f7eb47b… lmata 63 }
f7eb47b… lmata 64 _addSuite(suite) {
f7eb47b… lmata 65 suite.parent = this;
f7eb47b… lmata 66 this._entries.push(suite);
f7eb47b… lmata 67 }
f7eb47b… lmata 68 _prependSuite(suite) {
f7eb47b… lmata 69 suite.parent = this;
f7eb47b… lmata 70 this._entries.unshift(suite);
f7eb47b… lmata 71 }
f7eb47b… lmata 72 allTests() {
f7eb47b… lmata 73 const result = [];
f7eb47b… lmata 74 const visit = (suite) => {
f7eb47b… lmata 75 for (const entry of suite._entries) {
f7eb47b… lmata 76 if (entry instanceof Suite)
f7eb47b… lmata 77 visit(entry);
f7eb47b… lmata 78 else
f7eb47b… lmata 79 result.push(entry);
f7eb47b… lmata 80 }
f7eb47b… lmata 81 };
f7eb47b… lmata 82 visit(this);
f7eb47b… lmata 83 return result;
f7eb47b… lmata 84 }
f7eb47b… lmata 85 _hasTests() {
f7eb47b… lmata 86 let result = false;
f7eb47b… lmata 87 const visit = (suite) => {
f7eb47b… lmata 88 for (const entry of suite._entries) {
f7eb47b… lmata 89 if (result)
f7eb47b… lmata 90 return;
f7eb47b… lmata 91 if (entry instanceof Suite)
f7eb47b… lmata 92 visit(entry);
f7eb47b… lmata 93 else
f7eb47b… lmata 94 result = true;
f7eb47b… lmata 95 }
f7eb47b… lmata 96 };
f7eb47b… lmata 97 visit(this);
f7eb47b… lmata 98 return result;
f7eb47b… lmata 99 }
f7eb47b… lmata 100 titlePath() {
f7eb47b… lmata 101 const titlePath = this.parent ? this.parent.titlePath() : [];
f7eb47b… lmata 102 if (this.title || this._type !== "describe")
f7eb47b… lmata 103 titlePath.push(this.title);
f7eb47b… lmata 104 return titlePath;
f7eb47b… lmata 105 }
f7eb47b… lmata 106 _collectGrepTitlePath(path) {
f7eb47b… lmata 107 if (this.parent)
f7eb47b… lmata 108 this.parent._collectGrepTitlePath(path);
f7eb47b… lmata 109 if (this.title || this._type !== "describe")
f7eb47b… lmata 110 path.push(this.title);
f7eb47b… lmata 111 path.push(...this._tags);
f7eb47b… lmata 112 }
f7eb47b… lmata 113 _getOnlyItems() {
f7eb47b… lmata 114 const items = [];
f7eb47b… lmata 115 if (this._only)
f7eb47b… lmata 116 items.push(this);
f7eb47b… lmata 117 for (const suite of this.suites)
f7eb47b… lmata 118 items.push(...suite._getOnlyItems());
f7eb47b… lmata 119 items.push(...this.tests.filter((test) => test._only));
f7eb47b… lmata 120 return items;
f7eb47b… lmata 121 }
f7eb47b… lmata 122 _deepClone() {
f7eb47b… lmata 123 const suite = this._clone();
f7eb47b… lmata 124 for (const entry of this._entries) {
f7eb47b… lmata 125 if (entry instanceof Suite)
f7eb47b… lmata 126 suite._addSuite(entry._deepClone());
f7eb47b… lmata 127 else
f7eb47b… lmata 128 suite._addTest(entry._clone());
f7eb47b… lmata 129 }
f7eb47b… lmata 130 return suite;
f7eb47b… lmata 131 }
f7eb47b… lmata 132 _deepSerialize() {
f7eb47b… lmata 133 const suite = this._serialize();
f7eb47b… lmata 134 suite.entries = [];
f7eb47b… lmata 135 for (const entry of this._entries) {
f7eb47b… lmata 136 if (entry instanceof Suite)
f7eb47b… lmata 137 suite.entries.push(entry._deepSerialize());
f7eb47b… lmata 138 else
f7eb47b… lmata 139 suite.entries.push(entry._serialize());
f7eb47b… lmata 140 }
f7eb47b… lmata 141 return suite;
f7eb47b… lmata 142 }
f7eb47b… lmata 143 static _deepParse(data) {
f7eb47b… lmata 144 const suite = Suite._parse(data);
f7eb47b… lmata 145 for (const entry of data.entries) {
f7eb47b… lmata 146 if (entry.kind === "suite")
f7eb47b… lmata 147 suite._addSuite(Suite._deepParse(entry));
f7eb47b… lmata 148 else
f7eb47b… lmata 149 suite._addTest(TestCase._parse(entry));
f7eb47b… lmata 150 }
f7eb47b… lmata 151 return suite;
f7eb47b… lmata 152 }
f7eb47b… lmata 153 forEachTest(visitor) {
f7eb47b… lmata 154 for (const entry of this._entries) {
f7eb47b… lmata 155 if (entry instanceof Suite)
f7eb47b… lmata 156 entry.forEachTest(visitor);
f7eb47b… lmata 157 else
f7eb47b… lmata 158 visitor(entry, this);
f7eb47b… lmata 159 }
f7eb47b… lmata 160 }
f7eb47b… lmata 161 _serialize() {
f7eb47b… lmata 162 return {
f7eb47b… lmata 163 kind: "suite",
f7eb47b… lmata 164 title: this.title,
f7eb47b… lmata 165 type: this._type,
f7eb47b… lmata 166 location: this.location,
f7eb47b… lmata 167 only: this._only,
f7eb47b… lmata 168 requireFile: this._requireFile,
f7eb47b… lmata 169 timeout: this._timeout,
f7eb47b… lmata 170 retries: this._retries,
f7eb47b… lmata 171 staticAnnotations: this._staticAnnotations.slice(),
f7eb47b… lmata 172 tags: this._tags.slice(),
f7eb47b… lmata 173 modifiers: this._modifiers.slice(),
f7eb47b… lmata 174 parallelMode: this._parallelMode,
f7eb47b… lmata 175 hooks: this._hooks.map((h) => ({ type: h.type, location: h.location, title: h.title })),
f7eb47b… lmata 176 fileId: this._fileId
f7eb47b… lmata 177 };
f7eb47b… lmata 178 }
f7eb47b… lmata 179 static _parse(data) {
f7eb47b… lmata 180 const suite = new Suite(data.title, data.type);
f7eb47b… lmata 181 suite.location = data.location;
f7eb47b… lmata 182 suite._only = data.only;
f7eb47b… lmata 183 suite._requireFile = data.requireFile;
f7eb47b… lmata 184 suite._timeout = data.timeout;
f7eb47b… lmata 185 suite._retries = data.retries;
f7eb47b… lmata 186 suite._staticAnnotations = data.staticAnnotations;
f7eb47b… lmata 187 suite._tags = data.tags;
f7eb47b… lmata 188 suite._modifiers = data.modifiers;
f7eb47b… lmata 189 suite._parallelMode = data.parallelMode;
f7eb47b… lmata 190 suite._hooks = data.hooks.map((h) => ({ type: h.type, location: h.location, title: h.title, fn: () => {
f7eb47b… lmata 191 } }));
f7eb47b… lmata 192 suite._fileId = data.fileId;
f7eb47b… lmata 193 return suite;
f7eb47b… lmata 194 }
f7eb47b… lmata 195 _clone() {
f7eb47b… lmata 196 const data = this._serialize();
f7eb47b… lmata 197 const suite = Suite._parse(data);
f7eb47b… lmata 198 suite._use = this._use.slice();
f7eb47b… lmata 199 suite._hooks = this._hooks.slice();
f7eb47b… lmata 200 suite._fullProject = this._fullProject;
f7eb47b… lmata 201 return suite;
f7eb47b… lmata 202 }
f7eb47b… lmata 203 project() {
f7eb47b… lmata 204 return this._fullProject?.project || this.parent?.project();
f7eb47b… lmata 205 }
f7eb47b… lmata 206 }
f7eb47b… lmata 207 class TestCase extends Base {
f7eb47b… lmata 208 constructor(title, fn, testType, location) {
f7eb47b… lmata 209 super(title);
f7eb47b… lmata 210 this.results = [];
f7eb47b… lmata 211 this.type = "test";
f7eb47b… lmata 212 this.expectedStatus = "passed";
f7eb47b… lmata 213 this.timeout = 0;
f7eb47b… lmata 214 this.annotations = [];
f7eb47b… lmata 215 this.retries = 0;
f7eb47b… lmata 216 this.repeatEachIndex = 0;
f7eb47b… lmata 217 this.id = "";
f7eb47b… lmata 218 this._poolDigest = "";
f7eb47b… lmata 219 this._workerHash = "";
f7eb47b… lmata 220 this._projectId = "";
f7eb47b… lmata 221 // Explicitly declared tags that are not a part of the title.
f7eb47b… lmata 222 this._tags = [];
f7eb47b… lmata 223 this.fn = fn;
f7eb47b… lmata 224 this._testType = testType;
f7eb47b… lmata 225 this.location = location;
f7eb47b… lmata 226 }
f7eb47b… lmata 227 titlePath() {
f7eb47b… lmata 228 const titlePath = this.parent ? this.parent.titlePath() : [];
f7eb47b… lmata 229 titlePath.push(this.title);
f7eb47b… lmata 230 return titlePath;
f7eb47b… lmata 231 }
f7eb47b… lmata 232 outcome() {
f7eb47b… lmata 233 return (0, import_teleReceiver.computeTestCaseOutcome)(this);
f7eb47b… lmata 234 }
f7eb47b… lmata 235 ok() {
f7eb47b… lmata 236 const status = this.outcome();
f7eb47b… lmata 237 return status === "expected" || status === "flaky" || status === "skipped";
f7eb47b… lmata 238 }
f7eb47b… lmata 239 get tags() {
f7eb47b… lmata 240 const titleTags = this._grepBaseTitlePath().join(" ").match(/@[\S]+/g) || [];
f7eb47b… lmata 241 return [
f7eb47b… lmata 242 ...titleTags,
f7eb47b… lmata 243 ...this._tags
f7eb47b… lmata 244 ];
f7eb47b… lmata 245 }
f7eb47b… lmata 246 _serialize() {
f7eb47b… lmata 247 return {
f7eb47b… lmata 248 kind: "test",
f7eb47b… lmata 249 id: this.id,
f7eb47b… lmata 250 title: this.title,
f7eb47b… lmata 251 retries: this.retries,
f7eb47b… lmata 252 timeout: this.timeout,
f7eb47b… lmata 253 expectedStatus: this.expectedStatus,
f7eb47b… lmata 254 location: this.location,
f7eb47b… lmata 255 only: this._only,
f7eb47b… lmata 256 requireFile: this._requireFile,
f7eb47b… lmata 257 poolDigest: this._poolDigest,
f7eb47b… lmata 258 workerHash: this._workerHash,
f7eb47b… lmata 259 annotations: this.annotations.slice(),
f7eb47b… lmata 260 tags: this._tags.slice(),
f7eb47b… lmata 261 projectId: this._projectId
f7eb47b… lmata 262 };
f7eb47b… lmata 263 }
f7eb47b… lmata 264 static _parse(data) {
f7eb47b… lmata 265 const test = new TestCase(data.title, () => {
f7eb47b… lmata 266 }, import_testType.rootTestType, data.location);
f7eb47b… lmata 267 test.id = data.id;
f7eb47b… lmata 268 test.retries = data.retries;
f7eb47b… lmata 269 test.timeout = data.timeout;
f7eb47b… lmata 270 test.expectedStatus = data.expectedStatus;
f7eb47b… lmata 271 test._only = data.only;
f7eb47b… lmata 272 test._requireFile = data.requireFile;
f7eb47b… lmata 273 test._poolDigest = data.poolDigest;
f7eb47b… lmata 274 test._workerHash = data.workerHash;
f7eb47b… lmata 275 test.annotations = data.annotations;
f7eb47b… lmata 276 test._tags = data.tags;
f7eb47b… lmata 277 test._projectId = data.projectId;
f7eb47b… lmata 278 return test;
f7eb47b… lmata 279 }
f7eb47b… lmata 280 _clone() {
f7eb47b… lmata 281 const data = this._serialize();
f7eb47b… lmata 282 const test = TestCase._parse(data);
f7eb47b… lmata 283 test._testType = this._testType;
f7eb47b… lmata 284 test.fn = this.fn;
f7eb47b… lmata 285 return test;
f7eb47b… lmata 286 }
f7eb47b… lmata 287 _appendTestResult() {
f7eb47b… lmata 288 const result = {
f7eb47b… lmata 289 retry: this.results.length,
f7eb47b… lmata 290 parallelIndex: -1,
f7eb47b… lmata 291 workerIndex: -1,
f7eb47b… lmata 292 duration: 0,
f7eb47b… lmata 293 startTime: /* @__PURE__ */ new Date(),
f7eb47b… lmata 294 stdout: [],
f7eb47b… lmata 295 stderr: [],
f7eb47b… lmata 296 attachments: [],
f7eb47b… lmata 297 status: "skipped",
f7eb47b… lmata 298 steps: [],
f7eb47b… lmata 299 errors: [],
f7eb47b… lmata 300 annotations: []
f7eb47b… lmata 301 };
f7eb47b… lmata 302 this.results.push(result);
f7eb47b… lmata 303 return result;
f7eb47b… lmata 304 }
f7eb47b… lmata 305 _grepBaseTitlePath() {
f7eb47b… lmata 306 const path = [];
f7eb47b… lmata 307 this.parent._collectGrepTitlePath(path);
f7eb47b… lmata 308 path.push(this.title);
f7eb47b… lmata 309 return path;
f7eb47b… lmata 310 }
f7eb47b… lmata 311 _grepTitleWithTags() {
f7eb47b… lmata 312 const path = this._grepBaseTitlePath();
f7eb47b… lmata 313 path.push(...this._tags);
f7eb47b… lmata 314 return path.join(" ");
f7eb47b… lmata 315 }
f7eb47b… lmata 316 }
f7eb47b… lmata 317 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 318 0 && (module.exports = {
f7eb47b… lmata 319 Suite,
f7eb47b… lmata 320 TestCase
f7eb47b… lmata 321 });

Keyboard Shortcuts

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