forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-util-getcallsites.js
More file actions
171 lines (152 loc) · 4.26 KB
/
test-util-getcallsites.js
File metadata and controls
171 lines (152 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const file = fixtures.path('get-call-sites.js');
const { getCallSites } = require('node:util');
const { spawnSync } = require('node:child_process');
const assert = require('node:assert');
{
const callSites = getCallSites();
assert.ok(callSites.length > 1);
assert.match(
callSites[0].scriptName,
/test-util-getcallsites/,
'node:util should be ignored',
);
}
{
const callSites = getCallSites(3);
assert.strictEqual(callSites.length, 3);
assert.match(
callSites[0].scriptName,
/test-util-getcallsites/,
'node:util should be ignored',
);
}
// Guarantee dot-left numbers are ignored
{
const callSites = getCallSites(3.6);
assert.strictEqual(callSites.length, 3);
}
{
const callSites = getCallSites(3.4);
assert.strictEqual(callSites.length, 3);
}
{
assert.throws(() => {
// Max than kDefaultMaxCallStackSizeToCapture
getCallSites(201);
}, common.expectsError({
code: 'ERR_OUT_OF_RANGE'
}));
assert.throws(() => {
getCallSites(-1);
}, common.expectsError({
code: 'ERR_OUT_OF_RANGE'
}));
assert.throws(() => {
getCallSites([]);
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE'
}));
assert.throws(() => {
getCallSites({}, {});
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE'
}));
assert.throws(() => {
getCallSites(10, 10);
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE'
}));
}
{
const callSites = getCallSites(1);
assert.strictEqual(callSites.length, 1);
assert.match(
callSites[0].scriptName,
/test-util-getcallsites/,
'node:util should be ignored',
);
}
// ScriptId is a string.
{
const callSites = getCallSites(1);
assert.strictEqual(callSites.length, 1);
assert.strictEqual(typeof callSites[0].scriptId, 'string');
}
// Guarantee [eval] will appear on stacktraces when using -e
{
const { status, stderr, stdout } = spawnSync(
process.execPath,
[
'-e',
`const util = require('util');
const assert = require('assert');
assert.ok(util.getCallSites().length > 1);
process.stdout.write(util.getCallSites()[0].scriptName);
`,
],
);
assert.strictEqual(status, 0, stderr.toString());
assert.strictEqual(stdout.toString(), '[eval]');
}
// Guarantee the stacktrace[0] is the filename
{
const { status, stderr, stdout } = spawnSync(
process.execPath,
[file],
);
assert.strictEqual(status, 0, stderr.toString());
assert.strictEqual(stdout.toString(), file);
}
// Error.stackTraceLimit should not influence callsite size
{
const originalStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
const callSites = getCallSites();
assert.notStrictEqual(callSites.length, 0);
Error.stackTraceLimit = originalStackTraceLimit;
}
{
const { status, stderr, stdout } = spawnSync(process.execPath, [
'--no-warnings',
'--experimental-transform-types',
fixtures.path('typescript/ts/test-get-callsite.ts'),
]);
const output = stdout.toString();
assert.strictEqual(stderr.toString(), '');
assert.match(output, /lineNumber: 8/);
assert.match(output, /column: 18/);
assert.match(output, /test-get-callsite\.ts/);
assert.strictEqual(status, 0);
}
{
const { status, stderr, stdout } = spawnSync(process.execPath, [
'--no-warnings',
'--experimental-transform-types',
'--no-enable-source-maps',
fixtures.path('typescript/ts/test-get-callsite.ts'),
]);
const output = stdout.toString();
assert.strictEqual(stderr.toString(), '');
// Line should be wrong when sourcemaps are disable
assert.match(output, /lineNumber: 2/);
assert.match(output, /column: 18/);
assert.match(output, /test-get-callsite\.ts/);
assert.strictEqual(status, 0);
}
{
// Source maps should be disabled when options.sourceMap is false
const { status, stderr, stdout } = spawnSync(process.execPath, [
'--no-warnings',
'--experimental-transform-types',
fixtures.path('typescript/ts/test-get-callsite-explicit.ts'),
]);
const output = stdout.toString();
assert.strictEqual(stderr.toString(), '');
assert.match(output, /lineNumber: 2/);
assert.match(output, /column: 18/);
assert.match(output, /test-get-callsite-explicit\.ts/);
assert.strictEqual(status, 0);
}