Skip to content

Commit

Permalink
test: add test using child_process instead
Browse files Browse the repository at this point in the history
  • Loading branch information
RaisinTen committed Dec 19, 2020
1 parent 6c19991 commit ccc860a
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions test/parallel/test-repl-unsafe-array-iteration.js
@@ -1,41 +1,27 @@
'use strict';
const common = require('../common');
const ArrayStream = require('../common/arraystream');
const assert = require('assert');
const repl = require('repl');
const { spawn } = require('child_process');

function run(input, expectation) {
const inputStream = new ArrayStream();
const outputStream = new ArrayStream();
let output = '';
const node = spawn('node');

outputStream.write = (data) => { output += data.replace('\r', ''); };

const r = repl.start({
input: inputStream,
output: outputStream,
terminal: true
});

r.on('exit', common.mustCall(() => {
const actual = output.split('\n');
node.stderr.on('data', common.mustCall((data) => {
assert.ok(data.includes(expectation));
}));

// Validate that the for loop returns undefined
assert.strictEqual(actual[actual.length - 2], expectation);
node.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1);

This comment has been minimized.

Copy link
@RaisinTen

RaisinTen Dec 19, 2020

Author Contributor

I don't understand why ccc860a failed. Currently the ... in internal/errors.js doesn't use a safe iterator so it should throw an error. The logs say that the process exited with 0.

Hum the CI actually shows a failure (exit code is 1), which is expected given SafeArrayIterator hasn't landed on master.

@aduh95 isn't the exit code 0?

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

0 !== 1
}));

inputStream.run(input);
r.close();
node.stdin.write(input);
node.stdin.end();
}

run([
'delete Array.prototype[Symbol.iterator];',
'for(const x of [3, 2, 1]);'
], 'Uncaught TypeError: [3,2,1] is not iterable');
run('delete Array.prototype[Symbol.iterator];',
'TypeError: Found non-callable @@iterator');

run([
'const ArrayIteratorPrototype =',
' Object.getPrototypeOf(Array.prototype[Symbol.iterator]());',
'delete ArrayIteratorPrototype.next;',
'for(const x of [3, 2, 1]);'
], 'Uncaught TypeError: undefined is not a function');
run('const ArrayIteratorPrototype =' +
'Object.getPrototypeOf(Array.prototype[Symbol.iterator]());' +
'delete ArrayIteratorPrototype.next;',
'TypeError: fn is not a function');

0 comments on commit ccc860a

Please sign in to comment.