1'use strict'; 2 3// This tests that a program that decompresses a gzip file and saves the 4// content can be snapshotted and deserialized properly. 5 6require('../common'); 7const assert = require('assert'); 8const { spawnSync } = require('child_process'); 9const tmpdir = require('../common/tmpdir'); 10const fixtures = require('../common/fixtures'); 11const path = require('path'); 12const fs = require('fs'); 13 14tmpdir.refresh(); 15const blobPath = path.join(tmpdir.path, 'snapshot.blob'); 16const file = fixtures.path('snapshot', 'decompress-gzip-sync.js'); 17 18{ 19 // By default, the snapshot blob path is snapshot.blob at cwd 20 const child = spawnSync(process.execPath, [ 21 '--snapshot-blob', 22 blobPath, 23 '--build-snapshot', 24 file, 25 ], { 26 env: { 27 ...process.env, 28 NODE_TEST_FIXTURE: fixtures.path('person.jpg.gz'), 29 NODE_TEST_MODE: 'snapshot' 30 }, 31 cwd: tmpdir.path 32 }); 33 const stderr = child.stderr.toString(); 34 const stdout = child.stdout.toString(); 35 console.log(stderr); 36 console.log(stdout); 37 assert.strictEqual(child.status, 0); 38 39 const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob')); 40 assert(stats.isFile()); 41 assert(stdout.includes('NODE_TEST_MODE: snapshot')); 42} 43 44{ 45 const child = spawnSync(process.execPath, [ 46 '--snapshot-blob', 47 blobPath, 48 file, 49 ], { 50 env: { 51 ...process.env, 52 NODE_TEST_FIXTURE: fixtures.path('person.jpg.gz'), 53 NODE_TEST_MODE: 'verify' 54 }, 55 cwd: tmpdir.path 56 }); 57 const stderr = child.stderr.toString(); 58 const stdout = child.stdout.toString(); 59 console.log(stderr); 60 console.log(stdout); 61 assert.strictEqual(child.status, 0); 62 assert(stdout.includes('NODE_TEST_MODE: verify')); 63} 64