@empiricalrun/test-run 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @empiricalrun/test-run
2
2
 
3
+ ## 0.4.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 92bb271: fix: add retry on dashboard fetch call inside test-run package
8
+
9
+ ## 0.4.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 19075b9: fix: expose --skip-teardown flag on test-run package
14
+
3
15
  ## 0.4.2
4
16
 
5
17
  ### Patch Changes
package/dist/bin/index.js CHANGED
@@ -12,6 +12,7 @@ const utils_1 = require("../utils");
12
12
  .option("-n, --name <test-name>", "Name of the test to run")
13
13
  .option("-d, --dir <test-dir>", "Path to the test directory")
14
14
  .option("-p, --project <project-name...>", "Test projects to run")
15
+ .option("--skip-teardown", `This options skips running teardown tests`)
15
16
  .option("--forbid-only", `This options forbids the use of ".only" in the test files`)
16
17
  .allowUnknownOption();
17
18
  commander_1.program.parse(process.argv);
@@ -25,10 +26,12 @@ const utils_1 = require("../utils");
25
26
  const optionsToStrip = [
26
27
  "-n",
27
28
  "--name",
29
+ "--skip-teardown",
28
30
  "-d",
29
31
  "--dir",
30
32
  "-p",
31
33
  "--project",
34
+ options.skipTeardown,
32
35
  options.name,
33
36
  options.dir,
34
37
  ...options.project, // an array of comma separated project names/pattern matching globs *,premium-*,super-premium-*,safari
@@ -54,9 +57,13 @@ const utils_1 = require("../utils");
54
57
  filteringSets: [...options.project, ...environmentSpecificProjects],
55
58
  });
56
59
  pwOptions.push(...projectFilters);
60
+ const directory = options.dir || "tests";
61
+ if (options.skipTeardown) {
62
+ await (0, utils_1.handleTeardownSkipFlag)(directory);
63
+ }
57
64
  const { hasTestPassed } = await (0, __1.runTest)({
58
65
  name: options.name,
59
- dir: options.dir || "tests",
66
+ dir: directory,
60
67
  pwOptions: pwOptions.join(" "),
61
68
  platform,
62
69
  });
@@ -1 +1 @@
1
- {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../src/dashboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAK7C,eAAO,MAAM,wBAAwB,QAAa,QAAQ;IACxD,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,KAAK,CAAC;CACd,CA6BA,CAAC"}
1
+ {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../src/dashboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAK7C,eAAO,MAAM,wBAAwB,QAAa,QAAQ;IACxD,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,KAAK,CAAC;CACd,CAyDA,CAAC"}
package/dist/dashboard.js CHANGED
@@ -1,22 +1,44 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchEnvironmentAndBuild = void 0;
7
+ const async_retry_1 = __importDefault(require("async-retry"));
4
8
  const utils_1 = require("./utils");
5
9
  const DOMAIN = process.env.DASHBOARD_DOMAIN || "https://dash.empirical.run";
6
10
  const fetchEnvironmentAndBuild = async () => {
11
+ if (!process.env.PROJECT_NAME) {
12
+ throw new Error("PROJECT_NAME is required for fetching environment and latest build");
13
+ }
7
14
  const projectRepo = (0, utils_1.buildRepoName)(process.env.PROJECT_NAME);
8
15
  const environmentSlug = `${process.env.TEST_RUN_ENVIRONMENT}`;
9
- const resp = await fetch(`${DOMAIN}/api/environments?project_repo_name=${projectRepo}&environment_slug=${environmentSlug}`, {
10
- method: "GET",
11
- headers: {
12
- "Content-Type": "application/json",
13
- Authorization: `weQPMWKT`,
14
- },
16
+ const data = await (0, async_retry_1.default)(async (bail) => {
17
+ const resp = await fetch(`${DOMAIN}/api/environments?project_repo_name=${projectRepo}&environment_slug=${environmentSlug}`, {
18
+ method: "GET",
19
+ headers: {
20
+ "Content-Type": "application/json",
21
+ Authorization: `weQPMWKT`,
22
+ },
23
+ });
24
+ if (!resp.ok) {
25
+ if (resp.status === 400) {
26
+ const erroredResponse = await resp.json();
27
+ bail(new Error(erroredResponse?.error?.message));
28
+ return;
29
+ }
30
+ throw new Error(`Failed to fetch environment and latest build from dashboard for project: ${projectRepo} and env slug: ${environmentSlug}`);
31
+ }
32
+ return (await resp.json());
33
+ }, {
34
+ retries: 3,
35
+ minTimeout: 1000,
36
+ maxTimeout: 60000,
37
+ factor: 3,
15
38
  });
16
- if (!resp.ok) {
17
- throw new Error(`Failed to fetch environment from dashboard for project: ${projectRepo} and env slug: ${environmentSlug}. Use PROJECT_NAME and TEST_RUN_ENVIRONMENT env vars to set these values correctly.`);
39
+ if (!data?.data) {
40
+ throw new Error(`Failed to fetch environment and latest build from dashboard for project: ${projectRepo} and env slug: ${environmentSlug}.`);
18
41
  }
19
- const data = (await resp.json());
20
42
  return data.data;
21
43
  };
22
44
  exports.fetchEnvironmentAndBuild = fetchEnvironmentAndBuild;
@@ -27,4 +27,9 @@ export declare enum TestFramework {
27
27
  PLAYWRIGHT = "playwright",
28
28
  APPWRIGHT = "appwright"
29
29
  }
30
+ export type PlaywProjectConfig = {
31
+ name: string;
32
+ teardown?: string;
33
+ testMatch: string | RegExp;
34
+ };
30
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB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ACnB,GAAG,QAAQ;CACZ;AAED,oBAAY,aAAa;IACvB,UAAU,eAAe;IACzB,SAAS,cAAc;CACxB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B,CAAC"}
@@ -38,4 +38,5 @@ export declare const generateProjectFilters: ({ platform, filteringSets, }: {
38
38
  export declare function buildRepoName(projectName: string): string;
39
39
  export declare const downloadBuild: (buildUrl: string) => Promise<void>;
40
40
  export declare const getTestRunner: (platform: Platform) => TestFramework;
41
+ export declare const handleTeardownSkipFlag: (directory: string) => Promise<void>;
41
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAW,UAAU,EAAc,MAAM,UAAU,CAAC;AAGjE,OAAO,EAAsB,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEvE,wBAAgB,GAAG,CACjB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACxC,OAAO,CAAC,MAAM,CAAC,CA2BjB;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,aAAa,GAAE,MAAW,GACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CAqBnB;AAED,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC;IAAE,YAAY,EAAE,IAAI,GAAG,SAAS,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CAatE;AAED,wBAAsB,YAAY,CAAC,EACj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AmBnB,CAAC;AAEF,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,eAAO,MAAM,aAAa,aAAoB,MAAM,KAAG,QAAQ,IAAI,CAWlE,CAAC;AAEF,eAAO,MAAM,aAAa,aAAc,QAAQ,KAAG,aAIlD,CAAC;AA4DF,eAAO,MAAM,sBAAsB,cAAqB,MAAM,kBAkB7D,CAAC"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getTestRunner = exports.downloadBuild = exports.buildRepoName = exports.generateProjectFilters = exports.filterArrayByGlobMatchersSet = exports.getProjectsFromPlaywrightConfig = exports.markTestAsOnly = exports.hasTopLevelDescribeConfigureWithSerialMode = exports.findFirstSerialDescribeBlock = exports.hasTestBlock = exports.getTestCaseNode = exports.getAllFilePaths = exports.cmd = void 0;
6
+ exports.handleTeardownSkipFlag = exports.getTestRunner = exports.downloadBuild = exports.buildRepoName = exports.generateProjectFilters = exports.filterArrayByGlobMatchersSet = exports.getProjectsFromPlaywrightConfig = exports.markTestAsOnly = exports.hasTopLevelDescribeConfigureWithSerialMode = exports.findFirstSerialDescribeBlock = exports.hasTestBlock = exports.getTestCaseNode = exports.getAllFilePaths = exports.cmd = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const minimatch_1 = require("minimatch");
@@ -221,3 +221,67 @@ const getTestRunner = (platform) => {
221
221
  : types_1.TestFramework.APPWRIGHT;
222
222
  };
223
223
  exports.getTestRunner = getTestRunner;
224
+ const getAllTeardownFiles = async (directory) => {
225
+ const teardownFileRegex = /.*\.teardown\.ts/;
226
+ const files = await getAllFilePaths(directory);
227
+ return files.filter((file) => teardownFileRegex.test(file));
228
+ };
229
+ const skipTeardownFile = async (filePath) => {
230
+ const project = new ts_morph_1.Project();
231
+ const sourceFile = project.addSourceFileAtPath(filePath);
232
+ sourceFile
233
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
234
+ .forEach((callExpression) => {
235
+ const expression = callExpression.getExpression();
236
+ if (expression.getText() === "teardown") {
237
+ expression.replaceWithText("teardown.skip");
238
+ }
239
+ else if (expression.getText() === "test") {
240
+ expression.replaceWithText("test.skip");
241
+ }
242
+ });
243
+ // Save the modified file
244
+ sourceFile.save().catch((error) => {
245
+ console.error(`Error updating the file: ${filePath}`, error);
246
+ });
247
+ };
248
+ class TeardownManager {
249
+ directory;
250
+ constructor(directory) {
251
+ this.directory = directory;
252
+ }
253
+ teardownFiles = [];
254
+ teardownFileContents = [];
255
+ async skip() {
256
+ this.teardownFiles = await getAllTeardownFiles(this.directory);
257
+ this.teardownFileContents = await Promise.all(this.teardownFiles.map(async (filePath) => {
258
+ const content = await fs_extra_1.default.readFile(filePath, "utf-8");
259
+ return { filePath, content };
260
+ }));
261
+ await Promise.all(this.teardownFiles.map(async (filePath) => await skipTeardownFile(filePath)));
262
+ }
263
+ unskip() {
264
+ this.teardownFileContents.forEach(({ filePath, content }) => {
265
+ fs_extra_1.default.writeFileSync(filePath, content, "utf-8");
266
+ });
267
+ }
268
+ }
269
+ const handleTeardownSkipFlag = async (directory) => {
270
+ console.log("Skipping teardown tests ...");
271
+ const teardowns = new TeardownManager(directory);
272
+ await teardowns.skip();
273
+ // revert teardown changes on exit
274
+ process.on("beforeExit", () => {
275
+ teardowns.unskip();
276
+ });
277
+ process.on("exit", () => {
278
+ teardowns.unskip();
279
+ });
280
+ process.on("SIGINT", () => {
281
+ teardowns.unskip();
282
+ });
283
+ process.on("SIGTERM", () => {
284
+ teardowns.unskip();
285
+ });
286
+ };
287
+ exports.handleTeardownSkipFlag = handleTeardownSkipFlag;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-run",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -15,6 +15,7 @@
15
15
  },
16
16
  "author": "Empirical Team <hey@empirical.run>",
17
17
  "dependencies": {
18
+ "async-retry": "^1.3.3",
18
19
  "commander": "^12.1.0",
19
20
  "fs-extra": "^11.2.0",
20
21
  "minimatch": "^10.0.1",
@@ -22,6 +23,7 @@
22
23
  "tsx": "^4.16.2"
23
24
  },
24
25
  "devDependencies": {
26
+ "@types/async-retry": "^1.4.8",
25
27
  "@types/fs-extra": "^11.0.4",
26
28
  "@types/node": "^22.5.5"
27
29
  },