Skip to content

Commit

Permalink
Add test runner with eval disabled
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
davidje13 committed Mar 28, 2021
1 parent 71460f2 commit 51f1ef8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ before_install:
script:
# Run test script
- |
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -gt 8 ]]; then
npm run test-noeval
fi
if npm -ps ls nyc | grep -q nyc; then
npm run test-ci
else
Expand Down
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ test_script:
- ps: |
node --version
npm --version
# Run test script with eval disabled, if supported (node >= 9)
- ps: |
if ([int]$env:nodejs_version.split(".")[0] -gt 8) {
npm run test-noeval
}
# Run test script
- npm test
version: "{build}"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"bench": "node benchmark/index.js",
"lint": "eslint --plugin markdown --ext js,md .",
"test": "mocha --reporter spec --bail test/",
"test-noeval": "node --disallow-code-generation-from-strings node_modules/.bin/mocha --reporter spec --bail test/",
"test-ci": "nyc --reporter=text npm test",
"test-cov": "nyc --reporter=html --reporter=text npm test"
}
Expand Down
11 changes: 10 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ describe('deprecate(message)', function () {

it('should log call site within eval', function () {
function callold () { eval('mylib.old()') } // eslint-disable-line no-eval
var stderr = captureStderr(callold)
var stderr;
try {
stderr = captureStderr(callold)
} catch (e) {
if (!(e instanceof EvalError)) {
throw e;
}
// unable to test eval stack trace because eval is blocked in this test environment
this.skip();
}
assert.ok(stderr.indexOf(basename(__filename)) !== -1)
assert.ok(stderr.indexOf('<anonymous>:1:') !== -1)
assert.ok(/\.js:[0-9]+:[0-9]+/.test(stderr))
Expand Down

0 comments on commit 51f1ef8

Please sign in to comment.