-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from MattiasBuelens/test-node-support
Add unit tests for Node support
- Loading branch information
Showing
12 changed files
with
136 additions
and
17 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/// <reference lib="dom" /> | ||
export let NativeDOMException: typeof DOMException | undefined = typeof DOMException !== 'undefined' ? DOMException : undefined; | ||
export const NativeDOMException: typeof DOMException | undefined = typeof DOMException !== 'undefined' ? DOMException : undefined; |
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,6 @@ | ||
{ | ||
"extends": ["../.eslintrc.json"], | ||
"rules": { | ||
"@typescript-eslint/no-var-requires": "off" | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"extends": ["../.eslintrc.json"], | ||
"env": { | ||
"jasmine": true | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"spec_dir": "test/unit/", | ||
"spec_files": [ | ||
"**/*[sS]pec.js" | ||
], | ||
"helpers": [ | ||
"helpers/**/*.js" | ||
] | ||
} |
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,57 @@ | ||
const { ReadableStream, WritableStream } = require('../../../'); | ||
const { FakeAbortSignal } = require('../util/fake-abort-signal'); | ||
|
||
describe('ReadableStream', () => { | ||
describe('constructor', () => { | ||
it('constructs with no arguments', () => { | ||
const rs = new ReadableStream(); | ||
expect(rs instanceof ReadableStream).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('getReader', () => { | ||
it('reads chunks from underlying source', async () => { | ||
const rs = new ReadableStream({ | ||
start(c) { | ||
c.enqueue('a'); | ||
c.enqueue('b'); | ||
c.close(); | ||
} | ||
}); | ||
const reader = rs.getReader(); | ||
expect(await reader.read()).toEqual({ done: false, value: 'a' }); | ||
expect(await reader.read()).toEqual({ done: false, value: 'b' }); | ||
expect(await reader.read()).toEqual({ done: true, value: undefined }); | ||
}); | ||
}); | ||
|
||
describe('pipeTo', () => { | ||
it('accepts an abort signal', async () => { | ||
const rs = new ReadableStream({ | ||
start(c) { | ||
c.enqueue('a'); | ||
c.close(); | ||
} | ||
}); | ||
const ws = new WritableStream(); | ||
const signal = new FakeAbortSignal(false); | ||
await rs.pipeTo(ws, { signal }); | ||
}); | ||
it('rejects with an AbortError when aborted', async () => { | ||
const rs = new ReadableStream({ | ||
start(c) { | ||
c.enqueue('a'); | ||
c.close(); | ||
} | ||
}); | ||
const ws = new WritableStream(); | ||
const signal = new FakeAbortSignal(true); | ||
try { | ||
await rs.pipeTo(ws, { signal }); | ||
fail('should have rejected'); | ||
} catch (e) { | ||
expect(e.name).toBe('AbortError'); | ||
} | ||
}); | ||
}); | ||
}); |
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,17 @@ | ||
class FakeAbortSignal { | ||
constructor(aborted) { | ||
this.aborted = aborted; | ||
} | ||
|
||
addEventListener(type, listener) { | ||
return; | ||
} | ||
|
||
removeEventListener(type, listener) { | ||
return; | ||
} | ||
} | ||
|
||
module.exports = { | ||
FakeAbortSignal | ||
}; |