|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +require('../common'); |
| 4 | + |
| 5 | +const fixtures = require('../common/fixtures'); |
| 6 | +const file = fixtures.path('get-call-site.js'); |
| 7 | + |
| 8 | +const { getCallSite } = require('node:util'); |
| 9 | +const { spawnSync } = require('node:child_process'); |
| 10 | +const assert = require('node:assert'); |
| 11 | + |
| 12 | +{ |
| 13 | + const callsite = getCallSite(); |
| 14 | + assert.ok(callsite.length > 1); |
| 15 | + assert.match( |
| 16 | + callsite[0].getFileName(), |
| 17 | + /test-util-getCallSite/, |
| 18 | + 'node:util should be ignored', |
| 19 | + ); |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +{ |
| 24 | + const { status, stderr, stdout } = spawnSync( |
| 25 | + process.execPath, |
| 26 | + [ |
| 27 | + '-e', |
| 28 | + `const util = require('util'); |
| 29 | + const assert = require('assert'); |
| 30 | + assert.ok(util.getCallSite().length > 1); |
| 31 | + process.stdout.write(util.getCallSite()[0].getFileName()); |
| 32 | + `, |
| 33 | + ], |
| 34 | + ); |
| 35 | + assert.strictEqual(status, 0, stderr.toString()); |
| 36 | + assert.strictEqual(stdout.toString(), '[eval]'); |
| 37 | +} |
| 38 | + |
| 39 | +{ |
| 40 | + const { status, stderr, stdout } = spawnSync( |
| 41 | + process.execPath, |
| 42 | + [file], |
| 43 | + ); |
| 44 | + assert.strictEqual(status, 0, stderr.toString()); |
| 45 | + assert.strictEqual(stdout.toString(), file); |
| 46 | +} |
| 47 | + |
| 48 | +{ |
| 49 | + const originalStackTraceLimit = Error.stackTraceLimit; |
| 50 | + Error.stackTraceLimit = 0; |
| 51 | + const callsite = getCallSite(); |
| 52 | + assert.strictEqual(callsite.length, 0); |
| 53 | + Error.stackTraceLimit = originalStackTraceLimit; |
| 54 | +} |
0 commit comments