|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | + |
| 5 | +const { |
| 6 | + injectAndCodeSign, |
| 7 | + skipIfSingleExecutableIsNotSupported, |
| 8 | +} = require('../common/sea'); |
| 9 | + |
| 10 | +skipIfSingleExecutableIsNotSupported(); |
| 11 | + |
| 12 | +// This tests the snapshot support in single executable applications. |
| 13 | +const tmpdir = require('../common/tmpdir'); |
| 14 | + |
| 15 | +const { copyFileSync, writeFileSync, existsSync } = require('fs'); |
| 16 | +const { |
| 17 | + spawnSyncAndExitWithoutError, |
| 18 | +} = require('../common/child_process'); |
| 19 | +const assert = require('assert'); |
| 20 | +const fixtures = require('../common/fixtures'); |
| 21 | + |
| 22 | +tmpdir.refresh(); |
| 23 | +if (!tmpdir.hasEnoughSpace(120 * 1024 * 1024)) { |
| 24 | + common.skip('Not enough disk space'); |
| 25 | +} |
| 26 | + |
| 27 | +const configFile = tmpdir.resolve('sea-config.json'); |
| 28 | +const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); |
| 29 | +const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); |
| 30 | + |
| 31 | +{ |
| 32 | + tmpdir.refresh(); |
| 33 | + copyFileSync(fixtures.path('sea', 'get-asset-raw.js'), tmpdir.resolve('sea.js')); |
| 34 | + copyFileSync(fixtures.path('person.jpg'), tmpdir.resolve('person.jpg')); |
| 35 | + writeFileSync(configFile, ` |
| 36 | + { |
| 37 | + "main": "sea.js", |
| 38 | + "output": "sea-prep.blob", |
| 39 | + "assets": { |
| 40 | + "person.jpg": "person.jpg" |
| 41 | + } |
| 42 | + } |
| 43 | + `, 'utf8'); |
| 44 | + |
| 45 | + spawnSyncAndExitWithoutError( |
| 46 | + process.execPath, |
| 47 | + ['--experimental-sea-config', 'sea-config.json'], |
| 48 | + { |
| 49 | + env: { |
| 50 | + NODE_DEBUG_NATIVE: 'SEA', |
| 51 | + ...process.env, |
| 52 | + }, |
| 53 | + cwd: tmpdir.path |
| 54 | + }, |
| 55 | + {}); |
| 56 | + |
| 57 | + assert(existsSync(seaPrepBlob)); |
| 58 | + |
| 59 | + copyFileSync(process.execPath, outputFile); |
| 60 | + injectAndCodeSign(outputFile, seaPrepBlob); |
| 61 | + |
| 62 | + spawnSyncAndExitWithoutError( |
| 63 | + outputFile, |
| 64 | + { |
| 65 | + env: { |
| 66 | + ...process.env, |
| 67 | + NODE_DEBUG_NATIVE: 'SEA', |
| 68 | + __TEST_PERSON_JPG: fixtures.path('person.jpg'), |
| 69 | + } |
| 70 | + }, |
| 71 | + { } |
| 72 | + ); |
| 73 | +} |
0 commit comments