diff options
author | Masashi Hirano <cherrydog07@gmail.com> | 2019-04-21 17:04:04 +0900 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-04-24 10:07:09 +0200 |
commit | fb3f6005c037f9af8f435edd0d1f407266af2916 (patch) | |
tree | e78d5c169e9b3a99e42bad259aaaa0d90a1d0cf5 /test/parallel/test-vm-codegen.js | |
parent | 9b982feedf76ac51fe4ed1aaf22026cbb0df1a5e (diff) | |
download | android-node-v8-fb3f6005c037f9af8f435edd0d1f407266af2916.tar.gz android-node-v8-fb3f6005c037f9af8f435edd0d1f407266af2916.tar.bz2 android-node-v8-fb3f6005c037f9af8f435edd0d1f407266af2916.zip |
test: fix ineffective error tests
Fix tests whether errors are thrown correctly
because they are successful when error doesn't get thrown.
PR-URL: https://github.com/nodejs/node/pull/27333
Fixes: https://github.com/nodejs/node/issues/26385
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/parallel/test-vm-codegen.js')
-rw-r--r-- | test/parallel/test-vm-codegen.js | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/test/parallel/test-vm-codegen.js b/test/parallel/test-vm-codegen.js index ebafe30c07..0136e143ab 100644 --- a/test/parallel/test-vm-codegen.js +++ b/test/parallel/test-vm-codegen.js @@ -8,19 +8,6 @@ const { createContext, runInContext, runInNewContext } = require('vm'); const WASM_BYTES = Buffer.from( [0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]); - -function expectsError(fn, type) { - try { - fn(); - assert.fail('expected fn to error'); - } catch (err) { - if (typeof type === 'string') - assert.strictEqual(err.name, type); - else - assert(err instanceof type); - } -} - { const ctx = createContext({ WASM_BYTES }); const test = 'eval(""); new WebAssembly.Module(WASM_BYTES);'; @@ -39,7 +26,7 @@ function expectsError(fn, type) { }); const EvalError = runInContext('EvalError', ctx); - expectsError(() => { + assert.throws(() => { runInContext('eval("x")', ctx); }, EvalError); } @@ -52,26 +39,30 @@ function expectsError(fn, type) { }); const CompileError = runInContext('WebAssembly.CompileError', ctx); - expectsError(() => { + assert.throws(() => { runInContext('new WebAssembly.Module(WASM_BYTES)', ctx); }, CompileError); } -expectsError(() => { +assert.throws(() => { runInNewContext('eval("x")', {}, { contextCodeGeneration: { strings: false, }, }); -}, 'EvalError'); +}, { + name: 'EvalError' +}); -expectsError(() => { +assert.throws(() => { runInNewContext('new WebAssembly.Module(WASM_BYTES)', { WASM_BYTES }, { contextCodeGeneration: { wasm: false, }, }); -}, 'CompileError'); +}, { + name: 'CompileError' +}); common.expectsError(() => { createContext({}, { |