summaryrefslogtreecommitdiff
path: root/node_modules/snekfetch/test/node
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-03 02:37:42 -0700
committer8cy <[email protected]>2020-04-03 02:37:42 -0700
commit60867fb030bae582082340ead7dbc7efdc2f5398 (patch)
tree4c6a7356351be2e4914e15c4703172597c45656e /node_modules/snekfetch/test/node
parentcommenting (diff)
downloads5nical-60867fb030bae582082340ead7dbc7efdc2f5398.tar.xz
s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.zip
2020/04/03, 02:34, v1.2.0
Diffstat (limited to 'node_modules/snekfetch/test/node')
-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
6 files changed, 114 insertions, 0 deletions
diff --git a/node_modules/snekfetch/test/node/file.test.js b/node_modules/snekfetch/test/node/file.test.js
new file mode 100644
index 0000000..8ec0fd0
--- /dev/null
+++ b/node_modules/snekfetch/test/node/file.test.js
@@ -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:/);
+});
diff --git a/node_modules/snekfetch/test/node/http1.test.js b/node_modules/snekfetch/test/node/http1.test.js
new file mode 100644
index 0000000..00f91f4
--- /dev/null
+++ b/node_modules/snekfetch/test/node/http1.test.js
@@ -0,0 +1,7 @@
+/**
+ * @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
new file mode 100644
index 0000000..daf49d9
--- /dev/null
+++ b/node_modules/snekfetch/test/node/http2.test.js.disabled
@@ -0,0 +1,7 @@
+/**
+ * @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
new file mode 100644
index 0000000..b811ec9
--- /dev/null
+++ b/node_modules/snekfetch/test/node/main.js
@@ -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()
+);
diff --git a/node_modules/snekfetch/test/node/sync.test.js b/node_modules/snekfetch/test/node/sync.test.js
new file mode 100644
index 0000000..0c7187f
--- /dev/null
+++ b/node_modules/snekfetch/test/node/sync.test.js
@@ -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();
+}));
diff --git a/node_modules/snekfetch/test/node/util.test.js b/node_modules/snekfetch/test/node/util.test.js
new file mode 100644
index 0000000..1e71573
--- /dev/null
+++ b/node_modules/snekfetch/test/node/util.test.js
@@ -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');
+});