11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This tests the behavior of loading a UMD module with --build-snapshot 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cirequire('../common'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 81cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 91cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 101cb0ef41Sopenharmony_ciconst path = require('path'); 111cb0ef41Sopenharmony_ciconst fs = require('fs'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_citmpdir.refresh(); 141cb0ef41Sopenharmony_ciconst blobPath = path.join(tmpdir.path, 'snapshot.blob'); 151cb0ef41Sopenharmony_ciconst file = fixtures.path('snapshot', 'marked.js'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci{ 181cb0ef41Sopenharmony_ci // By default, the snapshot blob path is snapshot.blob at cwd 191cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, [ 201cb0ef41Sopenharmony_ci '--snapshot-blob', 211cb0ef41Sopenharmony_ci blobPath, 221cb0ef41Sopenharmony_ci '--build-snapshot', 231cb0ef41Sopenharmony_ci file, 241cb0ef41Sopenharmony_ci ], { 251cb0ef41Sopenharmony_ci cwd: tmpdir.path 261cb0ef41Sopenharmony_ci }); 271cb0ef41Sopenharmony_ci const stderr = child.stderr.toString(); 281cb0ef41Sopenharmony_ci const stdout = child.stdout.toString(); 291cb0ef41Sopenharmony_ci console.log(stderr); 301cb0ef41Sopenharmony_ci console.log(stdout); 311cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob')); 341cb0ef41Sopenharmony_ci assert(stats.isFile()); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci{ 381cb0ef41Sopenharmony_ci let child = spawnSync(process.execPath, [ 391cb0ef41Sopenharmony_ci '--snapshot-blob', 401cb0ef41Sopenharmony_ci path.join(tmpdir.path, 'snapshot.blob'), 411cb0ef41Sopenharmony_ci fixtures.path('snapshot', 'check-marked.js'), 421cb0ef41Sopenharmony_ci ], { 431cb0ef41Sopenharmony_ci cwd: tmpdir.path, 441cb0ef41Sopenharmony_ci env: { 451cb0ef41Sopenharmony_ci ...process.env, 461cb0ef41Sopenharmony_ci NODE_TEST_USE_SNAPSHOT: 'true' 471cb0ef41Sopenharmony_ci } 481cb0ef41Sopenharmony_ci }); 491cb0ef41Sopenharmony_ci let stderr = child.stderr.toString(); 501cb0ef41Sopenharmony_ci const snapshotOutput = child.stdout.toString(); 511cb0ef41Sopenharmony_ci console.log(stderr); 521cb0ef41Sopenharmony_ci console.log(snapshotOutput); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 551cb0ef41Sopenharmony_ci assert(stderr.includes('NODE_TEST_USE_SNAPSHOT true')); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci child = spawnSync(process.execPath, [ 581cb0ef41Sopenharmony_ci '--snapshot-blob', 591cb0ef41Sopenharmony_ci blobPath, 601cb0ef41Sopenharmony_ci fixtures.path('snapshot', 'check-marked.js'), 611cb0ef41Sopenharmony_ci ], { 621cb0ef41Sopenharmony_ci cwd: tmpdir.path, 631cb0ef41Sopenharmony_ci env: { 641cb0ef41Sopenharmony_ci ...process.env, 651cb0ef41Sopenharmony_ci NODE_TEST_USE_SNAPSHOT: 'false' 661cb0ef41Sopenharmony_ci } 671cb0ef41Sopenharmony_ci }); 681cb0ef41Sopenharmony_ci stderr = child.stderr.toString(); 691cb0ef41Sopenharmony_ci const verifyOutput = child.stdout.toString(); 701cb0ef41Sopenharmony_ci console.log(stderr); 711cb0ef41Sopenharmony_ci console.log(verifyOutput); 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 741cb0ef41Sopenharmony_ci assert(stderr.includes('NODE_TEST_USE_SNAPSHOT false')); 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci assert(snapshotOutput.includes(verifyOutput)); 771cb0ef41Sopenharmony_ci} 78