0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-22 07:37:56 +01:00
nodejs/test/internet/test-snapshot-dns-resolve.js
Joyee Cheung 8821860f11
dns: support dns module in the snapshot
For the initial iteration, only the default resolver can be
serialized/deserialized. If `dns.setServers()` has been
called, we'll preserve the configured DNS servers in the snapshot.
We can consider exposing the serialization method if it becomes
necessary for user-land snapshots.

PR-URL: https://github.com/nodejs/node/pull/44633
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-09-29 01:58:21 +08:00

37 lines
970 B
JavaScript

'use strict';
// This tests support for the dns module in snapshot.
require('../common');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { buildSnapshot, runWithSnapshot } = require('../common/snapshot');
const {
addresses: { DNS4_SERVER, INET4_IP, INET4_HOST },
} = require('../common/internet');
const entry = fixtures.path('snapshot', 'dns-resolve.js');
const env = {
NODE_TEST_IP: INET4_IP,
NODE_TEST_HOST: INET4_HOST,
NODE_TEST_DNS: DNS4_SERVER,
NODE_TEST_PROMISE: 'false',
};
tmpdir.refresh();
function checkOutput(stderr, stdout) {
assert(stdout.includes('hostnames: ['));
assert(stdout.includes('addresses: ['));
assert.strictEqual(stdout.trim().split('\n').length, 2);
}
{
const { stderr, stdout } = buildSnapshot(entry, env);
checkOutput(stderr, stdout);
}
{
const { stderr, stdout } = runWithSnapshot(entry, env);
checkOutput(stderr, stdout);
}