.dependabot
.github
.storybook
cypress
fixtures
integration
plugins
snapshots
support
utils
README.md
config.js
constants.js
dismiss-local-backup.js
mock-server.js
regexp.js
steps.js
Readme.md
dev-test
functions
img
packages
scripts
website
.all-contributorsrc
.editorconfig
.eslintrc.js
.gitignore
.nvmrc
.prettierignore
.prettierrc
.stylelintrc
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
babel.config.js
commitlint.config.js
cypress.json
jest.config.js
lerna.json
netlify.toml
package.json
renovate.json
setupTestFramework.js
tsconfig.json
yarn.lock
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
const { mockServerClient } = require('mockserver-client');
|
|
const mockserver = require('mockserver-node');
|
|
|
|
const PROXY_PORT = 1080;
|
|
const PROXY_HOST = 'localhost';
|
|
|
|
const start = () =>
|
|
mockserver.start_mockserver({
|
|
serverPort: PROXY_PORT,
|
|
});
|
|
|
|
const stop = () =>
|
|
mockserver.stop_mockserver({
|
|
serverPort: PROXY_PORT,
|
|
});
|
|
|
|
const retrieveRecordedExpectations = async () => {
|
|
const promise = new Promise((resolve, reject) => {
|
|
mockServerClient(PROXY_HOST, PROXY_PORT)
|
|
.retrieveRecordedExpectations({})
|
|
.then(resolve, reject);
|
|
});
|
|
|
|
let recorded = await promise;
|
|
recorded = recorded.filter(({ httpRequest }) => {
|
|
const { Host = [] } = httpRequest.headers;
|
|
|
|
// Host is an array of strings
|
|
return (
|
|
Host.includes('api.github.com') ||
|
|
(Host.includes('gitlab.com') && httpRequest.path.includes('api/v4')) ||
|
|
Host.includes('api.bitbucket.org') ||
|
|
(Host.includes('bitbucket.org') && httpRequest.path.includes('info/lfs')) ||
|
|
Host.includes('api.media.atlassian.com') ||
|
|
Host.some(host => host.includes('netlify.com')) ||
|
|
Host.some(host => host.includes('s3.amazonaws.com'))
|
|
);
|
|
});
|
|
|
|
return recorded;
|
|
};
|
|
|
|
const resetMockServerState = async () => {
|
|
const promise = new Promise((resolve, reject) => {
|
|
mockServerClient(PROXY_HOST, PROXY_PORT)
|
|
.reset()
|
|
.then(resolve, reject);
|
|
});
|
|
|
|
await promise;
|
|
};
|
|
|
|
module.exports = {
|
|
start,
|
|
stop,
|
|
resetMockServerState,
|
|
retrieveRecordedExpectations,
|
|
};
|