-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathspec_utils.js
More file actions
71 lines (62 loc) · 1.89 KB
/
spec_utils.js
File metadata and controls
71 lines (62 loc) · 1.89 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
export const before = (taskResult, options, backend) => {
Cypress.config('taskTimeout', 5 * 60 * 1000); // 5 minutes
cy.task('setupBackend', { backend, options }).then(data => {
taskResult.data = data;
Cypress.config('defaultCommandTimeout', data.mockResponses ? 5 * 1000 : 1 * 60 * 1000);
});
};
export const after = (taskResult, backend) => {
cy.task('teardownBackend', {
backend,
...taskResult.data,
});
};
export const beforeEach = (taskResult, backend) => {
const spec = Cypress.mocha.getRunner().suite.ctx.currentTest.parent.title;
const testName = Cypress.mocha.getRunner().suite.ctx.currentTest.title;
cy.task('setupBackendTest', {
backend,
...taskResult.data,
spec,
testName,
});
if (taskResult.data.mockResponses) {
const fixture = `${spec}__${testName}.json`;
console.log('loading fixture:', fixture);
cy.stubFetch({ fixture });
}
return cy.clock(0, ['Date']);
};
export const afterEach = (taskResult, backend) => {
const spec = Cypress.mocha.getRunner().suite.ctx.currentTest.parent.title;
const testName = Cypress.mocha.getRunner().suite.ctx.currentTest.title;
console.log(`Starting teardown for: ${spec} - ${testName}`);
const startTime = Date.now();
cy.task('teardownBackendTest', {
backend,
...taskResult.data,
spec,
testName,
}).then(() => {
const duration = Date.now() - startTime;
console.log(`Teardown completed in ${duration}ms for: ${spec} - ${testName}`);
});
if (!process.env.RECORD_FIXTURES) {
const {
suite: {
ctx: {
currentTest: { state, _retries: retries, _currentRetry: currentRetry },
},
},
} = Cypress.mocha.getRunner();
if (state === 'failed' && retries === currentRetry) {
Cypress.runner.stop();
}
}
};
export const seedRepo = (taskResult, backend) => {
cy.task('seedRepo', {
backend,
...taskResult.data,
});
};