-
Notifications
You must be signed in to change notification settings - Fork 28.1k
/
test-snapshot-config.js
139 lines (130 loc) Β· 3.09 KB
/
test-snapshot-config.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'use strict';
// This tests --build-snapshot-config.
require('../common');
const assert = require('assert');
const {
spawnSyncAndAssert,
spawnSyncAndExit,
spawnSyncAndExitWithoutError,
} = require('../common/child_process');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const fs = require('fs');
const blobPath = tmpdir.resolve('snapshot.blob');
const builderScript = fixtures.path('snapshot', 'mutate-fs.js');
const checkFile = fixtures.path('snapshot', 'check-mutate-fs.js');
const configPath = tmpdir.resolve('snapshot.json');
tmpdir.refresh();
{
// Relative path.
spawnSyncAndExit(process.execPath, [
'--snapshot-blob',
blobPath,
'--build-snapshot-config',
'snapshot.json',
], {
cwd: tmpdir.path
}, {
signal: null,
status: 1,
trim: true,
stderr: /Cannot read snapshot configuration from snapshot\.json/
});
// Absolute path.
spawnSyncAndExit(process.execPath, [
'--snapshot-blob',
blobPath,
'--build-snapshot-config',
configPath,
], {
cwd: tmpdir.path
}, {
signal: null,
status: 1,
trim: true,
stderr: /Cannot read snapshot configuration from .+snapshot\.json/
});
}
function writeConfig(config) {
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf8');
}
{
tmpdir.refresh();
// Config without "builder" field should be rejected.
writeConfig({});
spawnSyncAndExit(process.execPath, [
'--snapshot-blob',
blobPath,
'--build-snapshot-config',
configPath,
], {
cwd: tmpdir.path
}, {
signal: null,
status: 1,
trim: true,
stderr: /"builder" field of .+snapshot\.json is not a non-empty string/
});
}
let sizeWithCache;
{
tmpdir.refresh();
// Create a working snapshot.
writeConfig({ builder: builderScript });
spawnSyncAndExitWithoutError(process.execPath, [
'--snapshot-blob',
blobPath,
'--build-snapshot-config',
configPath,
], {
cwd: tmpdir.path
});
const stats = fs.statSync(blobPath);
assert(stats.isFile());
sizeWithCache = stats.size;
// Check the snapshot.
spawnSyncAndExitWithoutError(process.execPath, [
'--snapshot-blob',
blobPath,
checkFile,
], {
cwd: tmpdir.path
});
}
let sizeWithoutCache;
{
tmpdir.refresh();
// Create a working snapshot.
writeConfig({ builder: builderScript, withoutCodeCache: true });
spawnSyncAndExitWithoutError(process.execPath, [
'--snapshot-blob',
blobPath,
'--build-snapshot-config',
configPath,
], {
env: {
...process.env,
NODE_DEBUG_NATIVE: 'CODE_CACHE'
},
cwd: tmpdir.path
});
const stats = fs.statSync(blobPath);
assert(stats.isFile());
sizeWithoutCache = stats.size;
assert(sizeWithoutCache < sizeWithCache,
`sizeWithoutCache = ${sizeWithoutCache} >= sizeWithCache ${sizeWithCache}`);
// Check the snapshot.
spawnSyncAndAssert(process.execPath, [
'--snapshot-blob',
blobPath,
checkFile,
], {
cwd: tmpdir.path,
env: {
...process.env,
NODE_DEBUG_NATIVE: 'CODE_CACHE'
},
}, {
stderr: /snapshot contains 0 code cache/
});
}