1'use strict'; 2 3const common = require('../common'); 4const child_process = require('child_process'); 5const assert = require('assert'); 6 7if (process.env.NODE_PENDING_DEPRECATION) 8 common.skip('test does not work when NODE_PENDING_DEPRECATION is set'); 9 10function test(main, callSite, expected) { 11 const { stderr } = child_process.spawnSync(process.execPath, ['-p', ` 12 process.mainModule = { filename: ${JSON.stringify(main)} }; 13 14 vm.runInNewContext('new Buffer(10)', { Buffer }, { 15 filename: ${JSON.stringify(callSite)} 16 });`], { encoding: 'utf8' }); 17 if (expected) 18 assert(stderr.includes('[DEP0005] DeprecationWarning'), stderr); 19 else 20 assert.strictEqual(stderr.trim(), ''); 21} 22 23test('/a/node_modules/b.js', '/a/node_modules/x.js', false); 24test('/a/node_modules/b.js', '/a/node_modules/foo/node_modules/x.js', false); 25test('/a/node_modules/foo/node_modules/b.js', '/a/node_modules/x.js', false); 26test('/node_modules/foo/b.js', '/node_modules/foo/node_modules/x.js', false); 27test('/a.js', '/b.js', true); 28test('/a.js', '/node_modules/b.js', false); 29test('/node_modules/a.js.js', '/b.js', true); 30test('c:\\a\\node_modules\\b.js', 'c:\\a\\node_modules\\x.js', false); 31test('c:\\a\\node_modules\\b.js', 32 'c:\\a\\node_modules\\foo\\node_modules\\x.js', false); 33test('c:\\node_modules\\foo\\b.js', 34 'c:\\node_modules\\foo\\node_modules\\x.js', false); 35test('c:\\a.js', 'c:\\b.js', true); 36test('c:\\a.js', 'c:\\node_modules\\b.js', false); 37test('c:\\node_modules\\a.js', 'c:\\b.js', true); 38