summaryrefslogtreecommitdiff
path: root/test/parallel/test-process-redirect-warnings.js
blob: b4f55fa8345409e17eae7d3fe699830380f8c1bd (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
'use strict';

// Tests the --redirect-warnings command line flag by spawning
// a new child node process that emits a warning into a temporary
// warnings file. Once the process completes, the warning file is
// opened and the contents are validated

const common = require('../common');
const fixtures = require('../common/fixtures');
const fs = require('fs');
const fork = require('child_process').fork;
const path = require('path');
const assert = require('assert');

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

const warnmod = fixtures.path('warnings.js');
const warnpath = path.join(tmpdir.path, 'warnings.txt');

fork(warnmod, { execArgv: [`--redirect-warnings=${warnpath}`] })
  .on('exit', common.mustCall(() => {
    fs.readFile(warnpath, 'utf8', common.mustCall((err, data) => {
      assert.ifError(err);
      assert(/\(node:\d+\) Warning: a bad practice warning/.test(data));
    }));
  }));