Skip to content

Commit

Permalink
module: increase code coverage of cjs loader
Browse files Browse the repository at this point in the history
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: #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
melikhov-dev authored and targos committed Jul 20, 2019
1 parent 0b7feca commit 1770bc8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/fixtures/cjs-module-wrap.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
const assert = require('assert');
const m = require('module');

Expand Down
23 changes: 23 additions & 0 deletions test/fixtures/cjs-module-wrapper.js
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;
2 changes: 1 addition & 1 deletion test/parallel/test-module-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ const fixtures = require('../common/fixtures');
const { execFileSync } = require('child_process');

const cjsModuleWrapTest = fixtures.path('cjs-module-wrap.js');
const node = process.argv[0];
const node = process.execPath;

execFileSync(node, [cjsModuleWrapTest], { stdio: 'pipe' });
9 changes: 9 additions & 0 deletions test/parallel/test-module-wrapper.js
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' });

0 comments on commit 1770bc8

Please sign in to comment.