feat(backend-github): GitHub GraphQL API support (#2456)
* add GitHub GraphQL api initial support * support mutiple backends for e2e tests - initial commit * add github backend e2e test (currently skipped), fix bugs per tests * refactor e2e tests, add fork workflow tests, support fork workflow in GraphQL api * remove log message that might contain authentication token * return empty error when commit is not found when using GraphQL (align with base class) * disable github backend tests * fix bugs introduced after rebase of GraphQL and OpenAuthoring features * test: update tests per openAuthoring changes, split tests into multiple files * fix: pass in headers for pagination requests, avoid async iterator as it requires a polyfill on old browsers * test(e2e): disable github backend tests
This commit is contained in:
committed by
Shawn Erquhart
parent
083a336ba4
commit
ece136c92e
@ -10,8 +10,106 @@
|
||||
|
||||
// This function is called when a project is opened or re-opened (e.g. due to
|
||||
// the project's config changing)
|
||||
require('dotenv').config();
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const yaml = require('js-yaml');
|
||||
const {
|
||||
prepareTestGitHubRepo,
|
||||
deleteRepositories,
|
||||
getUser,
|
||||
getForkUser,
|
||||
resetRepositories,
|
||||
} = require('./github');
|
||||
|
||||
module.exports = (on, config) => {
|
||||
// `on` is used to hook into various events Cypress emits
|
||||
// `config` is the resolved Cypress config
|
||||
const devTestDirectory = path.join(__dirname, '..', '..', 'dev-test');
|
||||
const backendsDirectory = path.join(devTestDirectory, 'backends');
|
||||
|
||||
async function copyBackendFiles(backend) {
|
||||
for (let file of ['config.yml', 'index.html']) {
|
||||
await fs.copyFile(
|
||||
path.join(backendsDirectory, backend, file),
|
||||
path.join(devTestDirectory, file),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateConfig(configModifier) {
|
||||
const configFile = path.join(devTestDirectory, 'config.yml');
|
||||
const configContent = await fs.readFile(configFile);
|
||||
const config = yaml.safeLoad(configContent);
|
||||
await configModifier(config);
|
||||
await fs.writeFileSync(configFile, yaml.safeDump(config));
|
||||
return null;
|
||||
}
|
||||
|
||||
async function setupGitHub() {
|
||||
const [user, forkUser, repoData] = await Promise.all([
|
||||
getUser(),
|
||||
getForkUser(),
|
||||
prepareTestGitHubRepo(),
|
||||
]);
|
||||
|
||||
await updateConfig(config => {
|
||||
config.backend.repo = `${repoData.owner}/${repoData.repo}`;
|
||||
});
|
||||
|
||||
return { ...repoData, user, forkUser };
|
||||
}
|
||||
|
||||
async function teardownGitHub(taskData) {
|
||||
await deleteRepositories(taskData);
|
||||
return null;
|
||||
}
|
||||
|
||||
async function teardownBackendTest(taskData) {
|
||||
await resetRepositories(taskData);
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = async on => {
|
||||
// `on` is used to hook into various events Cypress emits
|
||||
on('task', {
|
||||
async setupBackend({ backend }) {
|
||||
console.log('Preparing environment for backend', backend);
|
||||
await copyBackendFiles(backend);
|
||||
|
||||
if (backend === 'github') {
|
||||
return await setupGitHub();
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
async teardownBackend(taskData) {
|
||||
const { backend } = taskData;
|
||||
console.log('Tearing down backend', backend);
|
||||
if (backend === 'github') {
|
||||
return await teardownGitHub(taskData);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
async teardownBackendTest(taskData) {
|
||||
const { backend } = taskData;
|
||||
console.log('Tearing down single test for backend', backend);
|
||||
if (backend === 'github') {
|
||||
return await teardownBackendTest(taskData);
|
||||
}
|
||||
},
|
||||
async updateBackendOptions({ backend, options }) {
|
||||
console.log('Updating backend', backend, 'with options', options);
|
||||
if (backend === 'github') {
|
||||
return await updateConfig(config => {
|
||||
config.backend = { ...config.backend, ...options };
|
||||
});
|
||||
}
|
||||
return null;
|
||||
},
|
||||
async restoreDefaults() {
|
||||
console.log('Restoring defaults');
|
||||
await copyBackendFiles('test');
|
||||
|
||||
return null;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user