Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 4a8b27c

Browse files
author
Jan Krems
committed
test: Remove unix path assumptions
1 parent 0a04b50 commit 4a8b27c

File tree

8 files changed

+76
-49
lines changed

8 files changed

+76
-49
lines changed

lib/internal/inspect_repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function isNativeUrl(url) {
8181
}
8282

8383
function getRelativePath(filename) {
84-
const dir = `${Path.resolve()}/`;
84+
const dir = Path.join(Path.resolve(), 'x').slice(0, -1);
8585

8686
// Change path to relative, if possible
8787
if (filename.indexOf(dir) === 0) {

test/cli/backtrace.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
2+
const Path = require('path');
3+
24
const { test } = require('tap');
35

46
const startCLI = require('./start-cli');
57

68
test('display and navigate backtrace', (t) => {
7-
const cli = startCLI(['examples/backtrace.js']);
9+
const script = Path.join('examples', 'backtrace.js');
10+
const cli = startCLI([script]);
811

912
function onFatal(error) {
1013
cli.quit();
@@ -16,11 +19,11 @@ test('display and navigate backtrace', (t) => {
1619
.then(() => cli.stepCommand('c'))
1720
.then(() => cli.command('bt'))
1821
.then(() => {
19-
t.match(cli.output, '#0 topFn examples/backtrace.js:8:2');
22+
t.match(cli.output, `#0 topFn ${script}:8:2`);
2023
})
2124
.then(() => cli.command('backtrace'))
2225
.then(() => {
23-
t.match(cli.output, '#0 topFn examples/backtrace.js:8:2');
26+
t.match(cli.output, `#0 topFn ${script}:8:2`);
2427
})
2528
.then(() => cli.quit())
2629
.then(null, onFatal);

test/cli/break.test.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
2+
const Path = require('path');
3+
24
const { test } = require('tap');
35

46
const startCLI = require('./start-cli');
57

68
test('stepping through breakpoints', (t) => {
7-
const cli = startCLI(['examples/break.js']);
9+
const script = Path.join('examples', 'break.js');
10+
const cli = startCLI([script]);
811

912
function onFatal(error) {
1013
cli.quit();
@@ -16,7 +19,7 @@ test('stepping through breakpoints', (t) => {
1619
.then(() => {
1720
t.match(
1821
cli.output,
19-
'break in examples/break.js:1',
22+
`break in ${script}:1`,
2023
'pauses in the first line of the script');
2124
t.match(
2225
cli.output,
@@ -27,7 +30,7 @@ test('stepping through breakpoints', (t) => {
2730
.then(() => {
2831
t.match(
2932
cli.output,
30-
'break in examples/break.js:2',
33+
`break in ${script}:2`,
3134
'pauses in next line of the script');
3235
t.match(
3336
cli.output,
@@ -38,7 +41,7 @@ test('stepping through breakpoints', (t) => {
3841
.then(() => {
3942
t.match(
4043
cli.output,
41-
'break in examples/break.js:3',
44+
`break in ${script}:3`,
4245
'pauses in next line of the script');
4346
t.match(
4447
cli.output,
@@ -49,7 +52,7 @@ test('stepping through breakpoints', (t) => {
4952
.then(() => {
5053
t.match(
5154
cli.output,
52-
'break in examples/break.js:10',
55+
`break in ${script}:10`,
5356
'pauses on the next breakpoint');
5457
t.match(
5558
cli.output,
@@ -65,8 +68,8 @@ test('stepping through breakpoints', (t) => {
6568
.then(() => t.notMatch(cli.output, 'Could not resolve breakpoint'))
6669
.then(() => cli.command('breakpoints'))
6770
.then(() => {
68-
t.match(cli.output, '#0 examples/break.js:6');
69-
t.match(cli.output, '#1 examples/break.js:16');
71+
t.match(cli.output, `#0 ${script}:6`);
72+
t.match(cli.output, `#1 ${script}:16`);
7073
})
7174

7275
.then(() => cli.command('list()'))
@@ -98,29 +101,31 @@ test('stepping through breakpoints', (t) => {
98101
.then(() => {
99102
t.match(
100103
cli.output,
101-
'break in examples/break.js:16',
104+
`break in ${script}:16`,
102105
'found breakpoint we set above w/ line number only');
103106
})
104107
.then(() => cli.stepCommand('cont'))
105108
.then(() => {
106109
t.match(
107110
cli.output,
108-
'break in examples/break.js:6',
111+
`break in ${script}:6`,
109112
'found breakpoint we set above w/ line number & script');
110113
})
111114
.then(() => cli.stepCommand(''))
112115
.then(() => {
113116
t.match(
114117
cli.output,
115-
'debugCommand in examples/break.js:14',
118+
`debugCommand in ${script}:14`,
116119
'found function breakpoint we set above');
117120
})
118121
.then(() => cli.quit())
119122
.then(null, onFatal);
120123
});
121124

122125
test('sb before loading file', (t) => {
123-
const cli = startCLI(['examples/cjs/index.js']);
126+
const script = Path.join('examples', 'cjs', 'index.js');
127+
const otherScript = Path.join('examples', 'cjs', 'other.js');
128+
const cli = startCLI([script]);
124129

125130
function onFatal(error) {
126131
cli.quit();
@@ -140,15 +145,16 @@ test('sb before loading file', (t) => {
140145
.then(() => {
141146
t.match(
142147
cli.output,
143-
'break in examples/cjs/other.js:3',
148+
`break in ${otherScript}:3`,
144149
'found breakpoint in file that was not loaded yet');
145150
})
146151
.then(() => cli.quit())
147152
.then(null, onFatal);
148153
});
149154

150155
test('clearBreakpoint', (t) => {
151-
const cli = startCLI(['examples/break.js']);
156+
const script = Path.join('examples', 'break.js');
157+
const cli = startCLI([script]);
152158

153159
function onFatal(error) {
154160
cli.quit();
@@ -161,8 +167,8 @@ test('clearBreakpoint', (t) => {
161167
.then(() => cli.command('sb("break.js", 9)'))
162168
.then(() => cli.command('breakpoints'))
163169
.then(() => {
164-
t.match(cli.output, '#0 examples/break.js:3');
165-
t.match(cli.output, '#1 examples/break.js:9');
170+
t.match(cli.output, `#0 ${script}:3`);
171+
t.match(cli.output, `#1 ${script}:9`);
166172
})
167173
.then(() => cli.command('clearBreakpoint("break.js", 4)'))
168174
.then(() => {
@@ -175,13 +181,13 @@ test('clearBreakpoint', (t) => {
175181
.then(() => cli.command('clearBreakpoint("break.js", 3)'))
176182
.then(() => cli.command('breakpoints'))
177183
.then(() => {
178-
t.match(cli.output, '#0 examples/break.js:9');
184+
t.match(cli.output, `#0 ${script}:9`);
179185
})
180186
.then(() => cli.stepCommand('cont'))
181187
.then(() => {
182188
t.match(
183189
cli.output,
184-
'break in examples/break.js:9',
190+
`break in ${script}:9`,
185191
'hits the 2nd breakpoint because the 1st was cleared');
186192
})
187193
.then(() => cli.quit())

test/cli/exceptions.test.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
2+
const Path = require('path');
3+
24
const { test } = require('tap');
35

46
const startCLI = require('./start-cli');
57

68
test('break on (uncaught) exceptions', (t) => {
7-
const cli = startCLI(['examples/exceptions.js']);
9+
const script = Path.join('examples', 'exceptions.js');
10+
const cli = startCLI([script]);
811

912
function onFatal(error) {
1013
cli.quit();
@@ -14,7 +17,7 @@ test('break on (uncaught) exceptions', (t) => {
1417
return cli.waitFor(/break/)
1518
.then(() => cli.waitForPrompt())
1619
.then(() => {
17-
t.match(cli.output, 'break in examples/exceptions.js:1');
20+
t.match(cli.output, `break in ${script}:1`);
1821
})
1922
// making sure it will die by default:
2023
.then(() => cli.command('c'))
@@ -23,34 +26,34 @@ test('break on (uncaught) exceptions', (t) => {
2326
// Next run: With `breakOnException` it pauses in both places
2427
.then(() => cli.stepCommand('r'))
2528
.then(() => {
26-
t.match(cli.output, 'break in examples/exceptions.js:1');
29+
t.match(cli.output, `break in ${script}:1`);
2730
})
2831
.then(() => cli.command('breakOnException'))
2932
.then(() => cli.stepCommand('c'))
3033
.then(() => {
31-
t.match(cli.output, 'exception in examples/exceptions.js:4');
34+
t.match(cli.output, `exception in ${script}:4`);
3235
})
3336
.then(() => cli.stepCommand('c'))
3437
.then(() => {
35-
t.match(cli.output, 'exception in examples/exceptions.js:10');
38+
t.match(cli.output, `exception in ${script}:10`);
3639
})
3740

3841
// Next run: With `breakOnUncaught` it only pauses on the 2nd exception
3942
.then(() => cli.command('breakOnUncaught'))
4043
.then(() => cli.stepCommand('r')) // also, the setting survives the restart
4144
.then(() => {
42-
t.match(cli.output, 'break in examples/exceptions.js:1');
45+
t.match(cli.output, `break in ${script}:1`);
4346
})
4447
.then(() => cli.stepCommand('c'))
4548
.then(() => {
46-
t.match(cli.output, 'exception in examples/exceptions.js:10');
49+
t.match(cli.output, `exception in ${script}:10`);
4750
})
4851

4952
// Next run: Back to the initial state! It should die again.
5053
.then(() => cli.command('breakOnNone'))
5154
.then(() => cli.stepCommand('r'))
5255
.then(() => {
53-
t.match(cli.output, 'break in examples/exceptions.js:1');
56+
t.match(cli.output, `break in ${script}:1`);
5457
})
5558
.then(() => cli.command('c'))
5659
.then(() => cli.waitFor(/disconnect/))

test/cli/launch.test.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
2+
const Path = require('path');
3+
24
const { test } = require('tap');
35

46
const startCLI = require('./start-cli');
57

68
test('examples/empty.js', (t) => {
7-
const cli = startCLI(['examples/empty.js']);
9+
const script = Path.join('examples', 'empty.js');
10+
const cli = startCLI([script]);
811
return cli.waitForPrompt()
912
.then(() => {
1013
t.match(cli.output, 'debug>', 'prints a prompt');
@@ -32,7 +35,8 @@ test('examples/empty.js', (t) => {
3235
});
3336

3437
test('run after quit / restart', (t) => {
35-
const cli = startCLI(['examples/three-lines.js']);
38+
const script = Path.join('examples', 'three-lines.js');
39+
const cli = startCLI([script]);
3640

3741
function onFatal(error) {
3842
cli.quit();
@@ -45,7 +49,7 @@ test('run after quit / restart', (t) => {
4549
.then(() => {
4650
t.match(
4751
cli.output,
48-
'break in examples/three-lines.js:2',
52+
`break in ${script}:2`,
4953
'steps to the 2nd line');
5054
})
5155
.then(() => cli.command('cont'))
@@ -56,6 +60,10 @@ test('run after quit / restart', (t) => {
5660
'Waiting for the debugger to disconnect',
5761
'the child was done');
5862
})
63+
.then(() => {
64+
// On windows the socket won't close by itself
65+
return cli.command('kill');
66+
})
5967
.then(() => cli.command('cont'))
6068
.then(() => cli.waitFor(/start the app/))
6169
.then(() => {
@@ -66,21 +74,21 @@ test('run after quit / restart', (t) => {
6674
.then(() => {
6775
t.match(
6876
cli.output,
69-
'break in examples/three-lines.js:1',
77+
`break in ${script}:1`,
7078
'is back at the beginning');
7179
})
7280
.then(() => cli.stepCommand('n'))
7381
.then(() => {
7482
t.match(
7583
cli.output,
76-
'break in examples/three-lines.js:2',
84+
`break in ${script}:2`,
7785
'steps to the 2nd line');
7886
})
7987
.then(() => cli.stepCommand('restart'))
8088
.then(() => {
8189
t.match(
8290
cli.output,
83-
'break in examples/three-lines.js:1',
91+
`break in ${script}:1`,
8492
'is back at the beginning');
8593
})
8694
.then(() => cli.command('kill'))
@@ -94,7 +102,7 @@ test('run after quit / restart', (t) => {
94102
.then(() => {
95103
t.match(
96104
cli.output,
97-
'break in examples/three-lines.js:1',
105+
`break in ${script}:1`,
98106
'is back at the beginning');
99107
})
100108
.then(() => cli.quit())

test/cli/low-level.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const startCLI = require('./start-cli');
55

66
test('Debugger agent direct access', (t) => {
77
const cli = startCLI(['examples/empty.js']);
8+
const scriptPattern = /^\* (\d+): examples(?:\/|\\)empty.js/;
89

910
function onFatal(error) {
1011
cli.quit();
@@ -15,7 +16,7 @@ test('Debugger agent direct access', (t) => {
1516
.then(() => cli.waitForPrompt())
1617
.then(() => cli.command('scripts'))
1718
.then(() => {
18-
const [, scriptId] = cli.output.match(/^\* (\d+): examples\/empty.js/);
19+
const [, scriptId] = cli.output.match(scriptPattern);
1920
return cli.command(
2021
`Debugger.getScriptSource({ scriptId: '${scriptId}' })`
2122
);

test/cli/preserve-breaks.test.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict';
2+
const Path = require('path');
3+
24
const { test } = require('tap');
35

46
const startCLI = require('./start-cli');
57

68
test('run after quit / restart', (t) => {
7-
const cli = startCLI(['examples/three-lines.js']);
9+
const script = Path.join('examples', 'three-lines.js');
10+
const cli = startCLI([script]);
811

912
function onFatal(error) {
1013
cli.quit();
@@ -21,32 +24,32 @@ test('run after quit / restart', (t) => {
2124
.then(() => cli.command('sb(3)'))
2225
.then(() => cli.command('breakpoints'))
2326
.then(() => {
24-
t.match(cli.output, '#0 examples/three-lines.js:2');
25-
t.match(cli.output, '#1 examples/three-lines.js:3');
27+
t.match(cli.output, `#0 ${script}:2`);
28+
t.match(cli.output, `#1 ${script}:3`);
2629
})
2730
.then(() => cli.stepCommand('c')) // hit line 2
2831
.then(() => cli.stepCommand('c')) // hit line 3
2932
.then(() => {
30-
t.match(cli.output, 'break in examples/three-lines.js:3');
33+
t.match(cli.output, `break in ${script}:3`);
3134
})
3235
.then(() => cli.command('restart'))
3336
.then(() => cli.waitFor([/break in examples/, /breakpoints restored/]))
3437
.then(() => cli.waitForPrompt())
3538
.then(() => {
36-
t.match(cli.output, 'break in examples/three-lines.js:1');
39+
t.match(cli.output, `break in ${script}:1`);
3740
})
3841
.then(() => cli.stepCommand('c'))
3942
.then(() => {
40-
t.match(cli.output, 'break in examples/three-lines.js:2');
43+
t.match(cli.output, `break in ${script}:2`);
4144
})
4245
.then(() => cli.stepCommand('c'))
4346
.then(() => {
44-
t.match(cli.output, 'break in examples/three-lines.js:3');
47+
t.match(cli.output, `break in ${script}:3`);
4548
})
4649
.then(() => cli.command('breakpoints'))
4750
.then(() => {
48-
t.match(cli.output, '#0 examples/three-lines.js:2');
49-
t.match(cli.output, '#1 examples/three-lines.js:3');
51+
t.match(cli.output, `#0 ${script}:2`);
52+
t.match(cli.output, `#1 ${script}:3`);
5053
})
5154
.then(() => cli.quit())
5255
.then(null, onFatal);

0 commit comments

Comments
 (0)