feat: v4.0.0 (#1016)
Co-authored-by: Denys Konovalov <kontakt@denyskon.de> Co-authored-by: Mathieu COSYNS <64072917+Mathieu-COSYNS@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
682576ffc4
commit
799c7e6936
80
cypress/plugins/common.js
Normal file
80
cypress/plugins/common.js
Normal file
@ -0,0 +1,80 @@
|
||||
const path = require('path');
|
||||
const { default: simpleGit } = require('simple-git');
|
||||
|
||||
const GIT_SSH_COMMAND = 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no';
|
||||
const GIT_SSL_NO_VERIFY = true;
|
||||
|
||||
const getExpectationsFilename = taskData => {
|
||||
const { spec, testName } = taskData;
|
||||
const basename = `${spec}__${testName}`;
|
||||
const fixtures = path.join(__dirname, '..', 'fixtures');
|
||||
const filename = path.join(fixtures, `${basename}.json`);
|
||||
|
||||
return filename;
|
||||
};
|
||||
|
||||
const HEADERS_TO_IGNORE = [
|
||||
'Date',
|
||||
'X-RateLimit-Remaining',
|
||||
'X-RateLimit-Reset',
|
||||
'ETag',
|
||||
'Last-Modified',
|
||||
'X-GitHub-Request-Id',
|
||||
'X-NF-Request-ID',
|
||||
'X-Request-Id',
|
||||
'X-Runtime',
|
||||
'RateLimit-Limit',
|
||||
'RateLimit-Observed',
|
||||
'RateLimit-Remaining',
|
||||
'RateLimit-Reset',
|
||||
'RateLimit-ResetTime',
|
||||
'GitLab-LB',
|
||||
].map(h => h.toLowerCase());
|
||||
|
||||
const transformRecordedData = (expectation, requestBodySanitizer, responseBodySanitizer) => {
|
||||
const { httpRequest, httpResponse } = expectation;
|
||||
|
||||
const responseHeaders = {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
};
|
||||
|
||||
Object.keys(httpResponse.headers)
|
||||
.filter(key => !HEADERS_TO_IGNORE.includes(key.toLowerCase()))
|
||||
.forEach(key => {
|
||||
responseHeaders[key] = httpResponse.headers[key][0];
|
||||
});
|
||||
|
||||
let queryString;
|
||||
if (httpRequest.queryStringParameters) {
|
||||
const { queryStringParameters } = httpRequest;
|
||||
|
||||
queryString = Object.keys(queryStringParameters)
|
||||
.map(key => `${key}=${queryStringParameters[key]}`)
|
||||
.join('&');
|
||||
}
|
||||
|
||||
const body = requestBodySanitizer(httpRequest);
|
||||
const responseBody = responseBodySanitizer(httpRequest, httpResponse);
|
||||
|
||||
const cypressRouteOptions = {
|
||||
body,
|
||||
method: httpRequest.method,
|
||||
url: queryString ? `${httpRequest.path}?${queryString}` : httpRequest.path,
|
||||
headers: responseHeaders,
|
||||
response: responseBody,
|
||||
status: httpResponse.statusCode,
|
||||
};
|
||||
|
||||
return cypressRouteOptions;
|
||||
};
|
||||
|
||||
function getGitClient(repoDir) {
|
||||
const git = simpleGit(repoDir).env({ ...process.env, GIT_SSH_COMMAND, GIT_SSL_NO_VERIFY });
|
||||
return git;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getExpectationsFilename,
|
||||
transformRecordedData,
|
||||
getGitClient,
|
||||
};
|
Reference in New Issue
Block a user