Skip to content

Commit

Permalink
Merge branch 'test-no-eval' into no-eval
Browse files Browse the repository at this point in the history
Replace previous testing strategy with new simpler one
  • Loading branch information
davidje13 committed Mar 29, 2021
2 parents 71460f2 + 9ee652b commit 903c28b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 8 additions & 0 deletions test/fixtures/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

var deprecate = require('../..')('basic')

var object = { foo: 'bar' }
deprecate.property(object, 'foo')

function fn () {}
deprecate.function(fn)
29 changes: 26 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ var script = path.join(__dirname, 'fixtures', 'script.js')
var spawn = require('child_process').spawn
var strictlib = libs.strict

function isNodeVersionGE (required) {
var nodeVersion = process.version.substr(1).split('.')
for (var i = 0; i < required.length; i++) {
if (+nodeVersion[i] < required[i]) {
return false
}
}
return true
}

describe('depd(namespace)', function () {
it('creates deprecated function', function () {
assert.strictEqual(typeof depd('test'), 'function')
Expand Down Expand Up @@ -730,9 +740,9 @@ describe('node script.js', function () {
;(function () {
// --*-deprecation switches are 0.8+
// no good way to feature detect this sync
var describe = /^v0\.6\./.test(process.version)
? global.describe.skip
: global.describe
var describe = isNodeVersionGE([0, 8])
? global.describe
: global.describe.skip

describe('node --no-deprecation script.js', function () {
it('should suppress deprecation message', function (done) {
Expand All @@ -755,6 +765,19 @@ describe('node script.js', function () {
})
}())

describe('node --disallow-code-generation-from-strings script.js', function () {
it('should run without error', function (done) {
if (!isNodeVersionGE([9])) this.skip() // --disallow-code-generation-from-strings is 9+

var basic = path.join(__dirname, 'fixtures', 'basic.js')
captureChildStderr(basic, ['--disallow-code-generation-from-strings'], function (err, stderr) {
if (err) return done(err)
assert.strictEqual(stderr, '')
done()
})
})
})

function captureChildStderr (script, opts, callback) {
var chunks = []
var env = { PATH: process.env.PATH }
Expand Down

0 comments on commit 903c28b

Please sign in to comment.