node/test/fixtures/sea/assets-raw/sea.js
Joyee Cheung 20b62ff488
test: use fixture directories for sea tests
Instead of copying and writing files on the fly for SEA tests,
put the fixtures into a directory and copy them into tmpdir
for testing. This allows easier reproduction and debugging
when they do fail - we can just copy the entire fixture directory
and test directly from there.

PR-URL: https://github.com/nodejs/node/pull/61167
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2026-01-22 23:32:44 +01:00

31 lines
895 B
JavaScript

'use strict';
const { isSea, getAsset, getRawAsset } = require('node:sea');
const { readFileSync } = require('fs');
const assert = require('assert');
assert(isSea());
{
assert.throws(() => getRawAsset('nonexistent'), {
code: 'ERR_SINGLE_EXECUTABLE_APPLICATION_ASSET_NOT_FOUND'
});
assert.throws(() => getRawAsset(null), {
code: 'ERR_INVALID_ARG_TYPE'
});
assert.throws(() => getRawAsset(1), {
code: 'ERR_INVALID_ARG_TYPE'
});
}
{
// Check that the asset embedded is the same as the original.
const assetOnDisk = readFileSync(process.env.__TEST_PERSON_JPG);
const assetCopy = getAsset('person.jpg')
const assetCopyBuffer = Buffer.from(assetCopy);
assert.deepStrictEqual(assetCopyBuffer, assetOnDisk);
// Check that the copied asset is the same as the raw one.
const rawAsset = getRawAsset('person.jpg');
assert.deepStrictEqual(rawAsset, assetCopy);
}