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.
module: increase code coverage of cjs loader
Add test cases to cover uncovered wrap and wrapper getters. Refs: https://coverage.nodejs.org/coverage-99268b1e996d13a0/lib/internal/modules/cjs/loader.js.html#L153 PR-URL: nodejs#27898 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
1 parent
a1cb14a
commit 6ef4d9e
Showing
4 changed files
with
34 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use strict'; | ||
const assert = require('assert'); | ||
const m = require('module'); | ||
|
||
|
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 @@ | ||
'use strict'; | ||
const assert = require('assert'); | ||
const m = require('module'); | ||
|
||
global.mwc = 0; | ||
|
||
const originalWrapper = m.wrapper; | ||
const patchedWrapper = {...m.wrapper}; | ||
|
||
patchedWrapper[0] += 'global.mwc = (global.mwc || 0 ) + 1'; | ||
|
||
// Storing original version of wrapper function | ||
m.wrapper = patchedWrapper; | ||
|
||
require('./not-main-module.js'); | ||
|
||
assert.strictEqual(mwc, 1); | ||
|
||
// Restoring original wrapper function | ||
m.wrapper = originalWrapper; | ||
// Cleaning require cache | ||
delete require.cache[require.resolve('./not-main-module.js')]; | ||
delete global.mwc; |
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,9 @@ | ||
'use strict'; | ||
require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const { execFileSync } = require('child_process'); | ||
|
||
const cjsModuleWrapTest = fixtures.path('cjs-module-wrapper.js'); | ||
const node = process.execPath; | ||
|
||
execFileSync(node, [cjsModuleWrapTest], { stdio: 'pipe' }); |