From cc5c3b557ee8f52dcbfa42984f38a80c55e6c3be Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 2 Dec 2019 11:47:10 -0800 Subject: [PATCH 1/2] test: simplify tmpdir import in wasi tests PR-URL: https://github.com/nodejs/node/pull/30770 Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Yongsheng Zhang Reviewed-By: Jiawen Geng Reviewed-By: Ruben Bridgewater Reviewed-By: Anna Henningsen --- test/wasi/test-wasi-symlinks.js | 2 +- test/wasi/test-wasi.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/wasi/test-wasi-symlinks.js b/test/wasi/test-wasi-symlinks.js index 3829464198273b..7c6e6809738975 100644 --- a/test/wasi/test-wasi-symlinks.js +++ b/test/wasi/test-wasi-symlinks.js @@ -33,7 +33,7 @@ if (process.argv[2] === 'wasi-child') { const assert = require('assert'); const cp = require('child_process'); - const tmpdir = require('../../test/common/tmpdir'); + const tmpdir = require('../common/tmpdir'); // Setup the sandbox environment. tmpdir.refresh(); diff --git a/test/wasi/test-wasi.js b/test/wasi/test-wasi.js index fa2e0894c906ce..d1060f5b32d33d 100644 --- a/test/wasi/test-wasi.js +++ b/test/wasi/test-wasi.js @@ -3,7 +3,7 @@ const common = require('../common'); if (process.argv[2] === 'wasi-child') { const fixtures = require('../common/fixtures'); - const tmpdir = require('../../test/common/tmpdir'); + const tmpdir = require('../common/tmpdir'); const fs = require('fs'); const path = require('path'); From bcd5491219bfd34630d331bdca3c92538a7b0e5e Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 2 Dec 2019 12:25:39 -0800 Subject: [PATCH 2/2] test: improve wasi test coverage Add test coverage for options validation in WASI constructor. PR-URL: https://github.com/nodejs/node/pull/30770 Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Yongsheng Zhang Reviewed-By: Jiawen Geng Reviewed-By: Ruben Bridgewater Reviewed-By: Anna Henningsen --- test/wasi/test-wasi-options-validation.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/wasi/test-wasi-options-validation.js diff --git a/test/wasi/test-wasi-options-validation.js b/test/wasi/test-wasi-options-validation.js new file mode 100644 index 00000000000000..34ab7e078f1210 --- /dev/null +++ b/test/wasi/test-wasi-options-validation.js @@ -0,0 +1,22 @@ +'use strict'; + +// Flags: --experimental-wasi-unstable-preview0 + +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' }); + +// If env is not an Object and not undefined, it should throw. +assert.throws(() => { new WASI({ env: 'fhqwhgads' }); }, + { code: 'ERR_INVALID_ARG_TYPE' }); + +// If preopens is not an Object and not undefined, it should throw. +assert.throws(() => { new WASI({ preopens: 'fhqwhgads' }); }, + { code: 'ERR_INVALID_ARG_TYPE' });