@empiricalrun/test-run 0.4.2 → 0.4.3

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,11 @@
1
1
  # @empiricalrun/test-run
2
2
 
3
+ ## 0.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 19075b9: fix: expose --skip-teardown flag on test-run package
8
+
3
9
  ## 0.4.2
4
10
 
5
11
  ### 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
  });
@@ -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,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AAEF,oBAAY,QAAQ;IAClB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,GAAG,QAAQ;CACZ;AAED,oBAAY,aAAa;IACvB,UAAU,eAAe;IACzB,SAAS,cAAc;CACxB"}
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,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AAEF,oBAAY,QAAQ;IAClB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,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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AY,EACZ,QAAQ,GACT,EAAE;IACD,UAAU,EAAE,UAAU,CAAC;IACvB,kBAAkB,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IACtC,YAAY,EAAE,IAAI,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB,iBAgBA;AAED,wBAAsB,+BAA+B,CAAC,QAAQ,EAAE,QAAQ,gBAevE;AAED,eAAO,MAAM,4BAA4B,UAEhC,MAAM,EAAE,mBAGE,MAAM,EAAE,EAAE,KAC1B,MAAM,EAUR,CAAC;AAEF,eAAO,MAAM,sBAAsB;cAIvB,QAAQ;mBACH,MAAM,EAAE;MACrB,QAAQ,MAAM,EAAE,CAmBnB,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.3",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"