Skip to content

Commit 51f1ef8

Browse files
committed
Add test runner with eval disabled
- add test-noeval to test with eval disabled - use test for checking coverage (coverage runner does not support non-eval mode) - update CIs to run test-noeval as well for node versions which support it (>= 9)
1 parent 71460f2 commit 51f1ef8

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ before_install:
8888
script:
8989
# Run test script
9090
- |
91+
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -gt 8 ]]; then
92+
npm run test-noeval
93+
fi
9194
if npm -ps ls nyc | grep -q nyc; then
9295
npm run test-ci
9396
else

appveyor.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ test_script:
7676
- ps: |
7777
node --version
7878
npm --version
79+
# Run test script with eval disabled, if supported (node >= 9)
80+
- ps: |
81+
if ([int]$env:nodejs_version.split(".")[0] -gt 8) {
82+
npm run test-noeval
83+
}
7984
# Run test script
8085
- npm test
8186
version: "{build}"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"bench": "node benchmark/index.js",
3939
"lint": "eslint --plugin markdown --ext js,md .",
4040
"test": "mocha --reporter spec --bail test/",
41+
"test-noeval": "node --disallow-code-generation-from-strings node_modules/.bin/mocha --reporter spec --bail test/",
4142
"test-ci": "nyc --reporter=text npm test",
4243
"test-cov": "nyc --reporter=html --reporter=text npm test"
4344
}

test/test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@ describe('deprecate(message)', function () {
6565

6666
it('should log call site within eval', function () {
6767
function callold () { eval('mylib.old()') } // eslint-disable-line no-eval
68-
var stderr = captureStderr(callold)
68+
var stderr;
69+
try {
70+
stderr = captureStderr(callold)
71+
} catch (e) {
72+
if (!(e instanceof EvalError)) {
73+
throw e;
74+
}
75+
// unable to test eval stack trace because eval is blocked in this test environment
76+
this.skip();
77+
}
6978
assert.ok(stderr.indexOf(basename(__filename)) !== -1)
7079
assert.ok(stderr.indexOf('<anonymous>:1:') !== -1)
7180
assert.ok(/\.js:[0-9]+:[0-9]+/.test(stderr))

0 commit comments

Comments
 (0)