1 |
|
2 | 'use strict'
|
3 |
|
4 | const { Buffer } = require('buffer')
|
5 |
|
6 | module.exports = function loadFixtures (filePath, module) {
|
7 | if (module) {
|
8 | filePath = 'node_modules/' + module + '/' + filePath
|
9 | }
|
10 | return syncXhr(filePath)
|
11 | }
|
12 |
|
13 |
|
14 |
|
15 | function syncXhr (filePath) {
|
16 | const target = '/base/' + filePath
|
17 |
|
18 | const request = new self.XMLHttpRequest()
|
19 | request.open('GET', target, false)
|
20 | request.overrideMimeType('text/plain; charset=x-user-defined')
|
21 | request.send(null)
|
22 |
|
23 | if (request.status === 200) {
|
24 | const filestream = request.responseText
|
25 | const res = new Uint8Array(filestream.length)
|
26 |
|
27 | for (let i = 0; i < filestream.length; i++) {
|
28 | res[i] = filestream.charCodeAt(i) & 0xff
|
29 | }
|
30 |
|
31 | return Buffer.from(res)
|
32 | } else {
|
33 | throw new Error(`Could not get the Fixture: ${filePath}`)
|
34 | }
|
35 | }
|