-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathoptions.socketPath.test.ts
More file actions
73 lines (65 loc) · 2.12 KB
/
options.socketPath.test.ts
File metadata and controls
73 lines (65 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { strict as assert } from 'node:assert';
import { describe, it, beforeAll, afterAll } from 'vitest';
import urllib from '../src/index.js';
import { startServer } from './fixtures/socket_server.js';
import { isWindows } from './utils.js';
describe.skipIf(isWindows())('options.socketPath.test.ts', () => {
let close: any;
let _url: string;
let _socketPath: string;
let server2: any;
beforeAll(async () => {
const { url, closeServer, socketPath } = await startServer();
close = closeServer;
_url = url;
_socketPath = socketPath;
server2 = await startServer();
});
afterAll(async () => {
await close();
await server2?.closeServer();
});
it('should request socket successfully', async () => {
let result = await urllib.request(_url, {
socketPath: _socketPath,
contentType: 'json',
dataType: 'json',
});
assert.deepStrictEqual(result.data, { a: 1 });
result = await urllib.request(_url, {
socketPath: _socketPath,
contentType: 'json',
dataType: 'json',
});
assert.deepStrictEqual(result.data, { a: 1 });
result = await urllib.request(_url, {
socketPath: _socketPath,
contentType: 'json',
dataType: 'json',
});
assert.deepStrictEqual(result.data, { a: 1 });
assert(result.res.socket.handledResponses > 1);
result = await urllib.request('http://unix/api/v1', {
socketPath: server2.socketPath,
contentType: 'json',
dataType: 'json',
});
assert.deepStrictEqual(result.data, { a: 1 });
assert.equal(result.url, 'http://unix/api/v1');
result = await urllib.request(_url, {
socketPath: _socketPath,
contentType: 'json',
dataType: 'json',
});
assert.deepStrictEqual(result.data, { a: 1 });
assert.equal(result.url, _url);
// request normal tcp should work
const host = process.env.CI ? 'registry.npmjs.org' : 'registry.npmmirror.com';
const url = `${host}/urllib/latest`;
const result2 = await urllib.request(url, {
dataType: 'json',
});
assert.equal(result2.status, 200);
assert.equal(result2.data.name, 'urllib');
});
});