summaryrefslogtreecommitdiff
path: root/test/parallel/test-snapshot-error.js
blob: 32f41244c725e26d71ee2310c4bec424c91a761b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';

// This tests that the errors in the snapshot script can be handled
// properly.

require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const path = require('path');
const fs = require('fs');

tmpdir.refresh();
const blobPath = path.join(tmpdir.path, 'snapshot.blob');
const entry = fixtures.path('snapshot', 'error.js');

// --build-snapshot should be run with an entry point.
{
  const child = spawnSync(process.execPath, [
    '--snapshot-blob',
    blobPath,
    '--build-snapshot',
  ], {
    cwd: tmpdir.path
  });
  const stderr = child.stderr.toString();
  console.log(child.status);
  console.log(stderr);
  console.log(child.stdout.toString());
  assert.strictEqual(child.status, 9);
  assert.match(stderr,
               /--build-snapshot must be used with an entry point script/);
  assert(!fs.existsSync(path.join(tmpdir.path, 'snapshot.blob')));
}

// Loading a non-existent snapshot should fail.
{
  const child = spawnSync(process.execPath, [
    '--snapshot-blob',
    blobPath,
    entry,
  ], {
    cwd: tmpdir.path
  });
  const stderr = child.stderr.toString();
  console.log(child.status);
  console.log(stderr);
  console.log(child.stdout.toString());
  assert.strictEqual(child.status, 14);
  assert.match(stderr, /Cannot open/);
  assert(!fs.existsSync(path.join(tmpdir.path, 'snapshot.blob')));
}


// Running an script that throws an error should result in an exit code of 1.
{
  const child = spawnSync(process.execPath, [
    '--snapshot-blob',
    blobPath,
    '--build-snapshot',
    entry,
  ], {
    cwd: tmpdir.path
  });
  const stderr = child.stderr.toString();
  console.log(child.status);
  console.log(stderr);
  console.log(child.stdout.toString());
  assert.strictEqual(child.status, 1);
  assert.match(stderr, /error\.js:1/);
  assert(!fs.existsSync(path.join(tmpdir.path, 'snapshot.blob')));
}