11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This tests the console works in the deserialized snapshot. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 101cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 111cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 121cb0ef41Sopenharmony_ciconst path = require('path'); 131cb0ef41Sopenharmony_ciconst fs = require('fs'); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_citmpdir.refresh(); 161cb0ef41Sopenharmony_ciconst blobPath = path.join(tmpdir.path, 'snapshot.blob'); 171cb0ef41Sopenharmony_ciconst entry = fixtures.path('snapshot', 'console.js'); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci{ 201cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, [ 211cb0ef41Sopenharmony_ci '--snapshot-blob', 221cb0ef41Sopenharmony_ci blobPath, 231cb0ef41Sopenharmony_ci '--build-snapshot', 241cb0ef41Sopenharmony_ci entry, 251cb0ef41Sopenharmony_ci ], { 261cb0ef41Sopenharmony_ci cwd: tmpdir.path 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci const stdout = child.stdout.toString(); 291cb0ef41Sopenharmony_ci if (child.status !== 0) { 301cb0ef41Sopenharmony_ci console.log(stdout); 311cb0ef41Sopenharmony_ci console.log(child.stderr.toString()); 321cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci assert.deepStrictEqual(Object.keys(console), JSON.parse(stdout)); 351cb0ef41Sopenharmony_ci const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob')); 361cb0ef41Sopenharmony_ci assert(stats.isFile()); 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci{ 401cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, [ 411cb0ef41Sopenharmony_ci '--snapshot-blob', 421cb0ef41Sopenharmony_ci blobPath, 431cb0ef41Sopenharmony_ci ], { 441cb0ef41Sopenharmony_ci cwd: tmpdir.path, 451cb0ef41Sopenharmony_ci env: { 461cb0ef41Sopenharmony_ci ...process.env, 471cb0ef41Sopenharmony_ci } 481cb0ef41Sopenharmony_ci }); 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci const stdout = child.stdout.toString(); 511cb0ef41Sopenharmony_ci if (child.status !== 0) { 521cb0ef41Sopenharmony_ci console.log(stdout); 531cb0ef41Sopenharmony_ci console.log(child.stderr.toString()); 541cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 551cb0ef41Sopenharmony_ci } 561cb0ef41Sopenharmony_ci assert.deepStrictEqual(Object.keys(console), JSON.parse(stdout)); 571cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 581cb0ef41Sopenharmony_ci} 59