Open
Conversation
Member
|
Thank you for your assistance! diff --git i/test/utils.test.ts w/test/utils.test.ts
index 9837a7d..b5940c2 100644
--- i/test/utils.test.ts
+++ w/test/utils.test.ts
@@ -177,7 +177,21 @@ describe('readWithoutBlocking', () => {
expect(result3).toEqual({ done: true, value: undefined })
})
- it('should return undefined if stream is closed', async () => {
+ it('should return undefined value if stream is closed in start', async () => {
+ const body = new ReadableStream({
+ async start(controller) {
+ controller.close()
+ },
+ })
+ const response = new Response(body)
+ const reader = response.body!.getReader()
+ const readPromise = reader.read()
+
+ const result = await readWithoutBlocking(readPromise)
+ expect(result).toEqual({ done: true, value: undefined })
+ })
+
+ it('should return undefined if stream is errored in start', async () => {
const body = new ReadableStream({
async start() {
throw new Error('test')
@@ -187,7 +201,7 @@ describe('readWithoutBlocking', () => {
const reader = response.body!.getReader()
const readPromise = reader.read()
- await expect(readPromise).rejects.toThrow('test')
+ expect(readWithoutBlocking(readPromise)).rejects.toThrow('test')
})
it('should return undefined if stream is errored', async () => {
@@ -200,7 +214,6 @@ describe('readWithoutBlocking', () => {
const reader = response.body!.getReader()
const readPromise = reader.read()
- const result = await readWithoutBlocking(readPromise).catch(() => undefined)
- expect(result).toBeUndefined()
+ expect(readWithoutBlocking(readPromise)).rejects.toThrow('test')
})
}) |
…cases
Ensure closed streams resolve with `{ done: true, value: undefined }`
and errored streams properly reject.
97f9448 to
167b3fd
Compare
Author
|
@usualoma As you pointed out, I have modified the test code for some existing test cases related to |
Member
|
If this PR is ready, please ping me! |
Member
|
Hi @koralle Since diff --git i/package.json w/package.json
index e1221b7..5b22f6f 100644
--- i/package.json
+++ w/package.json
@@ -54,7 +54,7 @@
}
},
"scripts": {
- "test": "node --expose-gc node_modules/.bin/vitest",
+ "test": "vitest",
"build": "tsup --external hono",
"watch": "tsup --watch",
"postbuild": "publint",
diff --git i/vitest.config.ts w/vitest.config.ts
index 5031913..2590435 100644
--- i/vitest.config.ts
+++ w/vitest.config.ts
@@ -6,6 +6,7 @@ export default defineConfig({
include: ['test/**/*.test.ts'],
environment: 'node',
globals: true,
+ execArgv: ['--expose-gc'],
setupFiles: ["./test/setup.ts"]
}
}) |
Author
|
Thank you. I have modified |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I migrated our test framework from Jest to Vitest, considering aspects such as performance and development experience.
Consideration
In the test case 'should return undefined if stream is closed', the test for the function
readWithoutBlocking()is failing.However, the following ReadableStream should be rejected when
reader.read()is executed, and I believe the verification method forreadWithoutBlocking()is incorrect.However, when I ran the tests with Jest, this test case passed, and I don't understand why.
For now, I'm verifying that an exception is thrown by
ReadableStream... I'd like you to think with me about what this test case should ideally be.