-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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: #54878 Fixes: #54428 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Erick Wendel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Paolo Insogna <[email protected]>
- Loading branch information
1 parent
be4babb
commit bb40521
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); | ||
}); |