Skip to content

Commit

Permalink
fix: stub sdk-test-helpers in browser environments (#132)
Browse files Browse the repository at this point in the history
The "sdk-test-helpers" file contains helper functions that generated SDKs use
in their generated unit tests. These functions are never actually needed when
running standard operational code, therefore they are never used in the browser.

The `expect` library that we use for testing has a dependency that isn't browser
friendly in certain scenarios. This causes the core and any SDKs importing it
to throw errors in these scenarios (like the React framework).

This change stubs the sdk-test-helpers in browser environments the same way we
stub the credentials file reading code.
  • Loading branch information
dpopp07 authored Apr 1, 2021
1 parent 43074a9 commit 006991b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/sdk-test-helpers.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Dummy for browser
export function checkUrlAndMethod(options, url: string, method: any) {
return;
};

export function checkMediaHeaders(createRequestMock, accept: string, contentType: string) {
return;
};

export function checkUserHeader(createRequestMock, userHeaderName: string, userHeaderValue: string) {
return;
};

export function checkForSuccessfulExecution(createRequestMock) {
return;
};

export function getOptions(createRequestMock) {
return;
};

export function expectToBePromise(sdkPromise) {
return;
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"tough-cookie": "^4.0.0"
},
"browser": {
"./auth/utils/read-credentials-file": "./auth/utils/read-credentials-file.browser"
"./auth/utils/read-credentials-file": "./auth/utils/read-credentials-file.browser",
"./lib/sdk-test-helpers": "./lib/sdk-test-helpers.browser"
},
"engines": {
"node": ">=10"
Expand Down

0 comments on commit 006991b

Please sign in to comment.