1'use strict';
2
3// This tests support for the dns module in snapshot.
4
5require('../common');
6const assert = require('assert');
7const tmpdir = require('../common/tmpdir');
8const fixtures = require('../common/fixtures');
9const { buildSnapshot, runWithSnapshot } = require('../common/snapshot');
10
11const entry = fixtures.path('snapshot', 'dns-lookup.js');
12const env = {
13  NODE_TEST_HOST: 'localhost',
14  NODE_TEST_PROMISE: 'true',
15};
16
17tmpdir.refresh();
18function checkOutput(stderr, stdout) {
19  // We allow failures as it's not always possible to resolve localhost.
20  // Functional tests are done in test/internet instead.
21  if (!stderr.startsWith('error:')) {
22    assert.match(stdout, /address: "\d+\.\d+\.\d+\.\d+"/);
23    assert.match(stdout, /family: 4/);
24    assert.strictEqual(stdout.trim().split('\n').length, 2);
25  }
26}
27{
28  const { stderr, stdout } = buildSnapshot(entry, env);
29  checkOutput(stderr, stdout);
30}
31
32{
33  const { stderr, stdout } = runWithSnapshot(entry, env);
34  checkOutput(stderr, stdout);
35}
36