aboutsummaryrefslogtreecommitdiff
path: root/test/addons/repl-domain-abort/test.js
blob: 1f30f0f9beae546c6d0ffb983fad26028564bb69 (plain)
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
'use strict';
const common = require('../../common');
const assert = require('assert');
const repl = require('repl');
const stream = require('stream');
const path = require('path');
var buildType = process.config.target_defaults.default_configuration;
var buildPath = path.join(__dirname, 'build', buildType, 'binding');
// On Windows, escape backslashes in the path before passing it to REPL.
if (common.isWindows)
  buildPath = buildPath.replace(/\\/g, '/');
var cb_ran = false;

process.on('exit', function() {
  assert(cb_ran);
  console.log('ok');
});

var lines = [
  // This line shouldn't cause an assertion error.
  'require(\'' + buildPath + '\')' +
  // Log output to double check callback ran.
  '.method(function() { console.log(\'cb_ran\'); });',
];

var dInput = new stream.Readable();
var dOutput = new stream.Writable();

dInput._read = function _read(size) {
  while (lines.length > 0 && this.push(lines.shift()));
  if (lines.length === 0)
    this.push(null);
};

dOutput._write = function _write(chunk, encoding, cb) {
  if (chunk.toString().indexOf('cb_ran') === 0)
    cb_ran = true;
  cb();
};

var options = {
  input: dInput,
  output: dOutput,
  terminal: false,
  ignoreUndefined: true
};

// Run commands from fake REPL.
repl.start(options);