diff --git a/test/common/sea.js b/test/common/sea.js index 53bfd93d927..2ba5de286fd 100644 --- a/test/common/sea.js +++ b/test/common/sea.js @@ -4,6 +4,9 @@ const common = require('../common'); const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); const { inspect } = require('util'); +const fs = require('fs'); +const path = require('path'); +const assert = require('assert'); const { readFileSync, copyFileSync, statSync } = require('fs'); const { @@ -70,37 +73,76 @@ function skipIfSingleExecutableIsNotSupported() { } } -function generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow = false) { +function generateSEA(fixtureDir, options = {}) { + const { + workingDir = tmpdir.path, + configPath = 'sea-config.json', + verifyWorkflow = false, + } = options; + // Copy fixture files to working directory if they are different. + if (fixtureDir !== workingDir) { + fs.cpSync(fixtureDir, workingDir, { recursive: true }); + } + + // Determine the output executable path. + const outputFile = path.resolve(workingDir, process.platform === 'win32' ? 'sea.exe' : 'sea'); + try { - copyFileSync(sourceExecutable, targetExecutable); + // Copy the executable. + copyFileSync(process.execPath, outputFile); + console.log(`Copied ${process.execPath} to ${outputFile}`); } catch (e) { - const message = `Cannot copy ${sourceExecutable} to ${targetExecutable}: ${inspect(e)}`; + const message = `Cannot copy ${process.execPath} to ${outputFile}: ${inspect(e)}`; if (verifyWorkflow) { throw new Error(message); } common.skip(message); } - console.log(`Copied ${sourceExecutable} to ${targetExecutable}`); + // Generate the blob using --experimental-sea-config. + spawnSyncAndExitWithoutError( + process.execPath, + ['--experimental-sea-config', configPath], + { + cwd: workingDir, + env: { + NODE_DEBUG_NATIVE: 'SEA', + ...process.env, + }, + }, + ); + + // Parse the config to get the output file path. + const config = JSON.parse(fs.readFileSync(path.resolve(workingDir, configPath))); + assert.strictEqual(typeof config.output, 'string'); + const seaPrepBlob = path.resolve(workingDir, config.output); + assert(fs.existsSync(seaPrepBlob), `Expected SEA blob ${seaPrepBlob} to exist`); + + // Use postject to inject the blob. const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js'); try { spawnSyncAndExitWithoutError(process.execPath, [ postjectFile, - targetExecutable, + outputFile, 'NODE_SEA_BLOB', - seaBlob, + seaPrepBlob, '--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2', ...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [], ]); } catch (e) { - const message = `Cannot inject ${seaBlob} into ${targetExecutable}: ${inspect(e)}`; + const message = `Cannot inject ${seaPrepBlob} into ${outputFile}: ${inspect(e)}`; if (verifyWorkflow) { throw new Error(message); } common.skip(message); } - console.log(`Injected ${seaBlob} into ${targetExecutable}`); + console.log(`Injected ${seaPrepBlob} into ${outputFile}`); + signSEA(outputFile, verifyWorkflow); + return outputFile; +} + +function signSEA(targetExecutable, verifyWorkflow = false) { if (process.platform === 'darwin') { try { spawnSyncAndExitWithoutError('codesign', [ '--sign', '-', targetExecutable ]); diff --git a/test/fixtures/sea/addon/sea-config.json b/test/fixtures/sea/addon/sea-config.json new file mode 100644 index 00000000000..8e9f7d86f7a --- /dev/null +++ b/test/fixtures/sea/addon/sea-config.json @@ -0,0 +1,8 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "disableExperimentalSEAWarning": true, + "assets": { + "hello.node": "binding.node" + } +} diff --git a/test/fixtures/sea/addon/sea.js b/test/fixtures/sea/addon/sea.js new file mode 100644 index 00000000000..c7e62a733c3 --- /dev/null +++ b/test/fixtures/sea/addon/sea.js @@ -0,0 +1,9 @@ +const sea = require('node:sea'); +const fs = require('fs'); +const path = require('path'); + +const addonPath = path.join(process.cwd(), 'hello.node'); +fs.writeFileSync(addonPath, new Uint8Array(sea.getRawAsset('hello.node'))); +const mod = {exports: {}}; +process.dlopen(mod, addonPath); +console.log('hello,', mod.exports.hello()); diff --git a/test/fixtures/sea/asset-keys-empty/sea-config.json b/test/fixtures/sea/asset-keys-empty/sea-config.json new file mode 100644 index 00000000000..8acf995f9ae --- /dev/null +++ b/test/fixtures/sea/asset-keys-empty/sea-config.json @@ -0,0 +1,4 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob" +} diff --git a/test/fixtures/sea/get-asset-keys.js b/test/fixtures/sea/asset-keys-empty/sea.js similarity index 100% rename from test/fixtures/sea/get-asset-keys.js rename to test/fixtures/sea/asset-keys-empty/sea.js diff --git a/test/fixtures/sea/asset-keys/asset-1.txt b/test/fixtures/sea/asset-keys/asset-1.txt new file mode 100644 index 00000000000..4034524332e --- /dev/null +++ b/test/fixtures/sea/asset-keys/asset-1.txt @@ -0,0 +1 @@ +This is asset 1 diff --git a/test/fixtures/sea/asset-keys/asset-2.txt b/test/fixtures/sea/asset-keys/asset-2.txt new file mode 100644 index 00000000000..d61c042511d --- /dev/null +++ b/test/fixtures/sea/asset-keys/asset-2.txt @@ -0,0 +1 @@ +This is asset 2 diff --git a/test/fixtures/sea/asset-keys/asset-3.txt b/test/fixtures/sea/asset-keys/asset-3.txt new file mode 100644 index 00000000000..cc9f44832da --- /dev/null +++ b/test/fixtures/sea/asset-keys/asset-3.txt @@ -0,0 +1 @@ +This is asset 3 diff --git a/test/fixtures/sea/asset-keys/sea-config.json b/test/fixtures/sea/asset-keys/sea-config.json new file mode 100644 index 00000000000..250fef01e98 --- /dev/null +++ b/test/fixtures/sea/asset-keys/sea-config.json @@ -0,0 +1,9 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "assets": { + "asset-1.txt": "asset-1.txt", + "asset-2.txt": "asset-2.txt", + "asset-3.txt": "asset-3.txt" + } +} diff --git a/test/fixtures/sea/asset-keys/sea.js b/test/fixtures/sea/asset-keys/sea.js new file mode 100644 index 00000000000..2330b8fa3d9 --- /dev/null +++ b/test/fixtures/sea/asset-keys/sea.js @@ -0,0 +1,9 @@ +'use strict'; + +const { isSea, getAssetKeys } = require('node:sea'); +const assert = require('node:assert'); + +assert(isSea()); + +const keys = getAssetKeys(); +console.log('Asset keys:', JSON.stringify(keys.sort())); diff --git a/test/fixtures/sea/assets-invalid-type/sea-config.json b/test/fixtures/sea/assets-invalid-type/sea-config.json new file mode 100644 index 00000000000..418df8cf78f --- /dev/null +++ b/test/fixtures/sea/assets-invalid-type/sea-config.json @@ -0,0 +1,5 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "assets": "invalid" +} diff --git a/test/fixtures/sea/assets-invalid-type/sea.js b/test/fixtures/sea/assets-invalid-type/sea.js new file mode 100644 index 00000000000..71e4a5e1aac --- /dev/null +++ b/test/fixtures/sea/assets-invalid-type/sea.js @@ -0,0 +1,3 @@ +'use strict'; +// This file is used for testing invalid "assets" configuration. +// It should not be executed because the configuration should fail. diff --git a/test/fixtures/sea/assets-nonexistent-file/sea-config.json b/test/fixtures/sea/assets-nonexistent-file/sea-config.json new file mode 100644 index 00000000000..f4549fe6377 --- /dev/null +++ b/test/fixtures/sea/assets-nonexistent-file/sea-config.json @@ -0,0 +1,7 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "assets": { + "nonexistent": "nonexistent.txt" + } +} diff --git a/test/fixtures/sea/assets-nonexistent-file/sea.js b/test/fixtures/sea/assets-nonexistent-file/sea.js new file mode 100644 index 00000000000..340e8ecac75 --- /dev/null +++ b/test/fixtures/sea/assets-nonexistent-file/sea.js @@ -0,0 +1,3 @@ +'use strict'; +// This file is used for testing nonexistent asset file. +// It should not be executed because the configuration should fail. diff --git a/test/fixtures/sea/assets-raw/person.jpg b/test/fixtures/sea/assets-raw/person.jpg new file mode 100644 index 00000000000..96d46888d76 Binary files /dev/null and b/test/fixtures/sea/assets-raw/person.jpg differ diff --git a/test/fixtures/sea/assets-raw/sea-config.json b/test/fixtures/sea/assets-raw/sea-config.json new file mode 100644 index 00000000000..d854b4f4507 --- /dev/null +++ b/test/fixtures/sea/assets-raw/sea-config.json @@ -0,0 +1,7 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "assets": { + "person.jpg": "person.jpg" + } +} diff --git a/test/fixtures/sea/get-asset-raw.js b/test/fixtures/sea/assets-raw/sea.js similarity index 100% rename from test/fixtures/sea/get-asset-raw.js rename to test/fixtures/sea/assets-raw/sea.js diff --git a/test/fixtures/sea/assets/person.jpg b/test/fixtures/sea/assets/person.jpg new file mode 100644 index 00000000000..96d46888d76 Binary files /dev/null and b/test/fixtures/sea/assets/person.jpg differ diff --git a/test/fixtures/sea/assets/sea-config.json b/test/fixtures/sea/assets/sea-config.json new file mode 100644 index 00000000000..78a64534b44 --- /dev/null +++ b/test/fixtures/sea/assets/sea-config.json @@ -0,0 +1,8 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "assets": { + "utf8_test_text.txt": "utf8_test_text.txt", + "person.jpg": "person.jpg" + } +} diff --git a/test/fixtures/sea/get-asset.js b/test/fixtures/sea/assets/sea.js similarity index 100% rename from test/fixtures/sea/get-asset.js rename to test/fixtures/sea/assets/sea.js diff --git a/test/fixtures/sea/assets/utf8_test_text.txt b/test/fixtures/sea/assets/utf8_test_text.txt new file mode 100644 index 00000000000..f4b6fc9bcfc --- /dev/null +++ b/test/fixtures/sea/assets/utf8_test_text.txt @@ -0,0 +1 @@ +永和九年,嵗在癸丑,暮春之初,會於會稽山隂之蘭亭,脩稧事也。羣賢畢至,少長咸集。此地有崇山峻領,茂林脩竹;又有清流激湍,暎帶左右。引以為流觴曲水,列坐其次。雖無絲竹管弦之盛,一觴一詠,亦足以暢敘幽情。是日也,天朗氣清,恵風和暢;仰觀宇宙之大,俯察品類之盛;所以遊目騁懐,足以極視聽之娛,信可樂也。夫人之相與,俯仰一世,或取諸懐抱,悟言一室之內,或因寄所託,放浪形骸之外。雖趣舎萬殊,靜躁不同,當其欣扵所遇,暫得扵己,怏然自足,不知老之將至。及其所之既惓,情隨事遷,感慨係之矣。向之所欣,俛仰之閒以為陳跡,猶不能不以之興懐;況脩短隨化,終期扵盡。古人云:「死生亦大矣。」豈不痛哉!每攬昔人興感之由,若合一契,未嘗不臨文嗟悼,不能喻之扵懐。固知一死生為虛誕,齊彭殤為妄作。後之視今,亦由今之視昔,悲夫!故列敘時人,錄其所述,雖世殊事異,所以興懐,其致一也。後之攬者,亦將有感扵斯文。 \ No newline at end of file diff --git a/test/fixtures/sea/disable-experimental-warning/requirable.js b/test/fixtures/sea/disable-experimental-warning/requirable.js new file mode 100644 index 00000000000..69f1fd8c377 --- /dev/null +++ b/test/fixtures/sea/disable-experimental-warning/requirable.js @@ -0,0 +1,3 @@ +module.exports = { + hello: 'world', +}; diff --git a/test/fixtures/sea/disable-experimental-warning/sea-config.json b/test/fixtures/sea/disable-experimental-warning/sea-config.json new file mode 100644 index 00000000000..9318271c734 --- /dev/null +++ b/test/fixtures/sea/disable-experimental-warning/sea-config.json @@ -0,0 +1,5 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "disableExperimentalSEAWarning": true +} diff --git a/test/fixtures/sea/disable-experimental-warning/sea.js b/test/fixtures/sea/disable-experimental-warning/sea.js new file mode 100644 index 00000000000..65bb8d37e01 --- /dev/null +++ b/test/fixtures/sea/disable-experimental-warning/sea.js @@ -0,0 +1,64 @@ +const { Module: { createRequire } } = require('module'); +const createdRequire = createRequire(__filename); + +// Although, require('../common') works locally, that couldn't be used here +// because we set NODE_TEST_DIR=/Users/iojs/node-tmp on Jenkins CI. +const { expectWarning, mustNotCall } = createdRequire(process.env.COMMON_DIRECTORY); + +const builtinWarning = +`Currently the require() provided to the main script embedded into single-executable applications only supports loading built-in modules. +To load a module from disk after the single executable application is launched, use require("module").createRequire(). +Support for bundled module loading or virtual file systems are under discussions in https://github.com/nodejs/single-executable`; + +// This additionally makes sure that no unexpected warnings are emitted. +if (!createdRequire('./sea-config.json').disableExperimentalSEAWarning) { + expectWarning('Warning', builtinWarning); // Triggered by require() calls below. + expectWarning('ExperimentalWarning', + 'Single executable application is an experimental feature and ' + + 'might change at any time'); + // Any unexpected warning would throw this error: + // https://github.com/nodejs/node/blob/c301404105a7256b79a0b8c4522ce47af96dfa17/test/common/index.js#L697-L700. +} + +// Should be possible to require core modules that optionally require the +// "node:" scheme. +const { deepStrictEqual, strictEqual, throws } = require('assert'); +const { dirname } = require('node:path'); + +// Checks that the source filename is used in the error stack trace. +strictEqual(new Error('lol').stack.split('\n')[1], ' at sea.js:29:13'); + +// Should be possible to require a core module that requires using the "node:" +// scheme. +{ + const { test } = require('node:test'); + strictEqual(typeof test, 'function'); +} + +// Should not be possible to require a core module without the "node:" scheme if +// it requires using the "node:" scheme. +throws(() => require('test'), { + code: 'ERR_UNKNOWN_BUILTIN_MODULE', +}); + +deepStrictEqual(process.argv, [process.execPath, process.execPath, '-a', '--b=c', 'd']); + +strictEqual(require.cache, undefined); +strictEqual(require.extensions, undefined); +strictEqual(require.main, module); +strictEqual(require.resolve, undefined); + +strictEqual(__filename, process.execPath); +strictEqual(__dirname, dirname(process.execPath)); +strictEqual(module.exports, exports); + +throws(() => require('./requirable.js'), { + code: 'ERR_UNKNOWN_BUILTIN_MODULE', +}); + +const requirable = createdRequire('./requirable.js'); +deepStrictEqual(requirable, { + hello: 'world', +}); + +console.log('Hello, world! 😊'); diff --git a/test/fixtures/sea/empty/empty.js b/test/fixtures/sea/empty/empty.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/fixtures/sea/empty/sea-config.json b/test/fixtures/sea/empty/sea-config.json new file mode 100644 index 00000000000..cd76437e265 --- /dev/null +++ b/test/fixtures/sea/empty/sea-config.json @@ -0,0 +1,4 @@ +{ + "main": "empty.js", + "output": "sea-prep.blob" +} diff --git a/test/fixtures/sea/exec-argv-empty/sea-config.json b/test/fixtures/sea/exec-argv-empty/sea-config.json new file mode 100644 index 00000000000..11b06a6c764 --- /dev/null +++ b/test/fixtures/sea/exec-argv-empty/sea-config.json @@ -0,0 +1,6 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "disableExperimentalSEAWarning": true, + "execArgv": [] +} diff --git a/test/fixtures/sea/exec-argv-empty/sea.js b/test/fixtures/sea/exec-argv-empty/sea.js new file mode 100644 index 00000000000..1c98860ba34 --- /dev/null +++ b/test/fixtures/sea/exec-argv-empty/sea.js @@ -0,0 +1,6 @@ +const assert = require('assert'); + +console.log('process.argv:', JSON.stringify(process.argv)); +assert.strictEqual(process.argv[2], 'user-arg'); +assert.deepStrictEqual(process.execArgv, []); +console.log('empty execArgv test passed'); diff --git a/test/fixtures/sea/exec-argv-extension-cli/sea-config.json b/test/fixtures/sea/exec-argv-extension-cli/sea-config.json new file mode 100644 index 00000000000..0ec0d706b38 --- /dev/null +++ b/test/fixtures/sea/exec-argv-extension-cli/sea-config.json @@ -0,0 +1,7 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "disableExperimentalSEAWarning": true, + "execArgv": ["--no-warnings"], + "execArgvExtension": "cli" +} diff --git a/test/fixtures/sea/exec-argv-extension-cli/sea.js b/test/fixtures/sea/exec-argv-extension-cli/sea.js new file mode 100644 index 00000000000..e9585483fcc --- /dev/null +++ b/test/fixtures/sea/exec-argv-extension-cli/sea.js @@ -0,0 +1,14 @@ +const assert = require('assert'); + +console.log('process.argv:', JSON.stringify(process.argv)); +console.log('process.execArgv:', JSON.stringify(process.execArgv)); + +// Should have execArgv from SEA config + CLI --node-options +assert.deepStrictEqual(process.execArgv, ['--no-warnings', '--max-old-space-size=1024']); + +assert.deepStrictEqual(process.argv.slice(2), [ + 'user-arg1', + 'user-arg2' +]); + +console.log('execArgvExtension cli test passed'); diff --git a/test/fixtures/sea/exec-argv-extension-env/sea-config.json b/test/fixtures/sea/exec-argv-extension-env/sea-config.json new file mode 100644 index 00000000000..f0d098bdb1d --- /dev/null +++ b/test/fixtures/sea/exec-argv-extension-env/sea-config.json @@ -0,0 +1,7 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "disableExperimentalSEAWarning": true, + "execArgv": ["--no-warnings"], + "execArgvExtension": "env" +} diff --git a/test/fixtures/sea/exec-argv-extension-env/sea.js b/test/fixtures/sea/exec-argv-extension-env/sea.js new file mode 100644 index 00000000000..1d706dfe7cf --- /dev/null +++ b/test/fixtures/sea/exec-argv-extension-env/sea.js @@ -0,0 +1,19 @@ +const assert = require('assert'); + +process.emitWarning('This warning should not be shown in the output', 'TestWarning'); + +console.log('process.argv:', JSON.stringify(process.argv)); +console.log('process.execArgv:', JSON.stringify(process.execArgv)); + +// Should have execArgv from SEA config. +// Note that flags from NODE_OPTIONS are not included in process.execArgv no matter it's +// an SEA or not, but we can test whether it works by checking that the warning emitted +// above was silenced. +assert.deepStrictEqual(process.execArgv, ['--no-warnings']); + +assert.deepStrictEqual(process.argv.slice(2), [ + 'user-arg1', + 'user-arg2' +]); + +console.log('execArgvExtension env test passed'); diff --git a/test/fixtures/sea/exec-argv-extension-none/sea-config.json b/test/fixtures/sea/exec-argv-extension-none/sea-config.json new file mode 100644 index 00000000000..15c7447abcf --- /dev/null +++ b/test/fixtures/sea/exec-argv-extension-none/sea-config.json @@ -0,0 +1,7 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "disableExperimentalSEAWarning": true, + "execArgv": ["--no-warnings"], + "execArgvExtension": "none" +} diff --git a/test/fixtures/sea/exec-argv-extension-none/sea.js b/test/fixtures/sea/exec-argv-extension-none/sea.js new file mode 100644 index 00000000000..c089b065677 --- /dev/null +++ b/test/fixtures/sea/exec-argv-extension-none/sea.js @@ -0,0 +1,14 @@ +const assert = require('assert'); + +console.log('process.argv:', JSON.stringify(process.argv)); +console.log('process.execArgv:', JSON.stringify(process.execArgv)); + +// Should only have execArgv from SEA config, no NODE_OPTIONS +assert.deepStrictEqual(process.execArgv, ['--no-warnings']); + +assert.deepStrictEqual(process.argv.slice(2), [ + 'user-arg1', + 'user-arg2' +]); + +console.log('execArgvExtension none test passed'); diff --git a/test/fixtures/sea/exec-argv/sea-config.json b/test/fixtures/sea/exec-argv/sea-config.json new file mode 100644 index 00000000000..d32cbd22e32 --- /dev/null +++ b/test/fixtures/sea/exec-argv/sea-config.json @@ -0,0 +1,6 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "disableExperimentalSEAWarning": true, + "execArgv": ["--no-warnings", "--max-old-space-size=2048"] +} diff --git a/test/fixtures/sea/exec-argv/sea.js b/test/fixtures/sea/exec-argv/sea.js new file mode 100644 index 00000000000..7f0f8ece575 --- /dev/null +++ b/test/fixtures/sea/exec-argv/sea.js @@ -0,0 +1,18 @@ +const assert = require('assert'); + +process.emitWarning('This warning should not be shown in the output', 'TestWarning'); + +console.log('process.argv:', JSON.stringify(process.argv)); +console.log('process.execArgv:', JSON.stringify(process.execArgv)); + +assert.deepStrictEqual(process.execArgv, [ '--no-warnings', '--max-old-space-size=2048' ]); + +// We start from 2, because in SEA, the index 1 would be the same as the execPath +// to accommodate the general expectation that index 1 is the path to script for +// applications. +assert.deepStrictEqual(process.argv.slice(2), [ + 'user-arg1', + 'user-arg2' +]); + +console.log('multiple execArgv test passed'); diff --git a/test/fixtures/sea/inspect-in-sea-flags/sea-config.json b/test/fixtures/sea/inspect-in-sea-flags/sea-config.json new file mode 100644 index 00000000000..8acf995f9ae --- /dev/null +++ b/test/fixtures/sea/inspect-in-sea-flags/sea-config.json @@ -0,0 +1,4 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob" +} diff --git a/test/fixtures/sea/inspect-in-sea-flags/sea.js b/test/fixtures/sea/inspect-in-sea-flags/sea.js new file mode 100644 index 00000000000..ab74fd7b799 --- /dev/null +++ b/test/fixtures/sea/inspect-in-sea-flags/sea.js @@ -0,0 +1 @@ +console.log(process.argv); diff --git a/test/fixtures/sea/inspect/hello.js b/test/fixtures/sea/inspect/hello.js new file mode 100644 index 00000000000..e9fe0090d63 --- /dev/null +++ b/test/fixtures/sea/inspect/hello.js @@ -0,0 +1 @@ +console.log('Hello, world!'); diff --git a/test/fixtures/sea/inspect/sea-config.json b/test/fixtures/sea/inspect/sea-config.json new file mode 100644 index 00000000000..96c7d51e65d --- /dev/null +++ b/test/fixtures/sea/inspect/sea-config.json @@ -0,0 +1,4 @@ +{ + "main": "hello.js", + "output": "sea-prep.blob" +} diff --git a/test/fixtures/sea/simple/requirable.js b/test/fixtures/sea/simple/requirable.js new file mode 100644 index 00000000000..69f1fd8c377 --- /dev/null +++ b/test/fixtures/sea/simple/requirable.js @@ -0,0 +1,3 @@ +module.exports = { + hello: 'world', +}; diff --git a/test/fixtures/sea/simple/sea-config.json b/test/fixtures/sea/simple/sea-config.json new file mode 100644 index 00000000000..c1dec576ecc --- /dev/null +++ b/test/fixtures/sea/simple/sea-config.json @@ -0,0 +1,6 @@ + +{ + "main": "sea.js", + "output": "snapshot.blob", + "disableExperimentalSEAWarning": true +} diff --git a/test/fixtures/sea/simple/sea.js b/test/fixtures/sea/simple/sea.js new file mode 100644 index 00000000000..65bb8d37e01 --- /dev/null +++ b/test/fixtures/sea/simple/sea.js @@ -0,0 +1,64 @@ +const { Module: { createRequire } } = require('module'); +const createdRequire = createRequire(__filename); + +// Although, require('../common') works locally, that couldn't be used here +// because we set NODE_TEST_DIR=/Users/iojs/node-tmp on Jenkins CI. +const { expectWarning, mustNotCall } = createdRequire(process.env.COMMON_DIRECTORY); + +const builtinWarning = +`Currently the require() provided to the main script embedded into single-executable applications only supports loading built-in modules. +To load a module from disk after the single executable application is launched, use require("module").createRequire(). +Support for bundled module loading or virtual file systems are under discussions in https://github.com/nodejs/single-executable`; + +// This additionally makes sure that no unexpected warnings are emitted. +if (!createdRequire('./sea-config.json').disableExperimentalSEAWarning) { + expectWarning('Warning', builtinWarning); // Triggered by require() calls below. + expectWarning('ExperimentalWarning', + 'Single executable application is an experimental feature and ' + + 'might change at any time'); + // Any unexpected warning would throw this error: + // https://github.com/nodejs/node/blob/c301404105a7256b79a0b8c4522ce47af96dfa17/test/common/index.js#L697-L700. +} + +// Should be possible to require core modules that optionally require the +// "node:" scheme. +const { deepStrictEqual, strictEqual, throws } = require('assert'); +const { dirname } = require('node:path'); + +// Checks that the source filename is used in the error stack trace. +strictEqual(new Error('lol').stack.split('\n')[1], ' at sea.js:29:13'); + +// Should be possible to require a core module that requires using the "node:" +// scheme. +{ + const { test } = require('node:test'); + strictEqual(typeof test, 'function'); +} + +// Should not be possible to require a core module without the "node:" scheme if +// it requires using the "node:" scheme. +throws(() => require('test'), { + code: 'ERR_UNKNOWN_BUILTIN_MODULE', +}); + +deepStrictEqual(process.argv, [process.execPath, process.execPath, '-a', '--b=c', 'd']); + +strictEqual(require.cache, undefined); +strictEqual(require.extensions, undefined); +strictEqual(require.main, module); +strictEqual(require.resolve, undefined); + +strictEqual(__filename, process.execPath); +strictEqual(__dirname, dirname(process.execPath)); +strictEqual(module.exports, exports); + +throws(() => require('./requirable.js'), { + code: 'ERR_UNKNOWN_BUILTIN_MODULE', +}); + +const requirable = createdRequire('./requirable.js'); +deepStrictEqual(requirable, { + hello: 'world', +}); + +console.log('Hello, world! 😊'); diff --git a/test/fixtures/sea/snapshot-and-code-cache/sea-config.json b/test/fixtures/sea/snapshot-and-code-cache/sea-config.json new file mode 100644 index 00000000000..9913b1a4e94 --- /dev/null +++ b/test/fixtures/sea/snapshot-and-code-cache/sea-config.json @@ -0,0 +1,6 @@ +{ + "main": "snapshot.js", + "output": "sea-prep.blob", + "useSnapshot": true, + "useCodeCache": true +} diff --git a/test/fixtures/sea/snapshot-and-code-cache/snapshot.js b/test/fixtures/sea/snapshot-and-code-cache/snapshot.js new file mode 100644 index 00000000000..39b51a0324f --- /dev/null +++ b/test/fixtures/sea/snapshot-and-code-cache/snapshot.js @@ -0,0 +1,7 @@ +const { + setDeserializeMainFunction, +} = require('v8').startupSnapshot; + +setDeserializeMainFunction(() => { + console.log('Hello from snapshot'); +}); diff --git a/test/fixtures/sea/snapshot-worker/sea-config.json b/test/fixtures/sea/snapshot-worker/sea-config.json new file mode 100644 index 00000000000..d4d3f30853c --- /dev/null +++ b/test/fixtures/sea/snapshot-worker/sea-config.json @@ -0,0 +1,5 @@ +{ + "main": "snapshot.js", + "output": "sea-prep.blob", + "useSnapshot": true +} diff --git a/test/fixtures/sea/snapshot-worker/snapshot.js b/test/fixtures/sea/snapshot-worker/snapshot.js new file mode 100644 index 00000000000..438090b3b76 --- /dev/null +++ b/test/fixtures/sea/snapshot-worker/snapshot.js @@ -0,0 +1,8 @@ +const { + setDeserializeMainFunction, +} = require('v8').startupSnapshot; + +setDeserializeMainFunction(() => { + const { Worker } = require('worker_threads'); + new Worker("console.log('Hello from Worker')", { eval: true }); +}); diff --git a/test/fixtures/sea/snapshot/sea-config.json b/test/fixtures/sea/snapshot/sea-config.json new file mode 100644 index 00000000000..d4d3f30853c --- /dev/null +++ b/test/fixtures/sea/snapshot/sea-config.json @@ -0,0 +1,5 @@ +{ + "main": "snapshot.js", + "output": "sea-prep.blob", + "useSnapshot": true +} diff --git a/test/fixtures/sea/snapshot/snapshot.js b/test/fixtures/sea/snapshot/snapshot.js new file mode 100644 index 00000000000..39b51a0324f --- /dev/null +++ b/test/fixtures/sea/snapshot/snapshot.js @@ -0,0 +1,7 @@ +const { + setDeserializeMainFunction, +} = require('v8').startupSnapshot; + +setDeserializeMainFunction(() => { + console.log('Hello from snapshot'); +}); diff --git a/test/fixtures/sea/use-code-cache/requirable.js b/test/fixtures/sea/use-code-cache/requirable.js new file mode 100644 index 00000000000..69f1fd8c377 --- /dev/null +++ b/test/fixtures/sea/use-code-cache/requirable.js @@ -0,0 +1,3 @@ +module.exports = { + hello: 'world', +}; diff --git a/test/fixtures/sea/use-code-cache/sea-config.json b/test/fixtures/sea/use-code-cache/sea-config.json new file mode 100644 index 00000000000..a69bd831f91 --- /dev/null +++ b/test/fixtures/sea/use-code-cache/sea-config.json @@ -0,0 +1,5 @@ +{ + "main": "sea.js", + "output": "sea-prep.blob", + "useCodeCache": true +} diff --git a/test/fixtures/sea/use-code-cache/sea.js b/test/fixtures/sea/use-code-cache/sea.js new file mode 100644 index 00000000000..65bb8d37e01 --- /dev/null +++ b/test/fixtures/sea/use-code-cache/sea.js @@ -0,0 +1,64 @@ +const { Module: { createRequire } } = require('module'); +const createdRequire = createRequire(__filename); + +// Although, require('../common') works locally, that couldn't be used here +// because we set NODE_TEST_DIR=/Users/iojs/node-tmp on Jenkins CI. +const { expectWarning, mustNotCall } = createdRequire(process.env.COMMON_DIRECTORY); + +const builtinWarning = +`Currently the require() provided to the main script embedded into single-executable applications only supports loading built-in modules. +To load a module from disk after the single executable application is launched, use require("module").createRequire(). +Support for bundled module loading or virtual file systems are under discussions in https://github.com/nodejs/single-executable`; + +// This additionally makes sure that no unexpected warnings are emitted. +if (!createdRequire('./sea-config.json').disableExperimentalSEAWarning) { + expectWarning('Warning', builtinWarning); // Triggered by require() calls below. + expectWarning('ExperimentalWarning', + 'Single executable application is an experimental feature and ' + + 'might change at any time'); + // Any unexpected warning would throw this error: + // https://github.com/nodejs/node/blob/c301404105a7256b79a0b8c4522ce47af96dfa17/test/common/index.js#L697-L700. +} + +// Should be possible to require core modules that optionally require the +// "node:" scheme. +const { deepStrictEqual, strictEqual, throws } = require('assert'); +const { dirname } = require('node:path'); + +// Checks that the source filename is used in the error stack trace. +strictEqual(new Error('lol').stack.split('\n')[1], ' at sea.js:29:13'); + +// Should be possible to require a core module that requires using the "node:" +// scheme. +{ + const { test } = require('node:test'); + strictEqual(typeof test, 'function'); +} + +// Should not be possible to require a core module without the "node:" scheme if +// it requires using the "node:" scheme. +throws(() => require('test'), { + code: 'ERR_UNKNOWN_BUILTIN_MODULE', +}); + +deepStrictEqual(process.argv, [process.execPath, process.execPath, '-a', '--b=c', 'd']); + +strictEqual(require.cache, undefined); +strictEqual(require.extensions, undefined); +strictEqual(require.main, module); +strictEqual(require.resolve, undefined); + +strictEqual(__filename, process.execPath); +strictEqual(__dirname, dirname(process.execPath)); +strictEqual(module.exports, exports); + +throws(() => require('./requirable.js'), { + code: 'ERR_UNKNOWN_BUILTIN_MODULE', +}); + +const requirable = createdRequire('./requirable.js'); +deepStrictEqual(requirable, { + hello: 'world', +}); + +console.log('Hello, world! 😊'); diff --git a/test/node-api/test_sea_addon/test.js b/test/node-api/test_sea_addon/test.js index 386ece80955..ef5fa118a0a 100644 --- a/test/node-api/test_sea_addon/test.js +++ b/test/node-api/test_sea_addon/test.js @@ -6,57 +6,30 @@ const { generateSEA, skipIfSingleExecutableIsNotSupported } = require('../../com skipIfSingleExecutableIsNotSupported(); -const assert = require('assert'); - const tmpdir = require('../../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync, rmSync } = require('fs'); +const { copyFileSync, rmSync, cpSync } = require('fs'); const { - spawnSyncAndExitWithoutError, spawnSyncAndAssert, } = require('../../common/child_process'); const { join } = require('path'); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); -tmpdir.refresh(); +const fixtures = require('../../common/fixtures'); -// Copy test fixture to working directory const addonPath = join(__dirname, 'build', common.buildType, 'binding.node'); const copiedAddonPath = tmpdir.resolve('binding.node'); + +tmpdir.refresh(); + +// Copy fixture files to working directory. +const fixtureDir = fixtures.path('sea', 'addon'); +cpSync(fixtureDir, tmpdir.path, { recursive: true }); + +// Copy the built addon to working directory. copyFileSync(addonPath, copiedAddonPath); -writeFileSync(tmpdir.resolve('sea.js'), ` -const sea = require('node:sea'); -const fs = require('fs'); -const path = require('path'); -const addonPath = path.join(${JSON.stringify(tmpdir.path)}, 'hello.node'); -fs.writeFileSync(addonPath, new Uint8Array(sea.getRawAsset('hello.node'))); -const mod = {exports: {}} -process.dlopen(mod, addonPath); -console.log('hello,', mod.exports.hello()); -`, 'utf-8'); +// Generate the SEA using the working directory directly (skip copy). +const outputFile = generateSEA(tmpdir.path, tmpdir.path); -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "disableExperimentalSEAWarning": true, - "assets": { - "hello.node": "binding.node" - } -} -`, 'utf8'); - -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }, -); -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); - -// Remove the copied addon after it's been packaged into the SEA blob +// Remove the copied addon after it's been packaged into the SEA blob. rmSync(copiedAddonPath, { force: true }); spawnSyncAndAssert( diff --git a/test/sea/test-single-executable-application-asset-keys-empty.js b/test/sea/test-single-executable-application-asset-keys-empty.js index 9168f2b2723..5d7a2df48ba 100644 --- a/test/sea/test-single-executable-application-asset-keys-empty.js +++ b/test/sea/test-single-executable-application-asset-keys-empty.js @@ -14,42 +14,14 @@ skipIfSingleExecutableIsNotSupported(); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); const { - spawnSyncAndExitWithoutError, spawnSyncAndAssert, } = require('../common/child_process'); -const assert = require('assert'); const fixtures = require('../common/fixtures'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); - tmpdir.refresh(); -copyFileSync(fixtures.path('sea', 'get-asset-keys.js'), tmpdir.resolve('sea.js')); -writeFileSync(tmpdir.resolve('sea-config.json'), ` -{ - "main": "sea.js", - "output": "sea-prep.blob" -} -`, 'utf8'); - -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - env: { - NODE_DEBUG_NATIVE: 'SEA', - ...process.env, - }, - cwd: tmpdir.path, - }, - {}); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'asset-keys-empty')); spawnSyncAndAssert( outputFile, diff --git a/test/sea/test-single-executable-application-asset-keys.js b/test/sea/test-single-executable-application-asset-keys.js index a2d1dce487e..ce30b7ff252 100644 --- a/test/sea/test-single-executable-application-asset-keys.js +++ b/test/sea/test-single-executable-application-asset-keys.js @@ -14,51 +14,14 @@ skipIfSingleExecutableIsNotSupported(); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); const { - spawnSyncAndExitWithoutError, spawnSyncAndAssert, } = require('../common/child_process'); -const assert = require('assert'); const fixtures = require('../common/fixtures'); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); - tmpdir.refresh(); -copyFileSync(fixtures.path('sea', 'get-asset-keys.js'), tmpdir.resolve('sea.js')); -writeFileSync(tmpdir.resolve('asset-1.txt'), 'This is asset 1'); -writeFileSync(tmpdir.resolve('asset-2.txt'), 'This is asset 2'); -writeFileSync(tmpdir.resolve('asset-3.txt'), 'This is asset 3'); -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "assets": { - "asset-1.txt": "asset-1.txt", - "asset-2.txt": "asset-2.txt", - "asset-3.txt": "asset-3.txt" - } -} -`, 'utf8'); - -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - env: { - NODE_DEBUG_NATIVE: 'SEA', - ...process.env, - }, - cwd: tmpdir.path, - }, - {}); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'asset-keys')); spawnSyncAndAssert( outputFile, diff --git a/test/sea/test-single-executable-application-assets-invalid-type.js b/test/sea/test-single-executable-application-assets-invalid-type.js new file mode 100644 index 00000000000..927acd8ac64 --- /dev/null +++ b/test/sea/test-single-executable-application-assets-invalid-type.js @@ -0,0 +1,35 @@ +'use strict'; + +// Test that invalid "assets" field (not a map) is rejected. + +require('../common'); +const { + spawnSyncAndExit, +} = require('../common/child_process'); +const fixtures = require('../common/fixtures'); +const tmpdir = require('../common/tmpdir'); +const { copyFileSync } = require('fs'); + +tmpdir.refresh(); + +// Copy the fixture files to tmpdir +copyFileSync( + fixtures.path('sea', 'assets-invalid-type', 'sea-config.json'), + tmpdir.resolve('sea-config.json'), +); +copyFileSync( + fixtures.path('sea', 'assets-invalid-type', 'sea.js'), + tmpdir.resolve('sea.js'), +); + +spawnSyncAndExit( + process.execPath, + ['--experimental-sea-config', 'sea-config.json'], + { + cwd: tmpdir.path, + }, + { + status: 1, + signal: null, + stderr: /"assets" field of .*sea-config\.json is not a map of strings/, + }); diff --git a/test/sea/test-single-executable-application-assets-nonexistent-file.js b/test/sea/test-single-executable-application-assets-nonexistent-file.js new file mode 100644 index 00000000000..260eb798fb8 --- /dev/null +++ b/test/sea/test-single-executable-application-assets-nonexistent-file.js @@ -0,0 +1,35 @@ +'use strict'; + +// Test that nonexistent asset file is rejected. + +const common = require('../common'); // eslint-disable-line no-unused-vars +const { + spawnSyncAndExit, +} = require('../common/child_process'); +const fixtures = require('../common/fixtures'); +const tmpdir = require('../common/tmpdir'); +const { copyFileSync } = require('fs'); + +tmpdir.refresh(); + +// Copy the fixture files to tmpdir +copyFileSync( + fixtures.path('sea', 'assets-nonexistent-file', 'sea-config.json'), + tmpdir.resolve('sea-config.json'), +); +copyFileSync( + fixtures.path('sea', 'assets-nonexistent-file', 'sea.js'), + tmpdir.resolve('sea.js'), +); + +spawnSyncAndExit( + process.execPath, + ['--experimental-sea-config', 'sea-config.json'], + { + cwd: tmpdir.path, + }, + { + status: 1, + signal: null, + stderr: /Cannot read asset nonexistent\.txt: no such file or directory/, + }); diff --git a/test/sea/test-single-executable-application-assets-raw.js b/test/sea/test-single-executable-application-assets-raw.js index ff0fb3ecacd..76a73745098 100644 --- a/test/sea/test-single-executable-application-assets-raw.js +++ b/test/sea/test-single-executable-application-assets-raw.js @@ -1,7 +1,6 @@ 'use strict'; -const common = require('../common'); - +require('../common'); const { generateSEA, skipIfSingleExecutableIsNotSupported, @@ -12,59 +11,21 @@ skipIfSingleExecutableIsNotSupported(); // This tests the snapshot support in single executable applications. const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); const { spawnSyncAndExitWithoutError, } = require('../common/child_process'); -const assert = require('assert'); const fixtures = require('../common/fixtures'); tmpdir.refresh(); -if (!tmpdir.hasEnoughSpace(120 * 1024 * 1024)) { - common.skip('Not enough disk space'); -} +const outputFile = generateSEA(fixtures.path('sea', 'assets-raw')); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); - -{ - tmpdir.refresh(); - copyFileSync(fixtures.path('sea', 'get-asset-raw.js'), tmpdir.resolve('sea.js')); - copyFileSync(fixtures.path('person.jpg'), tmpdir.resolve('person.jpg')); - writeFileSync(configFile, ` +spawnSyncAndExitWithoutError( + outputFile, { - "main": "sea.js", - "output": "sea-prep.blob", - "assets": { - "person.jpg": "person.jpg" - } - } - `, 'utf8'); - - spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - env: { - NODE_DEBUG_NATIVE: 'SEA', - ...process.env, - }, - cwd: tmpdir.path, - }); - - assert(existsSync(seaPrepBlob)); - - generateSEA(outputFile, process.execPath, seaPrepBlob); - - spawnSyncAndExitWithoutError( - outputFile, - { - env: { - ...process.env, - NODE_DEBUG_NATIVE: 'SEA', - __TEST_PERSON_JPG: fixtures.path('person.jpg'), - }, + env: { + ...process.env, + NODE_DEBUG_NATIVE: 'SEA', + __TEST_PERSON_JPG: fixtures.path('person.jpg'), }, - ); -} + }, +); diff --git a/test/sea/test-single-executable-application-assets.js b/test/sea/test-single-executable-application-assets.js index dd285021cd7..db1492be015 100644 --- a/test/sea/test-single-executable-application-assets.js +++ b/test/sea/test-single-executable-application-assets.js @@ -1,7 +1,8 @@ 'use strict'; -const common = require('../common'); +// This tests the assets support in single executable applications. +require('../common'); const { generateSEA, skipIfSingleExecutableIsNotSupported, @@ -9,121 +10,27 @@ const { skipIfSingleExecutableIsNotSupported(); -// This tests the snapshot support in single executable applications. const tmpdir = require('../common/tmpdir'); - -const { copyFileSync, writeFileSync, existsSync } = require('fs'); const { spawnSyncAndAssert, - spawnSyncAndExit, - spawnSyncAndExitWithoutError, } = require('../common/child_process'); -const assert = require('assert'); const fixtures = require('../common/fixtures'); tmpdir.refresh(); -if (!tmpdir.hasEnoughSpace(120 * 1024 * 1024)) { - common.skip('Not enough disk space'); -} +const outputFile = generateSEA(fixtures.path('sea', 'assets')); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); - -{ - tmpdir.refresh(); - copyFileSync(fixtures.path('sea', 'get-asset.js'), tmpdir.resolve('sea.js')); - writeFileSync(configFile, ` +spawnSyncAndAssert( + outputFile, { - "main": "sea.js", - "output": "sea-prep.blob", - "assets": "invalid" - } - `); - - spawnSyncAndExit( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - cwd: tmpdir.path, + env: { + ...process.env, + NODE_DEBUG_NATIVE: 'SEA', + __TEST_PERSON_JPG: fixtures.path('person.jpg'), + __TEST_UTF8_TEXT_PATH: fixtures.path('utf8_test_text.txt'), }, - { - status: 1, - signal: null, - stderr: /"assets" field of sea-config\.json is not a map of strings/, - }); -} - -{ - tmpdir.refresh(); - copyFileSync(fixtures.path('sea', 'get-asset.js'), tmpdir.resolve('sea.js')); - writeFileSync(configFile, ` + }, { - "main": "sea.js", - "output": "sea-prep.blob", - "assets": { - "nonexistent": "nonexistent.txt" - } - } - `); - - spawnSyncAndExit( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - cwd: tmpdir.path, - }, - { - status: 1, - signal: null, - stderr: /Cannot read asset nonexistent\.txt: no such file or directory/, - }); -} - -{ - tmpdir.refresh(); - copyFileSync(fixtures.path('sea', 'get-asset.js'), tmpdir.resolve('sea.js')); - copyFileSync(fixtures.utf8TestTextPath, tmpdir.resolve('utf8_test_text.txt')); - copyFileSync(fixtures.path('person.jpg'), tmpdir.resolve('person.jpg')); - writeFileSync(configFile, ` - { - "main": "sea.js", - "output": "sea-prep.blob", - "assets": { - "utf8_test_text.txt": "utf8_test_text.txt", - "person.jpg": "person.jpg" - } - } - `, 'utf8'); - - spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - env: { - NODE_DEBUG_NATIVE: 'SEA', - ...process.env, - }, - cwd: tmpdir.path, - }); - - assert(existsSync(seaPrepBlob)); - - generateSEA(outputFile, process.execPath, seaPrepBlob); - - spawnSyncAndAssert( - outputFile, - { - env: { - ...process.env, - NODE_DEBUG_NATIVE: 'SEA', - __TEST_PERSON_JPG: fixtures.path('person.jpg'), - __TEST_UTF8_TEXT_PATH: fixtures.path('utf8_test_text.txt'), - }, - }, - { - trim: true, - stdout: fixtures.utf8TestText, - }, - ); -} + trim: true, + stdout: fixtures.utf8TestText, + }, +); diff --git a/test/sea/test-single-executable-application-disable-experimental-sea-warning.js b/test/sea/test-single-executable-application-disable-experimental-sea-warning.js index b85a2f2e09f..d0cfe934d30 100644 --- a/test/sea/test-single-executable-application-disable-experimental-sea-warning.js +++ b/test/sea/test-single-executable-application-disable-experimental-sea-warning.js @@ -12,45 +12,14 @@ skipIfSingleExecutableIsNotSupported(); // This tests the creation of a single executable application which has the // experimental SEA warning disabled. -const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process'); +const { spawnSyncAndAssert } = require('../common/child_process'); const { join } = require('path'); -const assert = require('assert'); - -const inputFile = fixtures.path('sea.js'); -const requirableFile = tmpdir.resolve('requirable.js'); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); +const fixtures = require('../common/fixtures'); tmpdir.refresh(); -writeFileSync(requirableFile, ` -module.exports = { - hello: 'world', -}; -`); - -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "disableExperimentalSEAWarning": true -} -`); - -// Copy input to working directory -copyFileSync(inputFile, tmpdir.resolve('sea.js')); -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'disable-experimental-warning')); spawnSyncAndAssert( outputFile, diff --git a/test/sea/test-single-executable-application-empty.js b/test/sea/test-single-executable-application-empty.js index 6bffc94dbef..0f31dab4a35 100644 --- a/test/sea/test-single-executable-application-empty.js +++ b/test/sea/test-single-executable-application-empty.js @@ -13,34 +13,16 @@ skipIfSingleExecutableIsNotSupported(); // script. const tmpdir = require('../common/tmpdir'); -const { writeFileSync, existsSync } = require('fs'); +const fixtures = require('../common/fixtures'); const { spawnSyncAndExitWithoutError } = require('../common/child_process'); -const assert = require('assert'); - -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); tmpdir.refresh(); -writeFileSync(tmpdir.resolve('empty.js'), '', 'utf-8'); -writeFileSync(configFile, ` -{ - "main": "empty.js", - "output": "sea-prep.blob" -} -`); - -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }); - -assert(existsSync(seaPrepBlob)); - -// Verify the workflow. +let outputFile; try { - generateSEA(outputFile, process.execPath, seaPrepBlob, true); + outputFile = generateSEA(fixtures.path('sea', 'empty'), { + verifyWorkflow: true, + }); } catch (e) { if (/Cannot copy/.test(e.message)) { common.skip(e.message); diff --git a/test/sea/test-single-executable-application-exec-argv-empty.js b/test/sea/test-single-executable-application-exec-argv-empty.js index acae5e8eb50..e02f8ee6c89 100644 --- a/test/sea/test-single-executable-application-exec-argv-empty.js +++ b/test/sea/test-single-executable-application-exec-argv-empty.js @@ -11,39 +11,14 @@ skipIfSingleExecutableIsNotSupported(); // This tests the execArgv functionality with empty array in single executable applications. -const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process'); +const { spawnSyncAndAssert } = require('../common/child_process'); const { join } = require('path'); -const assert = require('assert'); - -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); +const fixtures = require('../common/fixtures'); tmpdir.refresh(); -// Copy test fixture to working directory -copyFileSync(fixtures.path('sea-exec-argv-empty.js'), tmpdir.resolve('sea.js')); - -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "disableExperimentalSEAWarning": true, - "execArgv": [] -} -`); - -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'exec-argv-empty')); // Test that empty execArgv work correctly spawnSyncAndAssert( diff --git a/test/sea/test-single-executable-application-exec-argv-extension-cli.js b/test/sea/test-single-executable-application-exec-argv-extension-cli.js index fcd8602fc76..738a2bc98b6 100644 --- a/test/sea/test-single-executable-application-exec-argv-extension-cli.js +++ b/test/sea/test-single-executable-application-exec-argv-extension-cli.js @@ -11,40 +11,14 @@ skipIfSingleExecutableIsNotSupported(); // This tests the execArgvExtension "cli" mode in single executable applications. -const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process'); +const { spawnSyncAndAssert } = require('../common/child_process'); const { join } = require('path'); -const assert = require('assert'); - -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); +const fixtures = require('../common/fixtures'); tmpdir.refresh(); -// Copy test fixture to working directory -copyFileSync(fixtures.path('sea-exec-argv-extension-cli.js'), tmpdir.resolve('sea.js')); - -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "disableExperimentalSEAWarning": true, - "execArgv": ["--no-warnings"], - "execArgvExtension": "cli" -} -`); - -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'exec-argv-extension-cli')); // Test that --node-options works with execArgvExtension: "cli" spawnSyncAndAssert( diff --git a/test/sea/test-single-executable-application-exec-argv-extension-env.js b/test/sea/test-single-executable-application-exec-argv-extension-env.js index 1bacba1fb0a..6d01c50d5c0 100644 --- a/test/sea/test-single-executable-application-exec-argv-extension-env.js +++ b/test/sea/test-single-executable-application-exec-argv-extension-env.js @@ -11,40 +11,15 @@ skipIfSingleExecutableIsNotSupported(); // This tests the execArgvExtension "env" mode (default) in single executable applications. -const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process'); +const { spawnSyncAndAssert } = require('../common/child_process'); const { join } = require('path'); const assert = require('assert'); - -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); +const fixtures = require('../common/fixtures'); tmpdir.refresh(); -// Copy test fixture to working directory -copyFileSync(fixtures.path('sea-exec-argv-extension-env.js'), tmpdir.resolve('sea.js')); - -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "disableExperimentalSEAWarning": true, - "execArgv": ["--no-warnings"], - "execArgvExtension": "env" -} -`); - -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'exec-argv-extension-env')); // Test that NODE_OPTIONS works with execArgvExtension: "env" (default behavior) spawnSyncAndAssert( diff --git a/test/sea/test-single-executable-application-exec-argv-extension-none.js b/test/sea/test-single-executable-application-exec-argv-extension-none.js index c4036bc5033..1b96e3ac8d7 100644 --- a/test/sea/test-single-executable-application-exec-argv-extension-none.js +++ b/test/sea/test-single-executable-application-exec-argv-extension-none.js @@ -11,40 +11,14 @@ skipIfSingleExecutableIsNotSupported(); // This tests the execArgvExtension "none" mode in single executable applications. -const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process'); +const { spawnSyncAndAssert } = require('../common/child_process'); const { join } = require('path'); -const assert = require('assert'); - -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); +const fixtures = require('../common/fixtures'); tmpdir.refresh(); -// Copy test fixture to working directory -copyFileSync(fixtures.path('sea-exec-argv-extension-none.js'), tmpdir.resolve('sea.js')); - -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "disableExperimentalSEAWarning": true, - "execArgv": ["--no-warnings"], - "execArgvExtension": "none" -} -`); - -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'exec-argv-extension-none')); // Test that NODE_OPTIONS is ignored with execArgvExtension: "none" spawnSyncAndAssert( diff --git a/test/sea/test-single-executable-application-exec-argv.js b/test/sea/test-single-executable-application-exec-argv.js index a60dbe1cab5..0d90a033633 100644 --- a/test/sea/test-single-executable-application-exec-argv.js +++ b/test/sea/test-single-executable-application-exec-argv.js @@ -11,39 +11,15 @@ skipIfSingleExecutableIsNotSupported(); // This tests the execArgv functionality with multiple arguments in single executable applications. -const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process'); +const { spawnSyncAndAssert } = require('../common/child_process'); const { join } = require('path'); +const fixtures = require('../common/fixtures'); const assert = require('assert'); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); - tmpdir.refresh(); -// Copy test fixture to working directory -copyFileSync(fixtures.path('sea-exec-argv.js'), tmpdir.resolve('sea.js')); - -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "disableExperimentalSEAWarning": true, - "execArgv": ["--no-warnings", "--max-old-space-size=2048"] -} -`); - -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'exec-argv')); // Test that multiple execArgv are properly applied spawnSyncAndAssert( diff --git a/test/sea/test-single-executable-application-inspect-in-sea-flags.js b/test/sea/test-single-executable-application-inspect-in-sea-flags.js index 66faed4812d..37cc969f9b2 100644 --- a/test/sea/test-single-executable-application-inspect-in-sea-flags.js +++ b/test/sea/test-single-executable-application-inspect-in-sea-flags.js @@ -6,10 +6,9 @@ require('../common'); const assert = require('assert'); -const { writeFileSync, existsSync } = require('fs'); const { spawnSyncAndAssert } = require('../common/child_process'); const tmpdir = require('../common/tmpdir'); -const { spawnSyncAndExitWithoutError } = require('../common/child_process'); +const fixtures = require('../common/fixtures'); const { generateSEA, @@ -18,33 +17,9 @@ const { skipIfSingleExecutableIsNotSupported(); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); - tmpdir.refresh(); -writeFileSync(tmpdir.resolve('sea.js'), `console.log(process.argv);`, 'utf-8'); - -// Create SEA configuration -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob" -} -`); - -// Generate the SEA prep blob -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }, -); - -assert(existsSync(seaPrepBlob)); - -// Generate the SEA executable -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'inspect-in-sea-flags')); // Spawn the SEA with inspect option spawnSyncAndAssert( diff --git a/test/sea/test-single-executable-application-inspect.js b/test/sea/test-single-executable-application-inspect.js index 5422159fbf3..d76d87c3e51 100644 --- a/test/sea/test-single-executable-application-inspect.js +++ b/test/sea/test-single-executable-application-inspect.js @@ -5,10 +5,9 @@ const common = require('../common'); const assert = require('assert'); -const { writeFileSync, existsSync } = require('fs'); const { spawn } = require('child_process'); const tmpdir = require('../common/tmpdir'); -const { spawnSyncAndExitWithoutError } = require('../common/child_process'); +const fixtures = require('../common/fixtures'); const { generateSEA, @@ -18,34 +17,9 @@ const { skipIfSingleExecutableIsNotSupported(); common.skipIfInspectorDisabled(); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); - tmpdir.refresh(); -// Create a simple hello world script -writeFileSync(tmpdir.resolve('hello.js'), `console.log('Hello, world!');`, 'utf-8'); - -// Create SEA configuration -writeFileSync(configFile, ` -{ - "main": "hello.js", - "output": "sea-prep.blob" -} -`); - -// Generate the SEA prep blob -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }, -); - -assert(existsSync(seaPrepBlob)); - -// Generate the SEA executable -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'inspect')); // Spawn the SEA with inspect option const seaProcess = spawn(outputFile, [], { diff --git a/test/sea/test-single-executable-application-snapshot-and-code-cache.js b/test/sea/test-single-executable-application-snapshot-and-code-cache.js index 24e10a1c12d..2ce4c2301eb 100644 --- a/test/sea/test-single-executable-application-snapshot-and-code-cache.js +++ b/test/sea/test-single-executable-application-snapshot-and-code-cache.js @@ -12,57 +12,15 @@ skipIfSingleExecutableIsNotSupported(); // This tests "useCodeCache" is ignored when "useSnapshot" is true. const tmpdir = require('../common/tmpdir'); -const { writeFileSync, existsSync } = require('fs'); const { spawnSyncAndAssert, } = require('../common/child_process'); -const { join } = require('path'); -const assert = require('assert'); - -const configFile = join(tmpdir.path, 'sea-config.json'); -const seaPrepBlob = join(tmpdir.path, 'sea-prep.blob'); -const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' : 'sea'); +const fixtures = require('../common/fixtures'); { tmpdir.refresh(); - const code = ` - const { - setDeserializeMainFunction, - } = require('v8').startupSnapshot; - setDeserializeMainFunction(() => { - console.log('Hello from snapshot'); - }); - `; - - writeFileSync(join(tmpdir.path, 'snapshot.js'), code, 'utf-8'); - writeFileSync(configFile, ` - { - "main": "snapshot.js", - "output": "sea-prep.blob", - "useSnapshot": true, - "useCodeCache": true - } - `); - - spawnSyncAndAssert( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - cwd: tmpdir.path, - env: { - NODE_DEBUG_NATIVE: 'SEA', - ...process.env, - }, - }, - { - stderr: /"useCodeCache" is redundant when "useSnapshot" is true/, - }, - ); - - assert(existsSync(seaPrepBlob)); - - generateSEA(outputFile, process.execPath, seaPrepBlob); + const outputFile = generateSEA(fixtures.path('sea', 'snapshot-and-code-cache')); spawnSyncAndAssert( outputFile, diff --git a/test/sea/test-single-executable-application-snapshot-worker.js b/test/sea/test-single-executable-application-snapshot-worker.js index 75ae6a27098..42242abf3a7 100644 --- a/test/sea/test-single-executable-application-snapshot-worker.js +++ b/test/sea/test-single-executable-application-snapshot-worker.js @@ -12,57 +12,15 @@ skipIfSingleExecutableIsNotSupported(); // This tests the snapshot support in single executable applications. const tmpdir = require('../common/tmpdir'); -const { writeFileSync, existsSync } = require('fs'); const { - spawnSyncAndAssert, spawnSyncAndExitWithoutError, + spawnSyncAndAssert, } = require('../common/child_process'); -const assert = require('assert'); - -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); +const fixtures = require('../common/fixtures'); { tmpdir.refresh(); - // FIXME(joyeecheung): currently `worker_threads` cannot be loaded during the - // snapshot building process because internal/worker.js is accessing isMainThread at - // the top level (and there are maybe more code that access these at the top-level), - // and have to be loaded in the deserialized snapshot main function. - // Change these states to be accessed on-demand. - const code = ` - const { - setDeserializeMainFunction, - } = require('v8').startupSnapshot; - setDeserializeMainFunction(() => { - const { Worker } = require('worker_threads'); - new Worker("console.log('Hello from Worker')", { eval: true }); - }); - `; - - writeFileSync(tmpdir.resolve('snapshot.js'), code, 'utf-8'); - writeFileSync(configFile, ` - { - "main": "snapshot.js", - "output": "sea-prep.blob", - "useSnapshot": true - } - `); - - spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - cwd: tmpdir.path, - env: { - NODE_DEBUG_NATIVE: 'SEA', - ...process.env, - }, - }); - - assert(existsSync(seaPrepBlob)); - - generateSEA(outputFile, process.execPath, seaPrepBlob); + const outputFile = generateSEA(fixtures.path('sea', 'snapshot-worker')); spawnSyncAndAssert( outputFile, diff --git a/test/sea/test-single-executable-application-snapshot.js b/test/sea/test-single-executable-application-snapshot.js index 15adcdb9b81..f6e52113860 100644 --- a/test/sea/test-single-executable-application-snapshot.js +++ b/test/sea/test-single-executable-application-snapshot.js @@ -12,22 +12,19 @@ skipIfSingleExecutableIsNotSupported(); // This tests the snapshot support in single executable applications. const tmpdir = require('../common/tmpdir'); -const { writeFileSync, existsSync } = require('fs'); +const { writeFileSync } = require('fs'); const { spawnSyncAndAssert, spawnSyncAndExit, } = require('../common/child_process'); +const fixtures = require('../common/fixtures'); const assert = require('assert'); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); - { tmpdir.refresh(); writeFileSync(tmpdir.resolve('snapshot.js'), '', 'utf-8'); - writeFileSync(configFile, ` + writeFileSync(tmpdir.resolve('sea-config.json'), ` { "main": "snapshot.js", "output": "sea-prep.blob", @@ -50,42 +47,8 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se { tmpdir.refresh(); - const code = ` - const { - setDeserializeMainFunction, - } = require('v8').startupSnapshot; - - setDeserializeMainFunction(() => { - console.log('Hello from snapshot'); - }); - `; - writeFileSync(tmpdir.resolve('snapshot.js'), code, 'utf-8'); - writeFileSync(configFile, ` - { - "main": "snapshot.js", - "output": "sea-prep.blob", - "useSnapshot": true - } - `); - - spawnSyncAndAssert( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - cwd: tmpdir.path, - env: { - NODE_DEBUG_NATIVE: 'SEA', - ...process.env, - }, - }, - { - stderr: /Single executable application is an experimental feature/, - }); - - assert(existsSync(seaPrepBlob)); - - generateSEA(outputFile, process.execPath, seaPrepBlob); + const outputFile = generateSEA(fixtures.path('sea', 'snapshot')); spawnSyncAndAssert( outputFile, diff --git a/test/sea/test-single-executable-application-use-code-cache.js b/test/sea/test-single-executable-application-use-code-cache.js index a66930f610e..fb857986a49 100644 --- a/test/sea/test-single-executable-application-use-code-cache.js +++ b/test/sea/test-single-executable-application-use-code-cache.js @@ -12,51 +12,14 @@ skipIfSingleExecutableIsNotSupported(); // This tests the creation of a single executable application which uses the // V8 code cache. -const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process'); +const { spawnSyncAndAssert } = require('../common/child_process'); const { join } = require('path'); -const assert = require('assert'); - -const inputFile = fixtures.path('sea.js'); -const requirableFile = tmpdir.resolve('requirable.js'); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); +const fixtures = require('../common/fixtures'); tmpdir.refresh(); -writeFileSync(requirableFile, ` -module.exports = { - hello: 'world', -}; -`); - -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "useCodeCache": true -} -`); - -// Copy input to working directory -copyFileSync(inputFile, tmpdir.resolve('sea.js')); -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { - cwd: tmpdir.path, - env: { - NODE_DEBUG_NATIVE: 'SEA', - ...process.env, - }, - }); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'use-code-cache')); spawnSyncAndAssert( outputFile, diff --git a/test/sea/test-single-executable-application.js b/test/sea/test-single-executable-application.js index 036589c1cb2..f9f92958921 100644 --- a/test/sea/test-single-executable-application.js +++ b/test/sea/test-single-executable-application.js @@ -11,45 +11,14 @@ skipIfSingleExecutableIsNotSupported(); // This tests the creation of a single executable application. -const fixtures = require('../common/fixtures'); const tmpdir = require('../common/tmpdir'); -const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSyncAndAssert, spawnSyncAndExitWithoutError } = require('../common/child_process'); +const { spawnSyncAndAssert } = require('../common/child_process'); const { join } = require('path'); -const assert = require('assert'); - -const inputFile = fixtures.path('sea.js'); -const requirableFile = tmpdir.resolve('requirable.js'); -const configFile = tmpdir.resolve('sea-config.json'); -const seaPrepBlob = tmpdir.resolve('sea-prep.blob'); -const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea'); +const fixtures = require('../common/fixtures'); tmpdir.refresh(); -writeFileSync(requirableFile, ` -module.exports = { - hello: 'world', -}; -`); - -writeFileSync(configFile, ` -{ - "main": "sea.js", - "output": "sea-prep.blob", - "disableExperimentalSEAWarning": false -} -`); - -// Copy input to working directory -copyFileSync(inputFile, tmpdir.resolve('sea.js')); -spawnSyncAndExitWithoutError( - process.execPath, - ['--experimental-sea-config', 'sea-config.json'], - { cwd: tmpdir.path }); - -assert(existsSync(seaPrepBlob)); - -generateSEA(outputFile, process.execPath, seaPrepBlob); +const outputFile = generateSEA(fixtures.path('sea', 'simple')); spawnSyncAndAssert( outputFile,