From 50fe4f0fad58ec3ddc0167a04e596261a3e9d496 Mon Sep 17 00:00:00 2001 From: maurice_hayward Date: Mon, 27 Feb 2017 16:37:05 -0500 Subject: [PATCH 1/3] test: changed test1 of test-vm-timeout.js so that entire error message would be matached in assert.throw --- test/parallel/test-vm-timeout.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-vm-timeout.js b/test/parallel/test-vm-timeout.js index 5260ca7dc28572..d3f229f7dc6e2a 100644 --- a/test/parallel/test-vm-timeout.js +++ b/test/parallel/test-vm-timeout.js @@ -6,7 +6,15 @@ const vm = require('vm'); // Test 1: Timeout of 100ms executing endless loop assert.throws(function() { vm.runInThisContext('while(true) {}', { timeout: 100 }); -}); +}, + function(err) { + if ( (err instanceof Error) && /^Script execution timed out\.$/.test(err.message) ) { + return true; + } + } + + +); // Test 2: Timeout must be >= 0ms assert.throws(function() { From 9fad978f267d3c0dd04fe1c9ca77e586b604b710 Mon Sep 17 00:00:00 2001 From: maurice_hayward Date: Mon, 27 Feb 2017 17:08:21 -0500 Subject: [PATCH 2/3] test: changed test1 of test-vm-timeout.js so that entire error message would be matched Before test 1 of test-vm-timeout.js would match any error, now it looks specifically for the error message "Script execution timed out." --- test/parallel/test-vm-timeout.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-vm-timeout.js b/test/parallel/test-vm-timeout.js index d3f229f7dc6e2a..c9e501a3d710a0 100644 --- a/test/parallel/test-vm-timeout.js +++ b/test/parallel/test-vm-timeout.js @@ -6,15 +6,10 @@ const vm = require('vm'); // Test 1: Timeout of 100ms executing endless loop assert.throws(function() { vm.runInThisContext('while(true) {}', { timeout: 100 }); -}, - function(err) { - if ( (err instanceof Error) && /^Script execution timed out\.$/.test(err.message) ) { - return true; - } - } - - -); +}, function(err) { + const re = /^Script execution timed out\.$/; + if ((err instanceof Error) && re.test(err.message)) { return true; } +}); // Test 2: Timeout must be >= 0ms assert.throws(function() { From 4412ae2e9968b90c00729331ebe8adca6c8bdcd4 Mon Sep 17 00:00:00 2001 From: maurice_hayward Date: Mon, 27 Feb 2017 17:34:32 -0500 Subject: [PATCH 3/3] made solution more succinct --- test/parallel/test-vm-timeout.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/parallel/test-vm-timeout.js b/test/parallel/test-vm-timeout.js index c9e501a3d710a0..6ed73f8b4ffd78 100644 --- a/test/parallel/test-vm-timeout.js +++ b/test/parallel/test-vm-timeout.js @@ -6,10 +6,7 @@ const vm = require('vm'); // Test 1: Timeout of 100ms executing endless loop assert.throws(function() { vm.runInThisContext('while(true) {}', { timeout: 100 }); -}, function(err) { - const re = /^Script execution timed out\.$/; - if ((err instanceof Error) && re.test(err.message)) { return true; } -}); +}, /^Error: Script execution timed out\.$/); // Test 2: Timeout must be >= 0ms assert.throws(function() {