mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-16 15:46:00 +00:00
fix
This commit is contained in:
4
node_modules/snekfetch/test/.eslintrc.json
generated
vendored
Normal file
4
node_modules/snekfetch/test/.eslintrc.json
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": ["../.eslintrc.json"],
|
||||
"env": { "jest": true }
|
||||
}
|
7
node_modules/snekfetch/test/browser/http1.test.js
generated
vendored
Normal file
7
node_modules/snekfetch/test/browser/http1.test.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
global.HTTP_VERSION = 1;
|
||||
|
||||
require('./main');
|
7
node_modules/snekfetch/test/browser/http2.test.js
generated
vendored
Normal file
7
node_modules/snekfetch/test/browser/http2.test.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
global.HTTP_VERSION = 2;
|
||||
|
||||
require('./main');
|
5
node_modules/snekfetch/test/browser/main.js
generated
vendored
Normal file
5
node_modules/snekfetch/test/browser/main.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
window.fetch = require('node-fetch');
|
||||
window.URLSearchParams = require('url').URLSearchParams;
|
||||
window.FormData = require('form-data');
|
||||
|
||||
require('../main');
|
22
node_modules/snekfetch/test/interop.js
generated
vendored
Normal file
22
node_modules/snekfetch/test/interop.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
function makeProxy(fetch) {
|
||||
return new Proxy(fetch, {
|
||||
get(target, prop) {
|
||||
const p = target[prop];
|
||||
if (typeof p === 'function') {
|
||||
return (url, options = {}) =>
|
||||
p.call(target, url, Object.assign(options, { version: global.HTTP_VERSION }));
|
||||
}
|
||||
return p;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
exports.Snekfetch = makeProxy(require('../'));
|
||||
try {
|
||||
exports.SnekfetchSync = makeProxy(require('../sync'));
|
||||
} catch (err) {} // eslint-disable-line no-empty
|
||||
|
||||
exports.TestRoot = global.HTTP_VERSION === 2 ?
|
||||
'https://nghttp2.org/httpbin' :
|
||||
'https://httpbin.org';
|
||||
|
152
node_modules/snekfetch/test/main.js
generated
vendored
Normal file
152
node_modules/snekfetch/test/main.js
generated
vendored
Normal file
@ -0,0 +1,152 @@
|
||||
const { Snekfetch, TestRoot } = require('./interop');
|
||||
|
||||
const server = require('./server');
|
||||
|
||||
function makeTestObj({ unicode = true, numbers = false } = {}) {
|
||||
const test = {
|
||||
Hello: 'world',
|
||||
Test: numbers ? 1337 : '1337',
|
||||
};
|
||||
if (unicode)
|
||||
test.Unicode = '( ͡° ͜ʖ ͡°)';
|
||||
return {
|
||||
test,
|
||||
check: (obj) => {
|
||||
expect(obj).not.toBeUndefined();
|
||||
expect(obj.Hello).toBe(test.Hello);
|
||||
expect(obj.Test).toBe(test.Test);
|
||||
if (unicode)
|
||||
expect(obj.Unicode).toBe(test.Unicode);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('should return a promise', () => {
|
||||
expect(Snekfetch.get(`${TestRoot}/get`).end())
|
||||
.toBeInstanceOf(Promise);
|
||||
});
|
||||
|
||||
test('should reject with error on network failure', () => {
|
||||
const invalid = 'http://localhost:0/';
|
||||
/* https://gc.gy/❥ȗ.png
|
||||
return expect(Snekfetch.get(invalid).end())
|
||||
.rejects.toBeInstanceOf(Error);*/
|
||||
return Snekfetch.get(invalid).catch((err) => {
|
||||
expect(err.name).toMatch(/(Fetch)?Error/);
|
||||
});
|
||||
});
|
||||
|
||||
test('should resolve on success', () =>
|
||||
Snekfetch.get(`${TestRoot}/get`).then((res) => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.ok).toBe(true);
|
||||
expect(res).toHaveProperty('text');
|
||||
expect(res).toHaveProperty('body');
|
||||
})
|
||||
);
|
||||
|
||||
test('end should work', () =>
|
||||
Snekfetch.get(`${TestRoot}/get`).end((err, res) => {
|
||||
expect(err).toBe(null);
|
||||
expect(res.body).not.toBeUndefined();
|
||||
})
|
||||
);
|
||||
|
||||
test('should reject if response is not between 200 and 300', () =>
|
||||
Snekfetch.get(`${TestRoot}/404`).catch((err) => {
|
||||
expect(err.status).toBe(404);
|
||||
expect(err.ok).toBe(false);
|
||||
})
|
||||
);
|
||||
|
||||
test('unzipping works', () =>
|
||||
Snekfetch.get(`${TestRoot}/gzip`)
|
||||
.then((res) => {
|
||||
expect(res.body).not.toBeUndefined();
|
||||
expect(res.body.gzipped).toBe(true);
|
||||
})
|
||||
);
|
||||
|
||||
test('query should work', () => {
|
||||
const { test, check } = makeTestObj();
|
||||
Promise.all([
|
||||
Snekfetch.get(`${TestRoot}/get?inline=true`)
|
||||
.query(test).end(),
|
||||
Snekfetch.get(`${TestRoot}/get?inline=true`, { query: test })
|
||||
.end(),
|
||||
])
|
||||
.then((ress) => {
|
||||
for (const res of ress) {
|
||||
const { args } = res.body;
|
||||
check(args);
|
||||
expect(args.inline).toBe('true');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('headers should work', () => {
|
||||
const { test, check } = makeTestObj({ unicode: false });
|
||||
return Promise.all([
|
||||
Snekfetch.get(`${TestRoot}/get`)
|
||||
.set(test).end(),
|
||||
Snekfetch.get(`${TestRoot}/get`, { headers: test })
|
||||
.end(),
|
||||
])
|
||||
.then((ress) => {
|
||||
for (const res of ress)
|
||||
check(res.body.headers);
|
||||
});
|
||||
});
|
||||
|
||||
test('attach should work', () => {
|
||||
const { test, check } = makeTestObj();
|
||||
return Snekfetch.post(`${TestRoot}/post`)
|
||||
.attach(test)
|
||||
.then((res) => check(res.body.form));
|
||||
});
|
||||
|
||||
test('send should work with json', () => {
|
||||
const { test, check } = makeTestObj({ numbers: true });
|
||||
return Promise.all([
|
||||
Snekfetch.post(`${TestRoot}/post`)
|
||||
.send(test).end(),
|
||||
Snekfetch.post(`${TestRoot}/post`, { data: test })
|
||||
.end(),
|
||||
])
|
||||
.then((ress) => {
|
||||
for (const res of ress)
|
||||
check(res.body.json);
|
||||
});
|
||||
});
|
||||
|
||||
test('send should work with urlencoded', () => {
|
||||
const { test, check } = makeTestObj();
|
||||
return Snekfetch.post(`${TestRoot}/post`)
|
||||
.set('content-type', 'application/x-www-form-urlencoded')
|
||||
.send(test)
|
||||
.then((res) => check(res.body.form));
|
||||
});
|
||||
|
||||
test('invalid json is just text', () =>
|
||||
Snekfetch.get(`http://localhost:${server.port}/invalid-json`)
|
||||
.then((res) => {
|
||||
expect(res.body).toBe('{ "a": 1');
|
||||
})
|
||||
);
|
||||
|
||||
test('x-www-form-urlencoded response body', () =>
|
||||
Snekfetch.get(`http://localhost:${server.port}/form-urlencoded`)
|
||||
.then((res) => {
|
||||
const { body } = res;
|
||||
expect(body.test).toBe('1');
|
||||
expect(body.hello).toBe('world');
|
||||
})
|
||||
);
|
||||
|
||||
test('redirects', () =>
|
||||
Snekfetch.get(`${TestRoot}/redirect/1`)
|
||||
.then((res) => {
|
||||
expect(res.body).not.toBeUndefined();
|
||||
expect(res.body.url).toBe(`${TestRoot}/get`);
|
||||
})
|
||||
);
|
47
node_modules/snekfetch/test/node/file.test.js
generated
vendored
Normal file
47
node_modules/snekfetch/test/node/file.test.js
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const { Snekfetch } = require('../interop');
|
||||
|
||||
const resolve = (x) => require.resolve(x);
|
||||
|
||||
test('node/file get', () => {
|
||||
const original = fs.readFileSync(resolve('../../package.json')).toString();
|
||||
return Snekfetch.get(`file://${resolve('../../package.json')}`)
|
||||
.then((res) => {
|
||||
expect(res.text).toBe(original);
|
||||
});
|
||||
});
|
||||
|
||||
test('node/file post', () => {
|
||||
const content = 'wow this is a\n\ntest!!';
|
||||
const file = './test_file_post.txt';
|
||||
return Snekfetch.post(`file://${file}`)
|
||||
.send(content)
|
||||
.then(() => Snekfetch.get(`file://${file}`))
|
||||
.then((res) => {
|
||||
expect(res.text).toBe(content);
|
||||
})
|
||||
.then(() => {
|
||||
fs.unlinkSync(file);
|
||||
});
|
||||
});
|
||||
|
||||
test('node/file delete', () => {
|
||||
const file = './test_file_delete.txt';
|
||||
fs.closeSync(fs.openSync(file, 'w'));
|
||||
expect(fs.existsSync(file)).toBe(true);
|
||||
return Snekfetch.delete(`file://${file}`)
|
||||
.then(() => {
|
||||
expect(fs.existsSync(file)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('node/file invalid method', () => {
|
||||
expect(() => {
|
||||
Snekfetch.options('file:///dev/urandom');
|
||||
}).toThrow(/Invalid request method for file:/);
|
||||
});
|
7
node_modules/snekfetch/test/node/http1.test.js
generated
vendored
Normal file
7
node_modules/snekfetch/test/node/http1.test.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
global.HTTP_VERSION = 1;
|
||||
|
||||
require('./main');
|
7
node_modules/snekfetch/test/node/http2.test.js.disabled
generated
vendored
Normal file
7
node_modules/snekfetch/test/node/http2.test.js.disabled
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
global.HTTP_VERSION = 2;
|
||||
|
||||
require('./main');
|
26
node_modules/snekfetch/test/node/main.js
generated
vendored
Normal file
26
node_modules/snekfetch/test/node/main.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const { Snekfetch, TestRoot } = require('../interop');
|
||||
|
||||
require('../main');
|
||||
|
||||
test('node/pipe get', (done) => {
|
||||
Snekfetch.get(`${TestRoot}/get`)
|
||||
.pipe(fs.createWriteStream('/dev/null'))
|
||||
.on('finish', done);
|
||||
});
|
||||
|
||||
|
||||
test('node/FormData json works', () =>
|
||||
Snekfetch.post(`${TestRoot}/post`)
|
||||
.attach('object', { a: 1 })
|
||||
.then((res) => {
|
||||
const { form } = res.body;
|
||||
expect(form.object).toBe('{"a":1}');
|
||||
})
|
||||
);
|
||||
|
||||
test('node/rawsend post', () =>
|
||||
Snekfetch.post(`${TestRoot}/post`)
|
||||
.send(Buffer.from('memes')).end()
|
||||
);
|
10
node_modules/snekfetch/test/node/sync.test.js
generated
vendored
Normal file
10
node_modules/snekfetch/test/node/sync.test.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
const { SnekfetchSync, TestRoot } = require('../interop');
|
||||
|
||||
test('sync get', SnekfetchSync && (() => {
|
||||
const res = SnekfetchSync.get(`${TestRoot}/get`).end();
|
||||
expect(res.body).not.toBeUndefined();
|
||||
}));
|
17
node_modules/snekfetch/test/node/util.test.js
generated
vendored
Normal file
17
node_modules/snekfetch/test/node/util.test.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
const FormData = require('../../src/node/FormData');
|
||||
const mime = require('../../src/node/mime');
|
||||
|
||||
test('node/FormData behaves predictably', () => {
|
||||
const f = new FormData();
|
||||
f.append('hello');
|
||||
f.append('hello', 'world');
|
||||
expect(f.length).toBe(77);
|
||||
f.append('meme', 'dream', 'name');
|
||||
expect(f.length).toBe(210);
|
||||
});
|
||||
|
||||
test('node/mimes behaves predictably', () => {
|
||||
expect(mime.lookup('js')).toBe('application/javascript');
|
||||
expect(mime.lookup('nope')).toBe('application/octet-stream');
|
||||
expect(mime.buffer([0xFF, 0xD8, 0xFF])).toBe('image/jpeg');
|
||||
});
|
41
node_modules/snekfetch/test/server.js
generated
vendored
Normal file
41
node_modules/snekfetch/test/server.js
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
const http = require('http');
|
||||
|
||||
const ref = require.main === module;
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
if (!ref)
|
||||
req.connection.unref();
|
||||
switch (req.url) {
|
||||
case '/invalid-json':
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end('{ "a": 1');
|
||||
break;
|
||||
case '/form-urlencoded':
|
||||
res.setHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
res.end('test=1&hello=world');
|
||||
break;
|
||||
case '/echo': {
|
||||
let body = '';
|
||||
req.on('data', (c) => { body += c; });
|
||||
req.on('end', () => {
|
||||
res.end(body);
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
res.end();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
server.on('connection', (socket) => {
|
||||
if (!ref)
|
||||
socket.unref();
|
||||
});
|
||||
|
||||
server.listen(0);
|
||||
|
||||
exports.port = server.address().port;
|
||||
|
||||
if (ref)
|
||||
console.log(exports.port); // eslint-disable-line no-console
|
Reference in New Issue
Block a user