Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#454@trivial: Continues on making Window a VM context.
- Loading branch information
1 parent
0a670ad
commit 546c10a
Showing
6 changed files
with
104 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
global.mockedModules = { | ||
'sync-request': { | ||
statusCode: null, | ||
body: null, | ||
options: null | ||
}, | ||
'node-fetch': { | ||
url: null, | ||
init: null, | ||
error: null, | ||
response: { | ||
arrayBuffer: Symbol('arrayBuffer'), | ||
blob: Symbol('blob'), | ||
buffer: Symbol('buffer'), | ||
json: Symbol('json'), | ||
text: Symbol('text'), | ||
textConverted: Symbol('textConverted') | ||
} | ||
} | ||
}; | ||
|
||
jest.mock('sync-request', () => (method, url) => { | ||
global.mockedModules['sync-request'].options = { | ||
method, | ||
url | ||
}; | ||
return { | ||
getBody: () => global.mockedModules['sync-request'].body, | ||
isError: () => global.mockedModules['sync-request'].statusCode !== 200, | ||
statusCode: global.mockedModules['sync-request'].statusCode | ||
}; | ||
}); | ||
|
||
/* eslint-disable jsdoc/require-jsdoc */ | ||
class NodeFetchResponse { | ||
arrayBuffer() { | ||
return Promise.resolve(global.mockedModules['node-fetch'].response.arrayBuffer); | ||
} | ||
blob() { | ||
return Promise.resolve(global.mockedModules['node-fetch'].response.blob); | ||
} | ||
buffer() { | ||
return Promise.resolve(global.mockedModules['node-fetch'].response.buffer); | ||
} | ||
json() { | ||
return Promise.resolve(global.mockedModules['node-fetch'].response.json); | ||
} | ||
text() { | ||
return Promise.resolve(global.mockedModules['node-fetch'].response.text); | ||
} | ||
textConverted() { | ||
return Promise.resolve(global.mockedModules['node-fetch'].response.textConverted); | ||
} | ||
} | ||
|
||
class NodeFetchRequest extends NodeFetchResponse {} | ||
class NodeFetchHeaders {} | ||
|
||
jest.mock('node-fetch', () => { | ||
return Object.assign( | ||
(url, options) => { | ||
global.mockedModules['node-fetch'].url = url; | ||
global.mockedModules['node-fetch'].init = options; | ||
if (global.mockedModules['node-fetch'].error) { | ||
return Promise.reject(global.mockedModules['node-fetch'].error); | ||
} | ||
return Promise.resolve(new NodeFetchResponse()); | ||
}, | ||
{ | ||
Response: NodeFetchResponse, | ||
Request: NodeFetchRequest, | ||
Headers: NodeFetchHeaders | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters