-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📦 NEW: Support options.opaque = object
- Loading branch information
Showing
5 changed files
with
56 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { strict as assert } from 'assert'; | ||
import urllib from '../src'; | ||
import { startServer } from './fixtures/server'; | ||
|
||
describe('options.opaque.test.ts', () => { | ||
let close: any; | ||
let _url: string; | ||
beforeAll(async () => { | ||
const { closeServer, url } = await startServer(); | ||
close = closeServer; | ||
_url = url; | ||
}); | ||
|
||
afterAll(async () => { | ||
await close(); | ||
}); | ||
|
||
it('should opaque work', async () => { | ||
const response = await urllib.request(_url, { | ||
dataType: 'json', | ||
opaque: { | ||
traceId: 'some random id here', | ||
}, | ||
}); | ||
assert.equal(response.status, 200); | ||
assert.deepEqual(response.opaque, { | ||
traceId: 'some random id here', | ||
}); | ||
}); | ||
|
||
it('should opaque work on error request', async () => { | ||
await assert.rejects(async () => { | ||
await urllib.request(`${_url}socket.end.error`, { | ||
opaque: { | ||
traceId: 'some random id here', | ||
}, | ||
}); | ||
}, (err: any) => { | ||
// console.error(err); | ||
assert.equal(err.res.status, 200); | ||
assert.equal(err.name, 'HTTPParserError'); | ||
assert.deepEqual(err.opaque, { | ||
traceId: 'some random id here', | ||
}); | ||
return true; | ||
}); | ||
}); | ||
}); |