cypress-plugin-last-failed 1.1.0 โ 1.2.0
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/.github/workflows/main.yml +1 -1
- package/README.md +1 -1
- package/package.json +1 -1
- package/runFailed.js +20 -3
- package/src/index.js +15 -10
package/README.md
CHANGED
package/package.json
CHANGED
package/runFailed.js
CHANGED
|
@@ -10,20 +10,37 @@ async function runLastFailed() {
|
|
|
10
10
|
Ensure you are in the directory of your cypress config
|
|
11
11
|
Try running tests again with cypress run`;
|
|
12
12
|
|
|
13
|
-
const failedTestFilePath = `${appDir}/test-results/last-run.
|
|
13
|
+
const failedTestFilePath = `${appDir}/test-results/last-run.json`;
|
|
14
14
|
|
|
15
15
|
if (fs.existsSync(failedTestFilePath)) {
|
|
16
16
|
// Retrieve the failedTests from the file
|
|
17
17
|
const failedTests = await fs.promises.readFile(failedTestFilePath, 'utf8');
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// Retrieve the parent suite and tests in the results from test-results/last-run
|
|
20
|
+
const parentAndTest = JSON.parse(failedTests).map(({ parent, test }) => ({
|
|
21
|
+
parent,
|
|
22
|
+
test,
|
|
23
|
+
}));
|
|
24
|
+
// Combine parent suite and test together
|
|
25
|
+
const resultSet = new Set(
|
|
26
|
+
Object.values(parentAndTest).flatMap(
|
|
27
|
+
(parent) => parent.parent + ',' + parent.test + ';'
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
// Format string for use in grep functionality
|
|
31
|
+
const stringedTests = Array.from(resultSet)
|
|
32
|
+
.toString()
|
|
33
|
+
.replaceAll(',', ' ')
|
|
34
|
+
.slice(0, -1);
|
|
35
|
+
|
|
36
|
+
if (stringedTests.length > 0) {
|
|
20
37
|
// Allow for additional cli arguments to be passed to the run command
|
|
21
38
|
const runOptions = await cypress.cli.parseRunArguments(
|
|
22
39
|
process.argv.slice(2)
|
|
23
40
|
);
|
|
24
41
|
|
|
25
42
|
// Set cypress environment variables needed for running last failed tests
|
|
26
|
-
process.env.CYPRESS_grep = `${
|
|
43
|
+
process.env.CYPRESS_grep = `${stringedTests}`;
|
|
27
44
|
process.env.CYPRESS_grepFilterSpecs = true;
|
|
28
45
|
process.env.CYPRESS_grepOmitFiltered = true;
|
|
29
46
|
|
package/src/index.js
CHANGED
|
@@ -21,18 +21,23 @@ const collectFailingTests = (on, config) => {
|
|
|
21
21
|
for (i in results.runs) {
|
|
22
22
|
const tests = results.runs[i].tests
|
|
23
23
|
.filter((test) => test.state === 'failed')
|
|
24
|
-
.map((test) => test.title
|
|
24
|
+
.map((test) => test.title);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const spec = results.runs[i].spec.relative;
|
|
27
|
+
|
|
28
|
+
for (i in tests) {
|
|
29
|
+
let report = {
|
|
30
|
+
spec: spec,
|
|
31
|
+
parent: [...tests[i].slice(0, -1)],
|
|
32
|
+
test: tests[i].pop(),
|
|
33
|
+
};
|
|
34
|
+
// Only store non empty test titles
|
|
35
|
+
if (tests != '') {
|
|
36
|
+
failedTests.push(report);
|
|
37
|
+
}
|
|
29
38
|
}
|
|
30
39
|
}
|
|
31
40
|
|
|
32
|
-
const stringedTests = failedTests.toString();
|
|
33
|
-
// Prepare a string that can be read from cy-grep
|
|
34
|
-
const greppedTestFormat = stringedTests.replaceAll(',', '; ');
|
|
35
|
-
|
|
36
41
|
// Use the cypress.config directory for path for storing test-results
|
|
37
42
|
const failedTestFileDirectory = `${path.dirname(
|
|
38
43
|
config.configFile
|
|
@@ -44,9 +49,9 @@ const collectFailingTests = (on, config) => {
|
|
|
44
49
|
});
|
|
45
50
|
const lastRunReportFile = path.join(
|
|
46
51
|
`${failedTestFileDirectory}`,
|
|
47
|
-
'last-run.
|
|
52
|
+
'last-run.json'
|
|
48
53
|
);
|
|
49
|
-
await fs.promises.writeFile(lastRunReportFile,
|
|
54
|
+
await fs.promises.writeFile(lastRunReportFile, JSON.stringify(failedTests));
|
|
50
55
|
});
|
|
51
56
|
|
|
52
57
|
return collectFailingTests;
|