testTools.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 testTools_exports = {};
  30. __export(testTools_exports, {
  31. debugTest: () => debugTest,
  32. listTests: () => listTests,
  33. runTests: () => runTests
  34. });
  35. module.exports = __toCommonJS(testTools_exports);
  36. var import_bundle = require("../sdk/bundle");
  37. var import_listModeReporter = __toESM(require("../../reporters/listModeReporter"));
  38. var import_testTool = require("./testTool");
  39. const listTests = (0, import_testTool.defineTestTool)({
  40. schema: {
  41. name: "test_list",
  42. title: "List tests",
  43. description: "List tests",
  44. inputSchema: import_bundle.z.object({}),
  45. type: "readOnly"
  46. },
  47. handle: async (context) => {
  48. const { testRunner, screen, output } = await context.createTestRunner();
  49. const reporter = new import_listModeReporter.default({ screen, includeTestId: true });
  50. await testRunner.listTests(reporter, {});
  51. return { content: output.map((text) => ({ type: "text", text })) };
  52. }
  53. });
  54. const runTests = (0, import_testTool.defineTestTool)({
  55. schema: {
  56. name: "test_run",
  57. title: "Run tests",
  58. description: "Run tests",
  59. inputSchema: import_bundle.z.object({
  60. locations: import_bundle.z.array(import_bundle.z.string()).optional().describe('Folder, file or location to run: "test/e2e" or "test/e2e/file.spec.ts" or "test/e2e/file.spec.ts:20"'),
  61. projects: import_bundle.z.array(import_bundle.z.string()).optional().describe('Projects to run, projects from playwright.config.ts, by default runs all projects. Running with "chromium" is a good start')
  62. }),
  63. type: "readOnly"
  64. },
  65. handle: async (context, params) => {
  66. const { output } = await context.runTestsWithGlobalSetupAndPossiblePause({
  67. locations: params.locations,
  68. projects: params.projects,
  69. disableConfigReporters: true
  70. });
  71. return { content: [{ type: "text", text: output }] };
  72. }
  73. });
  74. const debugTest = (0, import_testTool.defineTestTool)({
  75. schema: {
  76. name: "test_debug",
  77. title: "Debug single test",
  78. description: "Debug single test",
  79. inputSchema: import_bundle.z.object({
  80. test: import_bundle.z.object({
  81. id: import_bundle.z.string().describe("Test ID to debug."),
  82. title: import_bundle.z.string().describe("Human readable test title for granting permission to debug the test.")
  83. })
  84. }),
  85. type: "readOnly"
  86. },
  87. handle: async (context, params) => {
  88. const { output, status } = await context.runTestsWithGlobalSetupAndPossiblePause({
  89. headed: context.computedHeaded,
  90. testIds: [params.test.id],
  91. // For automatic recovery
  92. timeout: 0,
  93. workers: 1,
  94. pauseOnError: true,
  95. disableConfigReporters: true,
  96. actionTimeout: 5e3
  97. });
  98. return { content: [{ type: "text", text: output }], isError: status !== "paused" && status !== "passed" };
  99. }
  100. });
  101. // Annotate the CommonJS export names for ESM import in node:
  102. 0 && (module.exports = {
  103. debugTest,
  104. listTests,
  105. runTests
  106. });