11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This tests that user land snapshots works when the instance restored from 41cb0ef41Sopenharmony_ci// the snapshot is launched with -p and -e 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_cirequire('../common'); 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 91cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 101cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 111cb0ef41Sopenharmony_ciconst path = require('path'); 121cb0ef41Sopenharmony_ciconst fs = require('fs'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_citmpdir.refresh(); 151cb0ef41Sopenharmony_ciconst blobPath = path.join(tmpdir.path, 'snapshot.blob'); 161cb0ef41Sopenharmony_ciconst file = fixtures.path('snapshot', 'mutate-fs.js'); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci{ 191cb0ef41Sopenharmony_ci // Create the snapshot. 201cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, [ 211cb0ef41Sopenharmony_ci '--snapshot-blob', 221cb0ef41Sopenharmony_ci blobPath, 231cb0ef41Sopenharmony_ci '--build-snapshot', 241cb0ef41Sopenharmony_ci file, 251cb0ef41Sopenharmony_ci ], { 261cb0ef41Sopenharmony_ci cwd: tmpdir.path 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci if (child.status !== 0) { 291cb0ef41Sopenharmony_ci console.log(child.stderr.toString()); 301cb0ef41Sopenharmony_ci console.log(child.stdout.toString()); 311cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci const stats = fs.statSync(blobPath); 341cb0ef41Sopenharmony_ci assert(stats.isFile()); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci{ 381cb0ef41Sopenharmony_ci // Check -p works. 391cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, [ 401cb0ef41Sopenharmony_ci '--snapshot-blob', 411cb0ef41Sopenharmony_ci blobPath, 421cb0ef41Sopenharmony_ci '-p', 431cb0ef41Sopenharmony_ci 'require("fs").foo', 441cb0ef41Sopenharmony_ci ], { 451cb0ef41Sopenharmony_ci cwd: tmpdir.path 461cb0ef41Sopenharmony_ci }); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci if (child.status !== 0) { 491cb0ef41Sopenharmony_ci console.log(child.stderr.toString()); 501cb0ef41Sopenharmony_ci console.log(child.stdout.toString()); 511cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci assert(/I am from the snapshot/.test(child.stdout.toString())); 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci{ 571cb0ef41Sopenharmony_ci // Check -e works. 581cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, [ 591cb0ef41Sopenharmony_ci '--snapshot-blob', 601cb0ef41Sopenharmony_ci blobPath, 611cb0ef41Sopenharmony_ci '-e', 621cb0ef41Sopenharmony_ci 'console.log(require("fs").foo)', 631cb0ef41Sopenharmony_ci ], { 641cb0ef41Sopenharmony_ci cwd: tmpdir.path 651cb0ef41Sopenharmony_ci }); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci if (child.status !== 0) { 681cb0ef41Sopenharmony_ci console.log(child.stderr.toString()); 691cb0ef41Sopenharmony_ci console.log(child.stdout.toString()); 701cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 711cb0ef41Sopenharmony_ci } 721cb0ef41Sopenharmony_ci assert(/I am from the snapshot/.test(child.stdout.toString())); 731cb0ef41Sopenharmony_ci} 74