-
Notifications
You must be signed in to change notification settings - Fork 30k
/
test-wasi-options-validation.js
33 lines (25 loc) · 1.26 KB
/
test-wasi-options-validation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
// Flags: --experimental-wasi-unstable-preview1
require('../common');
const assert = require('assert');
const { WASI } = require('wasi');
// If args is undefined, it should default to [] and should not throw.
new WASI({});
// If args is not an Array and not undefined, it should throw.
assert.throws(() => { new WASI({ args: 'fhqwhgads' }); },
{ code: 'ERR_INVALID_ARG_TYPE', message: /\bargs\b/ });
// If env is not an Object and not undefined, it should throw.
assert.throws(() => { new WASI({ env: 'fhqwhgads' }); },
{ code: 'ERR_INVALID_ARG_TYPE', message: /\benv\b/ });
// If preopens is not an Object and not undefined, it should throw.
assert.throws(() => { new WASI({ preopens: 'fhqwhgads' }); },
{ code: 'ERR_INVALID_ARG_TYPE', message: /\bpreopens\b/ });
// If options is provided, but not an object, the constructor should throw.
[null, 'foo', '', 0, NaN, Symbol(), true, false, () => {}].forEach((value) => {
assert.throws(() => { new WASI(value); },
{ code: 'ERR_INVALID_ARG_TYPE' });
});
// Verify that exceptions thrown from the binding layer are handled.
assert.throws(() => {
new WASI({ preopens: { '/sandbox': '__/not/real/path' } });
}, { code: 'UVWASI_ENOENT', message: /uvwasi_init/ });