summaryrefslogtreecommitdiff
path: root/node_modules/snekfetch/test
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/snekfetch/test')
-rw-r--r--node_modules/snekfetch/test/.eslintrc.json4
-rw-r--r--node_modules/snekfetch/test/browser/http1.test.js7
-rw-r--r--node_modules/snekfetch/test/browser/http2.test.js7
-rw-r--r--node_modules/snekfetch/test/browser/main.js5
-rw-r--r--node_modules/snekfetch/test/interop.js22
-rw-r--r--node_modules/snekfetch/test/main.js152
-rw-r--r--node_modules/snekfetch/test/node/file.test.js47
-rw-r--r--node_modules/snekfetch/test/node/http1.test.js7
-rw-r--r--node_modules/snekfetch/test/node/http2.test.js.disabled7
-rw-r--r--node_modules/snekfetch/test/node/main.js26
-rw-r--r--node_modules/snekfetch/test/node/sync.test.js10
-rw-r--r--node_modules/snekfetch/test/node/util.test.js17
-rw-r--r--node_modules/snekfetch/test/server.js41
13 files changed, 0 insertions, 352 deletions
diff --git a/node_modules/snekfetch/test/.eslintrc.json b/node_modules/snekfetch/test/.eslintrc.json
deleted file mode 100644
index 063ae8c..0000000
--- a/node_modules/snekfetch/test/.eslintrc.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "extends": ["../.eslintrc.json"],
- "env": { "jest": true }
-}
diff --git a/node_modules/snekfetch/test/browser/http1.test.js b/node_modules/snekfetch/test/browser/http1.test.js
deleted file mode 100644
index 8ce2b94..0000000
--- a/node_modules/snekfetch/test/browser/http1.test.js
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * @jest-environment jsdom
- */
-
-global.HTTP_VERSION = 1;
-
-require('./main');
diff --git a/node_modules/snekfetch/test/browser/http2.test.js b/node_modules/snekfetch/test/browser/http2.test.js
deleted file mode 100644
index 19c51cf..0000000
--- a/node_modules/snekfetch/test/browser/http2.test.js
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * @jest-environment jsdom
- */
-
-global.HTTP_VERSION = 2;
-
-require('./main');
diff --git a/node_modules/snekfetch/test/browser/main.js b/node_modules/snekfetch/test/browser/main.js
deleted file mode 100644
index 7562ace..0000000
--- a/node_modules/snekfetch/test/browser/main.js
+++ /dev/null
@@ -1,5 +0,0 @@
-window.fetch = require('node-fetch');
-window.URLSearchParams = require('url').URLSearchParams;
-window.FormData = require('form-data');
-
-require('../main');
diff --git a/node_modules/snekfetch/test/interop.js b/node_modules/snekfetch/test/interop.js
deleted file mode 100644
index d63ff10..0000000
--- a/node_modules/snekfetch/test/interop.js
+++ /dev/null
@@ -1,22 +0,0 @@
-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';
-
diff --git a/node_modules/snekfetch/test/main.js b/node_modules/snekfetch/test/main.js
deleted file mode 100644
index 87f60fc..0000000
--- a/node_modules/snekfetch/test/main.js
+++ /dev/null
@@ -1,152 +0,0 @@
-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`);
- })
-);
diff --git a/node_modules/snekfetch/test/node/file.test.js b/node_modules/snekfetch/test/node/file.test.js
deleted file mode 100644
index 8ec0fd0..0000000
--- a/node_modules/snekfetch/test/node/file.test.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * @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:/);
-});
diff --git a/node_modules/snekfetch/test/node/http1.test.js b/node_modules/snekfetch/test/node/http1.test.js
deleted file mode 100644
index 00f91f4..0000000
--- a/node_modules/snekfetch/test/node/http1.test.js
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * @jest-environment node
- */
-
-global.HTTP_VERSION = 1;
-
-require('./main');
diff --git a/node_modules/snekfetch/test/node/http2.test.js.disabled b/node_modules/snekfetch/test/node/http2.test.js.disabled
deleted file mode 100644
index daf49d9..0000000
--- a/node_modules/snekfetch/test/node/http2.test.js.disabled
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * @jest-environment node
- */
-
-global.HTTP_VERSION = 2;
-
-require('./main');
diff --git a/node_modules/snekfetch/test/node/main.js b/node_modules/snekfetch/test/node/main.js
deleted file mode 100644
index b811ec9..0000000
--- a/node_modules/snekfetch/test/node/main.js
+++ /dev/null
@@ -1,26 +0,0 @@
-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()
-);
diff --git a/node_modules/snekfetch/test/node/sync.test.js b/node_modules/snekfetch/test/node/sync.test.js
deleted file mode 100644
index 0c7187f..0000000
--- a/node_modules/snekfetch/test/node/sync.test.js
+++ /dev/null
@@ -1,10 +0,0 @@
-/**
- * @jest-environment node
- */
-
-const { SnekfetchSync, TestRoot } = require('../interop');
-
-test('sync get', SnekfetchSync && (() => {
- const res = SnekfetchSync.get(`${TestRoot}/get`).end();
- expect(res.body).not.toBeUndefined();
-}));
diff --git a/node_modules/snekfetch/test/node/util.test.js b/node_modules/snekfetch/test/node/util.test.js
deleted file mode 100644
index 1e71573..0000000
--- a/node_modules/snekfetch/test/node/util.test.js
+++ /dev/null
@@ -1,17 +0,0 @@
-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');
-});
diff --git a/node_modules/snekfetch/test/server.js b/node_modules/snekfetch/test/server.js
deleted file mode 100644
index ac75cca..0000000
--- a/node_modules/snekfetch/test/server.js
+++ /dev/null
@@ -1,41 +0,0 @@
-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