Skip to content

Commit

Permalink
refactor(msw): get rid of url-join
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuel Kluge committed Jul 1, 2021
1 parent ca69e6b commit fda4320
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 4 additions & 5 deletions packages/msw/integration.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// @ts-check

const { fetch } = require('cross-fetch');
const joinUrl = require('url-join');

const getMockEndpoint = () => {
const getMockEndpoint = (pathName) => {
if (typeof process.env.MOCK_HOST !== 'string') {
throw new Error('Please define MOCK_HOST.');
}

return new URL(process.env.MOCK_HOST).toString();
return new URL(pathName, process.env.MOCK_HOST).toString();
};

/** @type {import('hops-msw/integration').mockGraphQLQuery} */
Expand Down Expand Up @@ -73,7 +72,7 @@ const mockDeleteRequest = (pathName, data) => {

/** @type {import('hops-msw/integration').registerServerMocks} */
const registerServerMocks = async (...mocks) => {
await fetch(joinUrl(getMockEndpoint(), '/_mocks/register'), {
await fetch(getMockEndpoint('/_mocks/register'), {
method: 'POST',
headers: {
'content-type': 'application/json',
Expand All @@ -84,7 +83,7 @@ const registerServerMocks = async (...mocks) => {

/** @type {import('hops-msw/integration').resetServerMocks} */
const resetServerMocks = async () => {
await fetch(joinUrl(getMockEndpoint(), '/_mocks/reset'));
await fetch(getMockEndpoint('/_mocks/reset'));
};

module.exports = {
Expand Down
3 changes: 1 addition & 2 deletions packages/msw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"cross-fetch": "^3.1.4",
"execa": "^5.1.1",
"hops-mixin": "15.0.0-nightly.6",
"msw": "^0.30.0",
"url-join": "^4.0.1"
"msw": "^0.30.0"
},
"homepage": "https://github.com/xing/hops/tree/master/packages/msw#readme"
}

0 comments on commit fda4320

Please sign in to comment.