11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This tests that a program that decompresses a gzip file and saves the 41cb0ef41Sopenharmony_ci// content can be snapshotted and deserialized properly. 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', 'decompress-gzip-sync.js'); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci{ 191cb0ef41Sopenharmony_ci // By default, the snapshot blob path is snapshot.blob at cwd 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 env: { 271cb0ef41Sopenharmony_ci ...process.env, 281cb0ef41Sopenharmony_ci NODE_TEST_FIXTURE: fixtures.path('person.jpg.gz'), 291cb0ef41Sopenharmony_ci NODE_TEST_MODE: 'snapshot' 301cb0ef41Sopenharmony_ci }, 311cb0ef41Sopenharmony_ci cwd: tmpdir.path 321cb0ef41Sopenharmony_ci }); 331cb0ef41Sopenharmony_ci const stderr = child.stderr.toString(); 341cb0ef41Sopenharmony_ci const stdout = child.stdout.toString(); 351cb0ef41Sopenharmony_ci console.log(stderr); 361cb0ef41Sopenharmony_ci console.log(stdout); 371cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob')); 401cb0ef41Sopenharmony_ci assert(stats.isFile()); 411cb0ef41Sopenharmony_ci assert(stdout.includes('NODE_TEST_MODE: snapshot')); 421cb0ef41Sopenharmony_ci} 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci{ 451cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, [ 461cb0ef41Sopenharmony_ci '--snapshot-blob', 471cb0ef41Sopenharmony_ci blobPath, 481cb0ef41Sopenharmony_ci file, 491cb0ef41Sopenharmony_ci ], { 501cb0ef41Sopenharmony_ci env: { 511cb0ef41Sopenharmony_ci ...process.env, 521cb0ef41Sopenharmony_ci NODE_TEST_FIXTURE: fixtures.path('person.jpg.gz'), 531cb0ef41Sopenharmony_ci NODE_TEST_MODE: 'verify' 541cb0ef41Sopenharmony_ci }, 551cb0ef41Sopenharmony_ci cwd: tmpdir.path 561cb0ef41Sopenharmony_ci }); 571cb0ef41Sopenharmony_ci const stderr = child.stderr.toString(); 581cb0ef41Sopenharmony_ci const stdout = child.stdout.toString(); 591cb0ef41Sopenharmony_ci console.log(stderr); 601cb0ef41Sopenharmony_ci console.log(stdout); 611cb0ef41Sopenharmony_ci assert.strictEqual(child.status, 0); 621cb0ef41Sopenharmony_ci assert(stdout.includes('NODE_TEST_MODE: verify')); 631cb0ef41Sopenharmony_ci} 64