@empiricalrun/test-run 0.4.1 → 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 +12 -0
- package/dist/bin/index.js +14 -4
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +69 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
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
|
+
|
|
9
|
+
## 0.4.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 27716bd: fix: consider latest build url only when dispatch build url is not preset
|
|
14
|
+
|
|
3
15
|
## 0.4.1
|
|
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
|
|
@@ -40,20 +43,27 @@ const utils_1 = require("../utils");
|
|
|
40
43
|
let environmentSpecificProjects = [];
|
|
41
44
|
let platform = types_1.Platform.WEB;
|
|
42
45
|
if (process.env.TEST_RUN_ENVIRONMENT) {
|
|
43
|
-
const { environment, build } = await (0, dashboard_1.fetchEnvironmentAndBuild)();
|
|
46
|
+
const { environment, build: latestBuild } = await (0, dashboard_1.fetchEnvironmentAndBuild)();
|
|
44
47
|
platform = environment.platform;
|
|
45
48
|
environmentSpecificProjects = environment.playwright_projects;
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
if (!process.env.BUILD_URL) {
|
|
50
|
+
process.env.BUILD_URL = latestBuild?.build_url; // pick the one coming from dispatch, otherwise use the latest build from DB
|
|
51
|
+
}
|
|
52
|
+
const buildUrl = process.env.BUILD_URL;
|
|
53
|
+
await (0, utils_1.downloadBuild)(buildUrl);
|
|
48
54
|
}
|
|
49
55
|
const projectFilters = await (0, utils_1.generateProjectFilters)({
|
|
50
56
|
platform,
|
|
51
57
|
filteringSets: [...options.project, ...environmentSpecificProjects],
|
|
52
58
|
});
|
|
53
59
|
pwOptions.push(...projectFilters);
|
|
60
|
+
const directory = options.dir || "tests";
|
|
61
|
+
if (options.skipTeardown) {
|
|
62
|
+
await (0, utils_1.handleTeardownSkipFlag)(directory);
|
|
63
|
+
}
|
|
54
64
|
const { hasTestPassed } = await (0, __1.runTest)({
|
|
55
65
|
name: options.name,
|
|
56
|
-
dir:
|
|
66
|
+
dir: directory,
|
|
57
67
|
pwOptions: pwOptions.join(" "),
|
|
58
68
|
platform,
|
|
59
69
|
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"A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E,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"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node, SourceFile } from "ts-morph";
|
|
2
|
-
import {
|
|
2
|
+
import { Platform, TestFramework } from "../types";
|
|
3
3
|
export declare function cmd(command: string[], options: {
|
|
4
4
|
env?: Record<string, string>;
|
|
5
5
|
}): Promise<number>;
|
|
@@ -36,6 +36,7 @@ export declare const generateProjectFilters: ({ platform, filteringSets, }: {
|
|
|
36
36
|
filteringSets: string[];
|
|
37
37
|
}) => Promise<string[]>;
|
|
38
38
|
export declare function buildRepoName(projectName: string): string;
|
|
39
|
-
export declare const downloadBuild: (
|
|
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,
|
|
1
|
+
{"version":3,"file":"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AClB,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"}
|
package/dist/utils/index.js
CHANGED
|
@@ -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");
|
|
@@ -202,14 +202,14 @@ function buildRepoName(projectName) {
|
|
|
202
202
|
return `${projectName}-tests`;
|
|
203
203
|
}
|
|
204
204
|
exports.buildRepoName = buildRepoName;
|
|
205
|
-
const downloadBuild = async (
|
|
205
|
+
const downloadBuild = async (buildUrl) => {
|
|
206
206
|
const packageJSONPath = "package.json";
|
|
207
207
|
const packageJsonStr = await fs_extra_1.default.readFile(packageJSONPath, "utf-8");
|
|
208
208
|
const packageJSONData = JSON.parse(packageJsonStr);
|
|
209
209
|
const buildDownloadScript = packageJSONData.scripts["download"];
|
|
210
|
-
if (buildDownloadScript &&
|
|
211
|
-
console.log(`Downloading build from ${
|
|
212
|
-
await cmd(`npm run download ${
|
|
210
|
+
if (buildDownloadScript && buildUrl) {
|
|
211
|
+
console.log(`Downloading build from ${buildUrl}`);
|
|
212
|
+
await cmd(`npm run download ${buildUrl}`.split(" "), {
|
|
213
213
|
env: { ...Object(process.env) },
|
|
214
214
|
});
|
|
215
215
|
}
|
|
@@ -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;
|