From a3f66df8215cae36cb32c97a5c6f64eaea8b3fcd Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 23 Aug 2022 23:56:10 +0800 Subject: [PATCH] fixup! fixup! test: log more information in debugger tests --- test/fixtures/snapshot/dns-localhost.js | 26 +++++++++++++ test/internet/test-snapshot-dns.js | 49 +++++++++++++++++++++++++ test/sequential/test-debugger-exec.js | 2 - 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/snapshot/dns-localhost.js create mode 100644 test/internet/test-snapshot-dns.js diff --git a/test/fixtures/snapshot/dns-localhost.js b/test/fixtures/snapshot/dns-localhost.js new file mode 100644 index 00000000000000..447c1b9f5d753c --- /dev/null +++ b/test/fixtures/snapshot/dns-localhost.js @@ -0,0 +1,26 @@ +'use strict'; +const dns = require('dns'); + +const { + setDeserializeMainFunction +} = require('v8').startupSnapshot; + +function query() { + dns.resolve4('nodejs.org', (err, addresses) => { + if (err) throw error; + + console.log(`addresses: ${JSON.stringify(addresses)}`); + + addresses.forEach((a) => { + dns.reverse(a, (err, hostnames) => { + if (err) throw error; + + console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`); + }); + }); + }); +} + +query(); + +setDeserializeMainFunction(query); diff --git a/test/internet/test-snapshot-dns.js b/test/internet/test-snapshot-dns.js new file mode 100644 index 00000000000000..df6e2e7301d0ae --- /dev/null +++ b/test/internet/test-snapshot-dns.js @@ -0,0 +1,49 @@ +'use strict'; + +// This tests support for the dns module in snapshot. + +require('../common'); +const assert = require('assert'); +const { spawnSync } = require('child_process'); +const tmpdir = require('../common/tmpdir'); +const fixtures = require('../common/fixtures'); +const path = require('path'); +const fs = require('fs'); + +tmpdir.refresh(); +const blobPath = path.join(tmpdir.path, 'snapshot.blob'); +const entry = fixtures.path('snapshot', 'dns-local.js'); +{ + const child = spawnSync(process.execPath, [ + '--snapshot-blob', + blobPath, + '--build-snapshot', + entry, + ], { + cwd: tmpdir.path + }); + if (child.status !== 0) { + console.log(child.stderr.toString()); + console.log(child.stdout.toString()); + assert.strictEqual(child.status, 0); + } + const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob')); + assert(stats.isFile()); +} + +{ + const child = spawnSync(process.execPath, [ + '--snapshot-blob', + blobPath, + ], { + cwd: tmpdir.path, + env: { + ...process.env, + } + }); + + const stdout = child.stdout.toString().trim(); + const file = fs.readFileSync(fixtures.path('x1024.txt'), 'utf8'); + assert.strictEqual(stdout, file); + assert.strictEqual(child.status, 0); +} diff --git a/test/sequential/test-debugger-exec.js b/test/sequential/test-debugger-exec.js index 4614913fa6768c..4057dd03785e7c 100644 --- a/test/sequential/test-debugger-exec.js +++ b/test/sequential/test-debugger-exec.js @@ -8,8 +8,6 @@ const startCLI = require('../common/debugger'); const assert = require('assert'); -process.env.NODE_DEBUG = 'inspect'; - { const cli = startCLI([fixtures.path('debugger/alive.js')]);