node/test/parallel/test-debugger-repeat-last.js
Joyee Cheung 812e236df9
test: move debugger tests with --port=0 to parallel
Before

```
❯ tools/test.py "sequential/test-debugger*"
[00:25|% 100|+  32|-   0]: Done

All tests passed.
❯ tools/test.py -J "parallel/test-debugger*"
[00:05|% 100|+   6|-   0]: Done

All tests passed.
```

After

```
❯ tools/test.py "sequential/test-debugger*"
[00:06|% 100|+   5|-   0]: Done

All tests passed.
❯ tools/test.py -J "parallel/test-debugger*"
[00:05|% 100|+  33|-   0]: Done

All tests passed.
```

PR-URL: https://github.com/nodejs/node/pull/47274
Refs: https://github.com/nodejs/node/issues/47146
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-04-05 00:49:46 +02:00

46 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const path = require('../common/fixtures').path;
const spawn = require('child_process').spawn;
const assert = require('assert');
const fixture = path('debugger-repeat-last.js');
const args = [
'inspect',
'--port=0',
fixture,
];
const proc = spawn(process.execPath, args, { stdio: 'pipe' });
proc.stdout.setEncoding('utf8');
let stdout = '';
let sentCommand = false;
let sentExit = false;
proc.stdout.on('data', (data) => {
stdout += data;
// Send 'n' as the first step.
if (!sentCommand && stdout.includes('> 1 ')) {
setImmediate(() => { proc.stdin.write('n\n'); });
return sentCommand = true;
}
// Send empty (repeat last command) until we reach line 5.
if (sentCommand && !stdout.includes('> 5')) {
setImmediate(() => { proc.stdin.write('\n'); });
return true;
}
if (!sentExit && stdout.includes('> 5')) {
setTimeout(() => { proc.stdin.write('\n\n\n.exit\n\n\n'); }, 1);
return sentExit = true;
}
});
process.on('exit', (exitCode) => {
assert.strictEqual(exitCode, 0);
console.log(stdout);
});