11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst child_process = require('child_process');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciif (process.env.NODE_PENDING_DEPRECATION)
81cb0ef41Sopenharmony_ci  common.skip('test does not work when NODE_PENDING_DEPRECATION is set');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cifunction test(main, callSite, expected) {
111cb0ef41Sopenharmony_ci  const { stderr } = child_process.spawnSync(process.execPath, ['-p', `
121cb0ef41Sopenharmony_ci  process.mainModule = { filename: ${JSON.stringify(main)} };
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  vm.runInNewContext('new Buffer(10)', { Buffer }, {
151cb0ef41Sopenharmony_ci    filename: ${JSON.stringify(callSite)}
161cb0ef41Sopenharmony_ci  });`], { encoding: 'utf8' });
171cb0ef41Sopenharmony_ci  if (expected)
181cb0ef41Sopenharmony_ci    assert(stderr.includes('[DEP0005] DeprecationWarning'), stderr);
191cb0ef41Sopenharmony_ci  else
201cb0ef41Sopenharmony_ci    assert.strictEqual(stderr.trim(), '');
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_citest('/a/node_modules/b.js', '/a/node_modules/x.js', false);
241cb0ef41Sopenharmony_citest('/a/node_modules/b.js', '/a/node_modules/foo/node_modules/x.js', false);
251cb0ef41Sopenharmony_citest('/a/node_modules/foo/node_modules/b.js', '/a/node_modules/x.js', false);
261cb0ef41Sopenharmony_citest('/node_modules/foo/b.js', '/node_modules/foo/node_modules/x.js', false);
271cb0ef41Sopenharmony_citest('/a.js', '/b.js', true);
281cb0ef41Sopenharmony_citest('/a.js', '/node_modules/b.js', false);
291cb0ef41Sopenharmony_citest('/node_modules/a.js.js', '/b.js', true);
301cb0ef41Sopenharmony_citest('c:\\a\\node_modules\\b.js', 'c:\\a\\node_modules\\x.js', false);
311cb0ef41Sopenharmony_citest('c:\\a\\node_modules\\b.js',
321cb0ef41Sopenharmony_ci     'c:\\a\\node_modules\\foo\\node_modules\\x.js', false);
331cb0ef41Sopenharmony_citest('c:\\node_modules\\foo\\b.js',
341cb0ef41Sopenharmony_ci     'c:\\node_modules\\foo\\node_modules\\x.js', false);
351cb0ef41Sopenharmony_citest('c:\\a.js', 'c:\\b.js', true);
361cb0ef41Sopenharmony_citest('c:\\a.js', 'c:\\node_modules\\b.js', false);
371cb0ef41Sopenharmony_citest('c:\\node_modules\\a.js', 'c:\\b.js', true);
38