-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathspec_utils.js
More file actions
91 lines (79 loc) · 3.03 KB
/
spec_utils.js
File metadata and controls
91 lines (79 loc) · 3.03 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
export function before(taskResult, options, backend) {
console.log(`[spec_utils.before] START backend=${backend}`);
Cypress.config('taskTimeout', 5 * 60 * 1000); // 5 minutes
cy.task('setupBackend', { backend, options }).then(data => {
console.log('[spec_utils.before] setupBackend completed, data=', data);
taskResult.data = data;
Cypress.config('defaultCommandTimeout', data.mockResponses ? 5 * 1000 : 1 * 60 * 1000);
console.log(`[spec_utils.before] COMPLETE mockResponses=${data.mockResponses} timeout=${data.mockResponses ? 5000 : 60000}ms`);
});
}
export function after(taskResult, backend) {
console.log(`[spec_utils.after] START backend=${backend}`);
cy.task('teardownBackend', {
backend,
...taskResult.data,
}).then(() => {
console.log('[spec_utils.after] COMPLETE');
});
}
export function beforeEach(taskResult, backend) {
const spec = Cypress.mocha.getRunner().suite.ctx.currentTest.parent.title;
const testName = Cypress.mocha.getRunner().suite.ctx.currentTest.title;
console.log(`[spec_utils.beforeEach] START backend=${backend} spec="${spec}" test="${testName}"`);
console.log(`[spec_utils.beforeEach] mockResponses=${taskResult.data.mockResponses}`);
console.log(`[spec_utils.beforeEach] user=`, JSON.stringify(taskResult.data.user || {}));
cy.task('setupBackendTest', {
backend,
...taskResult.data,
spec,
testName,
}).then(() => {
console.log('[spec_utils.beforeEach] setupBackendTest completed');
});
if (taskResult.data.mockResponses) {
const fixture = `${spec}__${testName}.json`;
console.log(`[spec_utils.beforeEach] Loading fixture: ${fixture}`);
cy.stubFetch({ fixture }).then(() => {
console.log('[spec_utils.beforeEach] stubFetch completed');
});
} else {
console.log('[spec_utils.beforeEach] WARNING: mockResponses is false/undefined - no fixture loaded');
}
// cy.clock(0, ['Date']) was hanging git-gateway tests after page load
// Hypothesis: freezing time to 0 breaks app initialization during cy.visit()
// Temporary fix: skip cy.clock for git-gateway, use default clock for others
if (backend !== 'git-gateway') {
console.log('[spec_utils.beforeEach] Setting clock to epoch 0');
return cy.clock(0, ['Date']);
}
console.log('[spec_utils.beforeEach] COMPLETE - skipped clock for git-gateway');
}
export function afterEach(taskResult, backend) {
const spec = Cypress.mocha.getRunner().suite.ctx.currentTest.parent.title;
const testName = Cypress.mocha.getRunner().suite.ctx.currentTest.title;
cy.task('teardownBackendTest', {
backend,
...taskResult.data,
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 function seedRepo(taskResult, backend) {
cy.task('seedRepo', {
backend,
...taskResult.data,
});
}