• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Tests the --redirect-warnings command line flag by spawning
4// a new child node process that emits a warning into a temporary
5// warnings file. Once the process completes, the warning file is
6// opened and the contents are validated
7
8const common = require('../common');
9const fixtures = require('../common/fixtures');
10const fs = require('fs');
11const fork = require('child_process').fork;
12const path = require('path');
13const assert = require('assert');
14
15const tmpdir = require('../common/tmpdir');
16tmpdir.refresh();
17
18const warnmod = fixtures.path('warnings.js');
19const warnpath = path.join(tmpdir.path, 'warnings.txt');
20
21fork(warnmod, { execArgv: [`--redirect-warnings=${warnpath}`] })
22  .on('exit', common.mustCall(() => {
23    fs.readFile(warnpath, 'utf8', common.mustSucceed((data) => {
24      assert(/\(node:\d+\) Warning: a bad practice warning/.test(data));
25    }));
26  }));
27