-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support mock.dataWithAsyncDispose()
- Loading branch information
Showing
12 changed files
with
126 additions
and
104 deletions.
There are no files selected for viewing
This file was deleted.
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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict'; | ||
|
||
const mm = require('..'); | ||
|
||
describe('test/async-await.test.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,38 @@ | ||
import { strict as assert } from 'node:assert'; | ||
require('@hazae41/symbol-dispose-polyfill'); | ||
import mm from '../index'; | ||
|
||
describe('test/asyncDispose.test.ts', () => { | ||
const foo = { | ||
async request() { | ||
return 'yes'; | ||
}, | ||
async echo() { | ||
return { | ||
hi: 'yes', | ||
async [Symbol.asyncDispose]() { | ||
console.log('asyncDispose run'); | ||
}, | ||
}; | ||
}, | ||
* generatorRequest() { | ||
return 'yes'; | ||
}, | ||
}; | ||
|
||
afterEach(mm.restore); | ||
|
||
describe('dataWithAsyncDispose()', () => { | ||
it('should mock async function with asyncDispose', async () => { | ||
mm.dataWithAsyncDispose(foo, 'echo', { | ||
hi: 'no', | ||
}); | ||
await using data1 = await foo.echo(); | ||
assert.equal(data1.hi, 'no'); | ||
|
||
mm.restore(); | ||
await using data2 = await foo.echo(); | ||
assert.equal(data2.hi, 'yes'); | ||
}); | ||
}); | ||
}); |
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,5 +1,3 @@ | ||
'use strict'; | ||
|
||
require('should'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
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,11 @@ | ||
{ | ||
"extends": "@eggjs/tsconfig", | ||
"compileOnSave": true, | ||
"compilerOptions": { | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
} | ||
} |