11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This tests support for the dns module in snapshot. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cirequire('../common'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 81cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 91cb0ef41Sopenharmony_ciconst { buildSnapshot, runWithSnapshot } = require('../common/snapshot'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst entry = fixtures.path('snapshot', 'dns-lookup.js'); 121cb0ef41Sopenharmony_ciconst env = { 131cb0ef41Sopenharmony_ci NODE_TEST_HOST: 'localhost', 141cb0ef41Sopenharmony_ci NODE_TEST_PROMISE: 'true', 151cb0ef41Sopenharmony_ci}; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_citmpdir.refresh(); 181cb0ef41Sopenharmony_cifunction checkOutput(stderr, stdout) { 191cb0ef41Sopenharmony_ci // We allow failures as it's not always possible to resolve localhost. 201cb0ef41Sopenharmony_ci // Functional tests are done in test/internet instead. 211cb0ef41Sopenharmony_ci if (!stderr.startsWith('error:')) { 221cb0ef41Sopenharmony_ci assert.match(stdout, /address: "\d+\.\d+\.\d+\.\d+"/); 231cb0ef41Sopenharmony_ci assert.match(stdout, /family: 4/); 241cb0ef41Sopenharmony_ci assert.strictEqual(stdout.trim().split('\n').length, 2); 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci} 271cb0ef41Sopenharmony_ci{ 281cb0ef41Sopenharmony_ci const { stderr, stdout } = buildSnapshot(entry, env); 291cb0ef41Sopenharmony_ci checkOutput(stderr, stdout); 301cb0ef41Sopenharmony_ci} 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci{ 331cb0ef41Sopenharmony_ci const { stderr, stdout } = runWithSnapshot(entry, env); 341cb0ef41Sopenharmony_ci checkOutput(stderr, stdout); 351cb0ef41Sopenharmony_ci} 36