test(cypress-github-backend): optionally record tests and run using recorded data (#2776)
This commit is contained in:
committed by
Shawn Erquhart
parent
0f60a559c1
commit
b869ce05ae
@ -19,29 +19,25 @@ import {
|
||||
} from '../../utils/steps';
|
||||
import { workflowStatus, editorStatus } from '../../utils/constants';
|
||||
import { entry1, entry2, entry3 } from './entries';
|
||||
import * as specUtils from './spec_utils';
|
||||
|
||||
export default function({ use_graphql }) {
|
||||
let taskResult = { data: {} };
|
||||
|
||||
const backend = 'github';
|
||||
|
||||
before(() => {
|
||||
Cypress.config('taskTimeout', 1200000);
|
||||
Cypress.config('defaultCommandTimeout', 60000);
|
||||
cy.task('setupBackend', { backend }).then(data => {
|
||||
taskResult.data = data;
|
||||
});
|
||||
|
||||
cy.task('updateBackendOptions', { backend, options: { use_graphql, open_authoring: false } });
|
||||
specUtils.before(taskResult, { use_graphql, open_authoring: false });
|
||||
});
|
||||
|
||||
after(() => {
|
||||
cy.task('teardownBackend', { backend, ...taskResult.data });
|
||||
cy.task('restoreDefaults');
|
||||
specUtils.after(taskResult);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
specUtils.beforeEach(taskResult);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cy.task('teardownBackendTest', { backend, ...taskResult.data });
|
||||
specUtils.afterEach(taskResult);
|
||||
});
|
||||
|
||||
it('successfully loads', () => {
|
||||
|
@ -10,28 +10,25 @@ import {
|
||||
} from '../../utils/steps';
|
||||
import { workflowStatus } from '../../utils/constants';
|
||||
import { entry1, entry2 } from './entries';
|
||||
import * as specUtils from './spec_utils';
|
||||
|
||||
export default function({ use_graphql }) {
|
||||
let taskResult = { data: {} };
|
||||
|
||||
const backend = 'github';
|
||||
|
||||
before(() => {
|
||||
Cypress.config('taskTimeout', 1200000);
|
||||
Cypress.config('defaultCommandTimeout', 60000);
|
||||
cy.task('setupBackend', { backend }).then(data => {
|
||||
taskResult.data = data;
|
||||
});
|
||||
cy.task('updateBackendOptions', { backend, options: { use_graphql, open_authoring: true } });
|
||||
specUtils.before(taskResult, { use_graphql, open_authoring: true });
|
||||
});
|
||||
|
||||
after(() => {
|
||||
cy.task('teardownBackend', { backend, ...taskResult.data });
|
||||
cy.task('restoreDefaults');
|
||||
specUtils.after(taskResult);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
specUtils.beforeEach(taskResult);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cy.task('teardownBackendTest', { backend, ...taskResult.data });
|
||||
specUtils.afterEach(taskResult);
|
||||
});
|
||||
|
||||
it('successfully loads', () => {
|
||||
|
51
cypress/integration/github/spec_utils.js
Normal file
51
cypress/integration/github/spec_utils.js
Normal file
@ -0,0 +1,51 @@
|
||||
const backend = 'github';
|
||||
|
||||
export const before = (taskResult, options) => {
|
||||
Cypress.config('taskTimeout', 5 * 60 * 1000);
|
||||
cy.task('setupBackend', { backend, options }).then(data => {
|
||||
taskResult.data = data;
|
||||
Cypress.config('defaultCommandTimeout', data.mockResponses ? 5 * 1000 : 1 * 60 * 1000);
|
||||
});
|
||||
};
|
||||
|
||||
export const after = taskResult => {
|
||||
cy.task('teardownBackend', {
|
||||
backend,
|
||||
...taskResult.data,
|
||||
});
|
||||
};
|
||||
|
||||
export const beforeEach = taskResult => {
|
||||
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 => {
|
||||
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 (Cypress.mocha.getRunner().suite.ctx.currentTest.state === 'failed') {
|
||||
Cypress.runner.stop();
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user