forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_retries.test.js
More file actions
99 lines (80 loc) · 2.47 KB
/
test_retries.test.js
File metadata and controls
99 lines (80 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'use strict';
const fs = require('fs');
const path = require('path');
const runJest = require('../runJest');
const ConditionalTest = require('../../scripts/ConditionalTest');
ConditionalTest.skipSuiteOnJasmine();
describe('Test Retries', () => {
const outputFileName = 'retries.result.json';
const outputFilePath = path.join(
process.cwd(),
'e2e/test-retries/',
outputFileName,
);
afterAll(() => {
fs.unlinkSync(outputFilePath);
});
it('retries failed tests', () => {
const result = runJest('test-retries', ['e2e.test.js']);
expect(result.code).toEqual(0);
expect(result.failed).toBe(false);
});
it('reporter shows more than 1 invocation if test is retried', () => {
let jsonResult;
const reporterConfig = {
reporters: [
['<rootDir>/reporters/RetryReporter.js', {output: outputFilePath}],
],
};
runJest('test-retries', [
'--config',
JSON.stringify(reporterConfig),
'retry.test.js',
]);
const testOutput = fs.readFileSync(outputFilePath, 'utf8');
try {
jsonResult = JSON.parse(testOutput);
} catch (err) {
throw new Error(
`Can't parse the JSON result from ${outputFileName}, ${err.toString()}`,
);
}
expect(jsonResult.numPassedTests).toBe(0);
expect(jsonResult.numFailedTests).toBe(1);
expect(jsonResult.numPendingTests).toBe(0);
expect(jsonResult.testResults[0].testResults[0].invocations).toBe(4);
});
it('reporter shows 1 invocation if tests are not retried', () => {
let jsonResult;
const reporterConfig = {
reporters: [
['<rootDir>/reporters/RetryReporter.js', {output: outputFilePath}],
],
};
runJest('test-retries', [
'--config',
JSON.stringify(reporterConfig),
'control.test.js',
]);
const testOutput = fs.readFileSync(outputFilePath, 'utf8');
try {
jsonResult = JSON.parse(testOutput);
} catch (err) {
throw new Error(
`Can't parse the JSON result from ${outputFileName}, ${err.toString()}`,
);
}
expect(jsonResult.numPassedTests).toBe(0);
expect(jsonResult.numFailedTests).toBe(1);
expect(jsonResult.numPendingTests).toBe(0);
expect(jsonResult.testResults[0].testResults[0].invocations).toBe(1);
});
});