forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_runner: support typescript module mocking
PR-URL: nodejs#54878 Fixes: nodejs#54428 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Erick Wendel <erick.workspace@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
- Loading branch information
1 parent
a6915e9
commit 8b8a4b2
Showing
7 changed files
with
55 additions
and
6 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,5 @@ | ||
const logger = (): void => { }; | ||
|
||
module.exports = { | ||
logger | ||
} |
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 @@ | ||
export const logger = (): void => { }; |
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,23 @@ | ||
import { before, mock, test } from 'node:test'; | ||
import { strictEqual } from 'node:assert'; | ||
|
||
const logger = mock.fn((s) => console.log(`Hello, ${s}!`)); | ||
|
||
before(async () => { | ||
mock.module('./module-logger.ts', { | ||
namedExports: { logger } | ||
}); | ||
mock.module('./commonjs-logger.ts', { | ||
namedExports: { logger } | ||
}); | ||
}); | ||
|
||
test('logger', async () => { | ||
const { logger: mockedModule } = await import('./module-logger.ts'); | ||
mockedModule('TypeScript-Module'); | ||
strictEqual(logger.mock.callCount(), 1); | ||
|
||
const { logger: mockedCommonjs } = await import('./commonjs-logger.ts'); | ||
mockedCommonjs('TypeScript-CommonJS'); | ||
strictEqual(logger.mock.callCount(), 2); | ||
}); |