|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +require('../common'); |
| 4 | + |
| 5 | +const { |
| 6 | + injectAndCodeSign, |
| 7 | + skipIfSingleExecutableIsNotSupported, |
| 8 | +} = require('../common/sea'); |
| 9 | + |
| 10 | +skipIfSingleExecutableIsNotSupported(); |
| 11 | + |
| 12 | +// This tests "useCodeCache" is ignored when "useSnapshot" is true. |
| 13 | + |
| 14 | +const tmpdir = require('../common/tmpdir'); |
| 15 | +const { copyFileSync, writeFileSync, existsSync } = require('fs'); |
| 16 | +const { spawnSync } = require('child_process'); |
| 17 | +const { join } = require('path'); |
| 18 | +const assert = require('assert'); |
| 19 | + |
| 20 | +const configFile = join(tmpdir.path, 'sea-config.json'); |
| 21 | +const seaPrepBlob = join(tmpdir.path, 'sea-prep.blob'); |
| 22 | +const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' : 'sea'); |
| 23 | + |
| 24 | +{ |
| 25 | + tmpdir.refresh(); |
| 26 | + const code = ` |
| 27 | + const { |
| 28 | + setDeserializeMainFunction, |
| 29 | + } = require('v8').startupSnapshot; |
| 30 | +
|
| 31 | + setDeserializeMainFunction(() => { |
| 32 | + console.log('Hello from snapshot'); |
| 33 | + }); |
| 34 | + `; |
| 35 | + |
| 36 | + writeFileSync(join(tmpdir.path, 'snapshot.js'), code, 'utf-8'); |
| 37 | + writeFileSync(configFile, ` |
| 38 | + { |
| 39 | + "main": "snapshot.js", |
| 40 | + "output": "sea-prep.blob", |
| 41 | + "useSnapshot": true, |
| 42 | + "useCodeCache": true |
| 43 | + } |
| 44 | + `); |
| 45 | + |
| 46 | + let child = spawnSync( |
| 47 | + process.execPath, |
| 48 | + ['--experimental-sea-config', 'sea-config.json'], |
| 49 | + { |
| 50 | + cwd: tmpdir.path |
| 51 | + }); |
| 52 | + assert.match( |
| 53 | + child.stderr.toString(), |
| 54 | + /"useCodeCache" is redundant when "useSnapshot" is true/); |
| 55 | + |
| 56 | + assert(existsSync(seaPrepBlob)); |
| 57 | + |
| 58 | + copyFileSync(process.execPath, outputFile); |
| 59 | + injectAndCodeSign(outputFile, seaPrepBlob); |
| 60 | + |
| 61 | + child = spawnSync(outputFile); |
| 62 | + assert.strictEqual(child.stdout.toString().trim(), 'Hello from snapshot'); |
| 63 | +} |
0 commit comments