testInfo.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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 testInfo_exports = {};
  30. __export(testInfo_exports, {
  31. StepSkipError: () => StepSkipError,
  32. TestInfoImpl: () => TestInfoImpl,
  33. TestSkipError: () => TestSkipError,
  34. TestStepInfoImpl: () => TestStepInfoImpl
  35. });
  36. module.exports = __toCommonJS(testInfo_exports);
  37. var import_fs = __toESM(require("fs"));
  38. var import_path = __toESM(require("path"));
  39. var import_utils = require("playwright-core/lib/utils");
  40. var import_timeoutManager = require("./timeoutManager");
  41. var import_util = require("../util");
  42. var import_testTracing = require("./testTracing");
  43. var import_util2 = require("./util");
  44. var import_transform = require("../transform/transform");
  45. class TestInfoImpl {
  46. constructor(configInternal, projectInternal, workerParams, test, retry, onStepBegin, onStepEnd, onAttach, onTestPaused) {
  47. this._snapshotNames = { lastAnonymousSnapshotIndex: 0, lastNamedSnapshotIndex: {} };
  48. this._ariaSnapshotNames = { lastAnonymousSnapshotIndex: 0, lastNamedSnapshotIndex: {} };
  49. this._interruptedPromise = new import_utils.ManualPromise();
  50. this._lastStepId = 0;
  51. this._steps = [];
  52. this._stepMap = /* @__PURE__ */ new Map();
  53. this._hasNonRetriableError = false;
  54. this._hasUnhandledError = false;
  55. this._allowSkips = false;
  56. this.duration = 0;
  57. this.annotations = [];
  58. this.attachments = [];
  59. this.status = "passed";
  60. this.snapshotSuffix = "";
  61. this.errors = [];
  62. this.testId = test?.id ?? "";
  63. this._onStepBegin = onStepBegin;
  64. this._onStepEnd = onStepEnd;
  65. this._onAttach = onAttach;
  66. this._onTestPaused = onTestPaused;
  67. this._startTime = (0, import_utils.monotonicTime)();
  68. this._startWallTime = Date.now();
  69. this._requireFile = test?._requireFile ?? "";
  70. this._uniqueSymbol = Symbol("testInfoUniqueSymbol");
  71. this._workerParams = workerParams;
  72. this.repeatEachIndex = workerParams.repeatEachIndex;
  73. this.retry = retry;
  74. this.workerIndex = workerParams.workerIndex;
  75. this.parallelIndex = workerParams.parallelIndex;
  76. this._projectInternal = projectInternal;
  77. this.project = projectInternal.project;
  78. this._configInternal = configInternal;
  79. this.config = configInternal.config;
  80. this.title = test?.title ?? "";
  81. this.titlePath = test?.titlePath() ?? [];
  82. this.file = test?.location.file ?? "";
  83. this.line = test?.location.line ?? 0;
  84. this.column = test?.location.column ?? 0;
  85. this.tags = test?.tags ?? [];
  86. this.fn = test?.fn ?? (() => {
  87. });
  88. this.expectedStatus = test?.expectedStatus ?? "skipped";
  89. this._timeoutManager = new import_timeoutManager.TimeoutManager(this.project.timeout);
  90. if (configInternal.configCLIOverrides.debug)
  91. this._setDebugMode();
  92. this.outputDir = (() => {
  93. const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile.replace(/\.(spec|test)\.(js|ts|jsx|tsx|mjs|mts|cjs|cts)$/, ""));
  94. const sanitizedRelativePath = relativeTestFilePath.replace(process.platform === "win32" ? new RegExp("\\\\", "g") : new RegExp("/", "g"), "-");
  95. const fullTitleWithoutSpec = this.titlePath.slice(1).join(" ");
  96. let testOutputDir = (0, import_util.trimLongString)(sanitizedRelativePath + "-" + (0, import_utils.sanitizeForFilePath)(fullTitleWithoutSpec), import_util.windowsFilesystemFriendlyLength);
  97. if (projectInternal.id)
  98. testOutputDir += "-" + (0, import_utils.sanitizeForFilePath)(projectInternal.id);
  99. if (this.retry)
  100. testOutputDir += "-retry" + this.retry;
  101. if (this.repeatEachIndex)
  102. testOutputDir += "-repeat" + this.repeatEachIndex;
  103. return import_path.default.join(this.project.outputDir, testOutputDir);
  104. })();
  105. this.snapshotDir = (() => {
  106. const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile);
  107. return import_path.default.join(this.project.snapshotDir, relativeTestFilePath + "-snapshots");
  108. })();
  109. this._attachmentsPush = this.attachments.push.bind(this.attachments);
  110. const attachmentsPush = (...attachments) => {
  111. for (const a of attachments)
  112. this._attach(a, this._parentStep()?.stepId);
  113. return this.attachments.length;
  114. };
  115. Object.defineProperty(this.attachments, "push", {
  116. value: attachmentsPush,
  117. writable: true,
  118. enumerable: false,
  119. configurable: true
  120. });
  121. this._tracing = new import_testTracing.TestTracing(this, workerParams.artifactsDir);
  122. this.skip = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("skip", location, args));
  123. this.fixme = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("fixme", location, args));
  124. this.fail = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("fail", location, args));
  125. this.slow = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("slow", location, args));
  126. }
  127. get error() {
  128. return this.errors[0];
  129. }
  130. set error(e) {
  131. if (e === void 0)
  132. throw new Error("Cannot assign testInfo.error undefined value!");
  133. this.errors[0] = e;
  134. }
  135. get timeout() {
  136. return this._timeoutManager.defaultSlot().timeout;
  137. }
  138. set timeout(timeout) {
  139. }
  140. _deadlineForMatcher(timeout) {
  141. const startTime = (0, import_utils.monotonicTime)();
  142. const matcherDeadline = timeout ? startTime + timeout : import_timeoutManager.kMaxDeadline;
  143. const testDeadline = this._timeoutManager.currentSlotDeadline() - 250;
  144. const matcherMessage = `Timeout ${timeout}ms exceeded while waiting on the predicate`;
  145. const testMessage = `Test timeout of ${this.timeout}ms exceeded`;
  146. return { deadline: Math.min(testDeadline, matcherDeadline), timeoutMessage: testDeadline < matcherDeadline ? testMessage : matcherMessage };
  147. }
  148. static _defaultDeadlineForMatcher(timeout) {
  149. return { deadline: timeout ? (0, import_utils.monotonicTime)() + timeout : 0, timeoutMessage: `Timeout ${timeout}ms exceeded while waiting on the predicate` };
  150. }
  151. _modifier(type, location, modifierArgs) {
  152. if (typeof modifierArgs[1] === "function") {
  153. throw new Error([
  154. "It looks like you are calling test.skip() inside the test and pass a callback.",
  155. "Pass a condition instead and optional description instead:",
  156. `test('my test', async ({ page, isMobile }) => {`,
  157. ` test.skip(isMobile, 'This test is not applicable on mobile');`,
  158. `});`
  159. ].join("\n"));
  160. }
  161. if (modifierArgs.length >= 1 && !modifierArgs[0])
  162. return;
  163. const description = modifierArgs[1];
  164. this.annotations.push({ type, description, location });
  165. if (type === "slow") {
  166. this._timeoutManager.slow();
  167. } else if (type === "skip" || type === "fixme") {
  168. this.expectedStatus = "skipped";
  169. throw new TestSkipError("Test is skipped: " + (description || ""));
  170. } else if (type === "fail") {
  171. if (this.expectedStatus !== "skipped")
  172. this.expectedStatus = "failed";
  173. }
  174. }
  175. _findLastPredefinedStep(steps) {
  176. for (let i = steps.length - 1; i >= 0; i--) {
  177. const child = this._findLastPredefinedStep(steps[i].steps);
  178. if (child)
  179. return child;
  180. if ((steps[i].category === "hook" || steps[i].category === "fixture") && !steps[i].endWallTime)
  181. return steps[i];
  182. }
  183. }
  184. _parentStep() {
  185. return (0, import_utils.currentZone)().data("stepZone") ?? this._findLastPredefinedStep(this._steps);
  186. }
  187. _addStep(data, parentStep) {
  188. const stepId = `${data.category}@${++this._lastStepId}`;
  189. if (data.category === "hook" || data.category === "fixture") {
  190. parentStep = this._findLastPredefinedStep(this._steps);
  191. } else {
  192. if (!parentStep)
  193. parentStep = this._parentStep();
  194. }
  195. const filteredStack = (0, import_util.filteredStackTrace)((0, import_utils.captureRawStack)());
  196. let boxedStack = parentStep?.boxedStack;
  197. let location = data.location;
  198. if (!boxedStack && data.box) {
  199. boxedStack = filteredStack.slice(1);
  200. location = location || boxedStack[0];
  201. }
  202. location = location || filteredStack[0];
  203. const step = {
  204. ...data,
  205. stepId,
  206. group: parentStep?.group ?? data.group,
  207. boxedStack,
  208. location,
  209. steps: [],
  210. attachmentIndices: [],
  211. info: new TestStepInfoImpl(this, stepId, data.title, parentStep?.info),
  212. complete: (result) => {
  213. if (step.endWallTime)
  214. return;
  215. step.endWallTime = Date.now();
  216. if (result.error) {
  217. if (typeof result.error === "object" && !result.error?.[stepSymbol])
  218. result.error[stepSymbol] = step;
  219. const error = (0, import_util2.testInfoError)(result.error);
  220. if (step.boxedStack)
  221. error.stack = `${error.message}
  222. ${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
  223. step.error = error;
  224. }
  225. if (!step.error) {
  226. for (const childStep of step.steps) {
  227. if (childStep.error && childStep.infectParentStepsWithError) {
  228. step.error = childStep.error;
  229. step.infectParentStepsWithError = true;
  230. break;
  231. }
  232. }
  233. }
  234. if (!step.group) {
  235. const payload = {
  236. testId: this.testId,
  237. stepId,
  238. wallTime: step.endWallTime,
  239. error: step.error,
  240. suggestedRebaseline: result.suggestedRebaseline,
  241. annotations: step.info.annotations
  242. };
  243. this._onStepEnd(payload);
  244. }
  245. if (step.group !== "internal") {
  246. const errorForTrace = step.error ? { name: "", message: step.error.message || "", stack: step.error.stack } : void 0;
  247. const attachments = step.attachmentIndices.map((i) => this.attachments[i]);
  248. this._tracing.appendAfterActionForStep(stepId, errorForTrace, attachments, step.info.annotations);
  249. }
  250. }
  251. };
  252. const parentStepList = parentStep ? parentStep.steps : this._steps;
  253. parentStepList.push(step);
  254. this._stepMap.set(stepId, step);
  255. if (!step.group) {
  256. const payload = {
  257. testId: this.testId,
  258. stepId,
  259. parentStepId: parentStep ? parentStep.stepId : void 0,
  260. title: step.title,
  261. category: step.category,
  262. wallTime: Date.now(),
  263. location: step.location
  264. };
  265. this._onStepBegin(payload);
  266. }
  267. if (step.group !== "internal") {
  268. this._tracing.appendBeforeActionForStep({
  269. stepId,
  270. parentId: parentStep?.stepId,
  271. title: step.shortTitle ?? step.title,
  272. category: step.category,
  273. params: step.params,
  274. stack: step.location ? [step.location] : [],
  275. group: step.group
  276. });
  277. }
  278. return step;
  279. }
  280. _interrupt() {
  281. this._interruptedPromise.resolve();
  282. this._timeoutManager.interrupt();
  283. if (this.status === "passed")
  284. this.status = "interrupted";
  285. }
  286. _failWithError(error) {
  287. if (this.status === "passed" || this.status === "skipped")
  288. this.status = error instanceof import_timeoutManager.TimeoutManagerError ? "timedOut" : "failed";
  289. const serialized = (0, import_util2.testInfoError)(error);
  290. const step = typeof error === "object" ? error?.[stepSymbol] : void 0;
  291. if (step && step.boxedStack)
  292. serialized.stack = `${error.name}: ${error.message}
  293. ${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
  294. this.errors.push(serialized);
  295. this._tracing.appendForError(serialized);
  296. }
  297. async _runAsStep(stepInfo, cb) {
  298. const step = this._addStep(stepInfo);
  299. try {
  300. await cb();
  301. step.complete({});
  302. } catch (error) {
  303. step.complete({ error });
  304. throw error;
  305. }
  306. }
  307. async _runWithTimeout(runnable, cb) {
  308. try {
  309. await this._timeoutManager.withRunnable(runnable, async () => {
  310. try {
  311. await cb();
  312. } catch (e) {
  313. if (this._allowSkips && e instanceof TestSkipError) {
  314. if (this.status === "passed")
  315. this.status = "skipped";
  316. } else {
  317. this._failWithError(e);
  318. }
  319. throw e;
  320. }
  321. });
  322. } catch (error) {
  323. if (!this._interruptedPromise.isDone() && error instanceof import_timeoutManager.TimeoutManagerError)
  324. this._failWithError(error);
  325. throw error;
  326. }
  327. }
  328. _isFailure() {
  329. return this.status !== "skipped" && this.status !== this.expectedStatus;
  330. }
  331. _currentHookType() {
  332. const type = this._timeoutManager.currentSlotType();
  333. return ["beforeAll", "afterAll", "beforeEach", "afterEach"].includes(type) ? type : void 0;
  334. }
  335. _setDebugMode() {
  336. this._timeoutManager.setIgnoreTimeouts();
  337. }
  338. async _didFinishTestFunction() {
  339. const shouldPause = this._workerParams.pauseAtEnd && !this._isFailure() || this._workerParams.pauseOnError && this._isFailure();
  340. if (shouldPause) {
  341. this._onTestPaused({ testId: this.testId, errors: this._isFailure() ? this.errors : [] });
  342. await this._interruptedPromise;
  343. }
  344. await this._onDidFinishTestFunctionCallback?.();
  345. }
  346. // ------------ TestInfo methods ------------
  347. async attach(name, options = {}) {
  348. const step = this._addStep({
  349. title: `Attach ${(0, import_utils.escapeWithQuotes)(name, '"')}`,
  350. category: "test.attach"
  351. });
  352. this._attach(
  353. await (0, import_util.normalizeAndSaveAttachment)(this.outputPath(), name, options),
  354. step.stepId
  355. );
  356. step.complete({});
  357. }
  358. _attach(attachment, stepId) {
  359. const index = this._attachmentsPush(attachment) - 1;
  360. let step = stepId ? this._stepMap.get(stepId) : void 0;
  361. if (!!step?.group)
  362. step = void 0;
  363. if (step) {
  364. step.attachmentIndices.push(index);
  365. } else {
  366. const stepId2 = `attach@${(0, import_utils.createGuid)()}`;
  367. this._tracing.appendBeforeActionForStep({ stepId: stepId2, title: `Attach ${(0, import_utils.escapeWithQuotes)(attachment.name, '"')}`, category: "test.attach", stack: [] });
  368. this._tracing.appendAfterActionForStep(stepId2, void 0, [attachment]);
  369. }
  370. this._onAttach({
  371. testId: this.testId,
  372. name: attachment.name,
  373. contentType: attachment.contentType,
  374. path: attachment.path,
  375. body: attachment.body?.toString("base64"),
  376. stepId: step?.stepId
  377. });
  378. }
  379. outputPath(...pathSegments) {
  380. const outputPath = this._getOutputPath(...pathSegments);
  381. import_fs.default.mkdirSync(this.outputDir, { recursive: true });
  382. return outputPath;
  383. }
  384. _getOutputPath(...pathSegments) {
  385. const joinedPath = import_path.default.join(...pathSegments);
  386. const outputPath = (0, import_util.getContainedPath)(this.outputDir, joinedPath);
  387. if (outputPath)
  388. return outputPath;
  389. throw new Error(`The outputPath is not allowed outside of the parent directory. Please fix the defined path.
  390. outputPath: ${joinedPath}`);
  391. }
  392. _fsSanitizedTestName() {
  393. const fullTitleWithoutSpec = this.titlePath.slice(1).join(" ");
  394. return (0, import_utils.sanitizeForFilePath)((0, import_util.trimLongString)(fullTitleWithoutSpec));
  395. }
  396. _resolveSnapshotPaths(kind, name, updateSnapshotIndex, anonymousExtension) {
  397. const snapshotNames = kind === "aria" ? this._ariaSnapshotNames : this._snapshotNames;
  398. const defaultExtensions = { "aria": ".aria.yml", "screenshot": ".png", "snapshot": ".txt" };
  399. const ariaAwareExtname = (filePath) => kind === "aria" && filePath.endsWith(".aria.yml") ? ".aria.yml" : import_path.default.extname(filePath);
  400. let subPath;
  401. let ext;
  402. let relativeOutputPath;
  403. if (!name) {
  404. const index = snapshotNames.lastAnonymousSnapshotIndex + 1;
  405. if (updateSnapshotIndex === "updateSnapshotIndex")
  406. snapshotNames.lastAnonymousSnapshotIndex = index;
  407. const fullTitleWithoutSpec = [...this.titlePath.slice(1), index].join(" ");
  408. ext = anonymousExtension ?? defaultExtensions[kind];
  409. subPath = (0, import_util.sanitizeFilePathBeforeExtension)((0, import_util.trimLongString)(fullTitleWithoutSpec) + ext, ext);
  410. relativeOutputPath = (0, import_util.sanitizeFilePathBeforeExtension)((0, import_util.trimLongString)(fullTitleWithoutSpec, import_util.windowsFilesystemFriendlyLength) + ext, ext);
  411. } else {
  412. if (Array.isArray(name)) {
  413. subPath = import_path.default.join(...name);
  414. relativeOutputPath = import_path.default.join(...name);
  415. ext = ariaAwareExtname(subPath);
  416. } else {
  417. ext = ariaAwareExtname(name);
  418. subPath = (0, import_util.sanitizeFilePathBeforeExtension)(name, ext);
  419. relativeOutputPath = (0, import_util.sanitizeFilePathBeforeExtension)((0, import_util.trimLongString)(name, import_util.windowsFilesystemFriendlyLength), ext);
  420. }
  421. const index = (snapshotNames.lastNamedSnapshotIndex[relativeOutputPath] || 0) + 1;
  422. if (updateSnapshotIndex === "updateSnapshotIndex")
  423. snapshotNames.lastNamedSnapshotIndex[relativeOutputPath] = index;
  424. if (index > 1)
  425. relativeOutputPath = (0, import_util.addSuffixToFilePath)(relativeOutputPath, `-${index - 1}`);
  426. }
  427. const absoluteSnapshotPath = this._applyPathTemplate(kind, subPath, ext);
  428. return { absoluteSnapshotPath, relativeOutputPath };
  429. }
  430. _applyPathTemplate(kind, relativePath, ext) {
  431. const legacyTemplate = "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{-snapshotSuffix}{ext}";
  432. let template;
  433. if (kind === "screenshot") {
  434. template = this._projectInternal.expect?.toHaveScreenshot?.pathTemplate || this._projectInternal.snapshotPathTemplate || legacyTemplate;
  435. } else if (kind === "aria") {
  436. const ariaDefaultTemplate = "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{ext}";
  437. template = this._projectInternal.expect?.toMatchAriaSnapshot?.pathTemplate || this._projectInternal.snapshotPathTemplate || ariaDefaultTemplate;
  438. } else {
  439. template = this._projectInternal.snapshotPathTemplate || legacyTemplate;
  440. }
  441. const dir = import_path.default.dirname(relativePath);
  442. const name = import_path.default.basename(relativePath, ext);
  443. const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile);
  444. const parsedRelativeTestFilePath = import_path.default.parse(relativeTestFilePath);
  445. const projectNamePathSegment = (0, import_utils.sanitizeForFilePath)(this.project.name);
  446. const snapshotPath = template.replace(/\{(.)?testDir\}/g, "$1" + this.project.testDir).replace(/\{(.)?snapshotDir\}/g, "$1" + this.project.snapshotDir).replace(/\{(.)?snapshotSuffix\}/g, this.snapshotSuffix ? "$1" + this.snapshotSuffix : "").replace(/\{(.)?testFileDir\}/g, "$1" + parsedRelativeTestFilePath.dir).replace(/\{(.)?platform\}/g, "$1" + process.platform).replace(/\{(.)?projectName\}/g, projectNamePathSegment ? "$1" + projectNamePathSegment : "").replace(/\{(.)?testName\}/g, "$1" + this._fsSanitizedTestName()).replace(/\{(.)?testFileName\}/g, "$1" + parsedRelativeTestFilePath.base).replace(/\{(.)?testFilePath\}/g, "$1" + relativeTestFilePath).replace(/\{(.)?arg\}/g, "$1" + import_path.default.join(dir, name)).replace(/\{(.)?ext\}/g, ext ? "$1" + ext : "");
  447. return import_path.default.normalize(import_path.default.resolve(this._configInternal.configDir, snapshotPath));
  448. }
  449. snapshotPath(...args) {
  450. let name = args;
  451. let kind = "snapshot";
  452. const options = args[args.length - 1];
  453. if (options && typeof options === "object") {
  454. kind = options.kind ?? kind;
  455. name = args.slice(0, -1);
  456. }
  457. if (!["snapshot", "screenshot", "aria"].includes(kind))
  458. throw new Error(`testInfo.snapshotPath: unknown kind "${kind}", must be one of "snapshot", "screenshot" or "aria"`);
  459. return this._resolveSnapshotPaths(kind, name.length <= 1 ? name[0] : name, "dontUpdateSnapshotIndex").absoluteSnapshotPath;
  460. }
  461. setTimeout(timeout) {
  462. this._timeoutManager.setTimeout(timeout);
  463. }
  464. }
  465. class TestStepInfoImpl {
  466. constructor(testInfo, stepId, title, parentStep) {
  467. this.annotations = [];
  468. this._testInfo = testInfo;
  469. this._stepId = stepId;
  470. this._title = title;
  471. this._parentStep = parentStep;
  472. this.skip = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => {
  473. if (args.length > 0 && !args[0])
  474. return;
  475. const description = args[1];
  476. this.annotations.push({ type: "skip", description, location });
  477. throw new StepSkipError(description);
  478. });
  479. }
  480. async _runStepBody(skip, body, location) {
  481. if (skip) {
  482. this.annotations.push({ type: "skip", location });
  483. return void 0;
  484. }
  485. try {
  486. return await body(this);
  487. } catch (e) {
  488. if (e instanceof StepSkipError)
  489. return void 0;
  490. throw e;
  491. }
  492. }
  493. _attachToStep(attachment) {
  494. this._testInfo._attach(attachment, this._stepId);
  495. }
  496. async attach(name, options) {
  497. this._attachToStep(await (0, import_util.normalizeAndSaveAttachment)(this._testInfo.outputPath(), name, options));
  498. }
  499. get titlePath() {
  500. const parent = this._parentStep ?? this._testInfo;
  501. return [...parent.titlePath, this._title];
  502. }
  503. }
  504. class TestSkipError extends Error {
  505. }
  506. class StepSkipError extends Error {
  507. }
  508. const stepSymbol = Symbol("step");
  509. // Annotate the CommonJS export names for ESM import in node:
  510. 0 && (module.exports = {
  511. StepSkipError,
  512. TestInfoImpl,
  513. TestSkipError,
  514. TestStepInfoImpl
  515. });