1'use strict';
2
3// This tests that user land snapshots works when the instance restored from
4// the snapshot is launched as a CJS module.
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', 'mutate-fs.js');
17const checkFile = fixtures.path('snapshot', 'check-mutate-fs.js');
18
19{
20  // Create the snapshot.
21  const child = spawnSync(process.execPath, [
22    '--snapshot-blob',
23    blobPath,
24    '--build-snapshot',
25    file,
26  ], {
27    cwd: tmpdir.path
28  });
29  if (child.status !== 0) {
30    console.log(child.stderr.toString());
31    console.log(child.stdout.toString());
32    assert.strictEqual(child.status, 0);
33  }
34  const stats = fs.statSync(blobPath);
35  assert(stats.isFile());
36}
37
38{
39  // Run the check file as a CJS module
40  const child = spawnSync(process.execPath, [
41    '--snapshot-blob',
42    blobPath,
43    checkFile,
44  ], {
45    cwd: tmpdir.path
46  });
47
48  if (child.status !== 0) {
49    console.log(child.stderr.toString());
50    console.log(child.stdout.toString());
51    assert.strictEqual(child.status, 0);
52  }
53}
54