|
1 | 1 | import { zstdCompressSync } from 'node:zlib' |
2 | | -import { extractWindowsSmolRuntime } from '../../../scripts/repo/cli-build/sea/windows-runtime.mts' |
| 2 | +import { extractSmolRuntime } from '../../../scripts/repo/cli-build/sea/runtime.mts' |
3 | 3 | import { createHash } from 'node:crypto' |
4 | 4 | import { runInNewContext } from 'node:vm' |
5 | 5 | import { describe, expect, it } from 'vitest' |
@@ -91,30 +91,40 @@ describe('SEA package', () => { |
91 | 91 | }) |
92 | 92 | }) |
93 | 93 |
|
94 | | -describe('Windows node-smol runtime', () => { |
| 94 | +describe('node-smol runtime', () => { |
95 | 95 | it('extracts a verified PE payload', () => { |
96 | | - const fixture = createWindowsFixture() |
97 | | - expect(extractWindowsSmolRuntime(fixture)).toEqual( |
| 96 | + const fixture = createSmolFixture() |
| 97 | + expect(extractSmolRuntime(fixture, 'win32-arm64')).toEqual( |
98 | 98 | Buffer.from('MZ example node runtime'), |
99 | 99 | ) |
100 | 100 | }) |
| 101 | + it.each([ |
| 102 | + ['linux-x64', [0x7f, 0x45, 0x4c, 0x46]], |
| 103 | + ['darwin-arm64', [0xcf, 0xfa, 0xed, 0xfe]], |
| 104 | + ] as const)('extracts %s runtime', (target, magic) => { |
| 105 | + const runtime = Buffer.from(magic) |
| 106 | + expect(extractSmolRuntime(createSmolFixture(runtime), target)).toEqual( |
| 107 | + runtime, |
| 108 | + ) |
| 109 | + }) |
101 | 110 | it('rejects corrupted compressed bytes', () => { |
102 | | - const fixture = createWindowsFixture() |
| 111 | + const fixture = createSmolFixture() |
103 | 112 | fixture[fixture.length - 1] = fixture[fixture.length - 1]! ^ 1 |
104 | | - expect(() => extractWindowsSmolRuntime(fixture)).toThrow() |
| 113 | + expect(() => extractSmolRuntime(fixture, 'win32-arm64')).toThrow() |
105 | 114 | }) |
106 | 115 | it('rejects oversized declared output', () => { |
107 | | - const fixture = createWindowsFixture() |
| 116 | + const fixture = createSmolFixture() |
108 | 117 | fixture.writeBigUInt64LE(512n * 1024n * 1024n, 40) |
109 | | - expect(() => extractWindowsSmolRuntime(fixture)).toThrow() |
| 118 | + expect(() => extractSmolRuntime(fixture, 'win32-arm64')).toThrow() |
110 | 119 | }) |
111 | 120 | it('rejects truncated metadata', () => { |
112 | | - expect(() => extractWindowsSmolRuntime(Buffer.alloc(10))).toThrow() |
| 121 | + expect(() => extractSmolRuntime(Buffer.alloc(10), 'win32-arm64')).toThrow() |
113 | 122 | }) |
114 | 123 | }) |
115 | 124 |
|
116 | | -function createWindowsFixture(): Buffer { |
117 | | - const runtime = Buffer.from('MZ example node runtime') |
| 125 | +function createSmolFixture( |
| 126 | + runtime = Buffer.from('MZ example node runtime'), |
| 127 | +): Buffer { |
118 | 128 | const compressed = zstdCompressSync(runtime) |
119 | 129 | const header = Buffer.alloc(100) |
120 | 130 | header.write('__SMOL_PRESSED_DATA_MAGIC_MARKER') |
|
0 commit comments