[Pkg-javascript-commits] [node-depd] 02/03: Imported Upstream version 1.0.1

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sat May 16 23:14:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to branch master
in repository node-depd.

commit a32551a550a06d1450bd55a8bac887499ed243dc
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Sat May 16 23:11:48 2015 +0000

    Imported Upstream version 1.0.1
---
 .travis.yml                 |  11 +-
 History.md                  |   8 +
 Readme.md                   |  17 +-
 appveyor.yml                |  16 ++
 index.js                    |  13 +-
 package.json                |  13 +-
 test/fixtures/strict-lib.js |  51 ++++++
 test/test.js                | 400 +++++++++++++++++++++++++++++---------------
 8 files changed, 367 insertions(+), 162 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 9c3778a..31d82cf 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,10 +3,9 @@ node_js:
   - "0.6"
   - "0.8"
   - "0.10"
-  - "0.11"
-matrix:
-  allow_failures:
-    - node_js: "0.11"
-  fast_finish: true
-script: "npm run-script test-travis"
+  - "0.12"
+  - "1.0"
+  - "1.6"
+sudo: false
+script: "npm run-script test-ci"
 after_script: "npm install coveralls at 2.10.0 && cat ./coverage/lcov.info | coveralls"
diff --git a/History.md b/History.md
index bdbcf58..4a36a6c 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,11 @@
+1.0.1 / 2015-04-07
+==================
+
+  * Fix `TypeError`s when under `'use strict'` code
+  * Fix useless type name on auto-generated messages
+  * Support io.js 1.x
+  * Support Node.js 0.12
+
 1.0.0 / 2014-09-17
 ==================
 
diff --git a/Readme.md b/Readme.md
index 9fb2737..5ead5da 100644
--- a/Readme.md
+++ b/Readme.md
@@ -3,7 +3,8 @@
 [![NPM Version][npm-version-image]][npm-url]
 [![NPM Downloads][npm-downloads-image]][npm-url]
 [![Node.js Version][node-image]][node-url]
-[![Build Status][travis-image]][travis-url]
+[![Linux Build][travis-image]][travis-url]
+[![Windows Build][appveyor-image]][appveyor-url]
 [![Coverage Status][coveralls-image]][coveralls-url]
 [![Gratipay][gratipay-image]][gratipay-url]
 
@@ -258,14 +259,16 @@ deprecate.property(exports, 'oldprop', 'oldprop >= 0.10')
 
 [MIT](LICENSE)
 
-[npm-version-image]: https://img.shields.io/npm/v/depd.svg?style=flat
-[npm-downloads-image]: https://img.shields.io/npm/dm/depd.svg?style=flat
+[npm-version-image]: https://img.shields.io/npm/v/depd.svg
+[npm-downloads-image]: https://img.shields.io/npm/dm/depd.svg
 [npm-url]: https://npmjs.org/package/depd
-[travis-image]: https://img.shields.io/travis/dougwilson/nodejs-depd.svg?style=flat
+[travis-image]: https://img.shields.io/travis/dougwilson/nodejs-depd/master.svg?label=linux
 [travis-url]: https://travis-ci.org/dougwilson/nodejs-depd
-[coveralls-image]: https://img.shields.io/coveralls/dougwilson/nodejs-depd.svg?style=flat
+[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/nodejs-depd/master.svg?label=windows
+[appveyor-url]: https://ci.appveyor.com/project/dougwilson/nodejs-depd
+[coveralls-image]: https://img.shields.io/coveralls/dougwilson/nodejs-depd/master.svg
 [coveralls-url]: https://coveralls.io/r/dougwilson/nodejs-depd?branch=master
-[node-image]: https://img.shields.io/node/v/depd.svg?style=flat
+[node-image]: https://img.shields.io/node/v/depd.svg
 [node-url]: http://nodejs.org/download/
-[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
+[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg
 [gratipay-url]: https://www.gratipay.com/dougwilson/
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..ba20385
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,16 @@
+environment:
+  matrix:
+    - nodejs_version: "0.8"
+    - nodejs_version: "0.10"
+    - nodejs_version: "0.12"
+    - nodejs_version: "1.0"
+    - nodejs_version: "1.6"
+install:
+  - ps: Install-Product node $env:nodejs_version
+  - npm install
+build: off
+test_script:
+  - node --version
+  - npm --version
+  - npm run test-ci
+version: "{build}"
diff --git a/index.js b/index.js
index 4fee4d9..d183b0a 100644
--- a/index.js
+++ b/index.js
@@ -280,19 +280,26 @@ function callSiteLocation(callSite) {
 function defaultMessage(site) {
   var callSite = site.callSite
   var funcName = site.name
-  var typeName = callSite.getTypeName()
 
   // make useful anonymous name
   if (!funcName) {
     funcName = '<anonymous@' + formatLocation(site) + '>'
   }
 
+  var context = callSite.getThis()
+  var typeName = context && callSite.getTypeName()
+
+  // ignore useless type name
+  if (typeName === 'Object') {
+    typeName = undefined
+  }
+
   // make useful type name
   if (typeName === 'Function') {
-    typeName = callSite.getThis().name || typeName
+    typeName = context.name || typeName
   }
 
-  return callSite.getMethodName()
+  return typeName && callSite.getMethodName()
     ? typeName + '.' + funcName
     : funcName
 }
diff --git a/package.json b/package.json
index dd38015..9e9e402 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "depd",
   "description": "Deprecate all the things",
-  "version": "1.0.0",
+  "version": "1.0.1",
   "author": "Douglas Christopher Wilson <doug at somethingdoug.com>",
   "license": "MIT",
   "keywords": [
@@ -12,9 +12,8 @@
   "devDependencies": {
     "benchmark": "1.0.0",
     "beautify-benchmark": "0.2.4",
-    "istanbul": "0.3.2",
-    "mocha": "~1.21.4",
-    "should": "~4.0.4"
+    "istanbul": "0.3.5",
+    "mocha": "~1.21.5"
   },
   "files": [
     "lib/",
@@ -28,8 +27,8 @@
   },
   "scripts": {
     "bench": "node benchmark/index.js",
-    "test": "mocha --reporter spec --bail --require should test/",
-    "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should test/",
-    "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --require should test/"
+    "test": "mocha --reporter spec --bail test/",
+    "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --no-exit test/",
+    "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/"
   }
 }
diff --git a/test/fixtures/strict-lib.js b/test/fixtures/strict-lib.js
new file mode 100644
index 0000000..f4f0201
--- /dev/null
+++ b/test/fixtures/strict-lib.js
@@ -0,0 +1,51 @@
+
+'use strict'
+
+var deprecate = require('../..')('strict-lib')
+
+exports.old = function () {
+  deprecate('old')
+}
+
+exports.oldfn = deprecate.function(fn, 'oldfn')
+
+exports.oldfnauto = deprecate.function(fn)
+
+exports.oldfnautoanon = deprecate.function(function () {})
+
+exports.propa = 'thingie'
+exports.propauto = 'thingie'
+
+deprecate.property(exports, 'propa', 'propa gone')
+deprecate.property(exports, 'propauto')
+
+exports.automsg = function () {
+  deprecate()
+}
+
+exports.automsgnamed = function automsgnamed() {
+  deprecate()
+}
+
+exports.automsganon = function () {
+  (function () { deprecate() }())
+}
+
+exports.fnprop = function thefn() {}
+exports.fnprop.propa = 'thingie'
+exports.fnprop.propautomsg = 'thingie'
+
+deprecate.property(exports.fnprop, 'propa', 'fn propa gone')
+deprecate.property(exports.fnprop, 'propautomsg')
+
+exports.layerfn = function () {
+  exports.oldfn()
+}
+
+exports.layerprop = function () {
+  exports.propa
+}
+
+function fn(a1, a2) {
+  return a2
+}
diff --git a/test/test.js b/test/test.js
index 33e79d3..a484c55 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,44 +1,52 @@
 
+var assert = require('assert')
 var basename = require('path').basename
 var bufferConcat = require('../lib/compat').bufferConcat
 var depd = require('..')
 var mylib = require('./fixtures/my-lib')
 var path = require('path')
 var script = path.join(__dirname, 'fixtures', 'script.js')
-var should = require('should')
 var spawn = require('child_process').spawn
+var strictlib = require('./fixtures/strict-lib')
 
 describe('depd(namespace)', function () {
   it('creates deprecated function', function () {
-    depd('test').should.be.a.function
+    assert.equal(typeof depd('test'), 'function')
   })
 
   it('requires namespace', function () {
-    depd.bind().should.throw(/namespace.*required/)
+    assert.throws(depd.bind(null), /namespace.*required/)
   })
 })
 
 describe('deprecate(message)', function () {
   it('should log namespace', function () {
     function callold() { mylib.old() }
-    captureStderr(callold).should.containEql('my-lib')
+    assert.ok(captureStderr(callold).indexOf('my-lib') !== -1)
   })
 
   it('should log deprecation', function () {
     function callold() { mylib.old() }
-    captureStderr(callold).should.containEql('deprecate')
+    assert.ok(captureStderr(callold).indexOf('deprecate') !== -1)
   })
 
   it('should log message', function () {
     function callold() { mylib.old() }
-    captureStderr(callold).should.containEql('old')
+    assert.ok(captureStderr(callold).indexOf('old') !== -1)
   })
 
   it('should log call site', function () {
     function callold() { mylib.old() }
     var stderr = captureStderr(callold)
-    stderr.should.containEql(basename(__filename))
-    stderr.should.match(/\.js:[0-9]+:[0-9]+/)
+    assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+    assert.ok(/\.js:[0-9]+:[0-9]+/.test(stderr))
+  })
+
+  it('should log call site from strict lib', function () {
+    function callold() { strictlib.old() }
+    var stderr = captureStderr(callold)
+    assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+    assert.ok(/\.js:[0-9]+:[0-9]+/.test(stderr))
   })
 
   it('should log call site regardless of Error.stackTraceLimit', function () {
@@ -47,8 +55,8 @@ describe('deprecate(message)', function () {
     try {
       Error.stackTraceLimit = 1
       var stderr = captureStderr(callold)
-      stderr.should.containEql(basename(__filename))
-      stderr.should.match(/\.js:[0-9]+:[0-9]+/)
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(/\.js:[0-9]+:[0-9]+/.test(stderr))
     } finally {
       Error.stackTraceLimit = limit
     }
@@ -57,9 +65,16 @@ describe('deprecate(message)', function () {
   it('should log call site within eval', function () {
     function callold() { eval('mylib.old()') }
     var stderr = captureStderr(callold)
-    stderr.should.containEql(basename(__filename))
-    stderr.should.containEql('<anonymous>:1:')
-    stderr.should.match(/\.js:[0-9]+:[0-9]+/)
+    assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+    assert.ok(stderr.indexOf('<anonymous>:1:') !== -1)
+    assert.ok(/\.js:[0-9]+:[0-9]+/.test(stderr))
+  })
+
+  it('should log call site within strict', function () {
+    function callold() { 'use strict'; mylib.old() }
+    var stderr = captureStderr(callold)
+    assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+    assert.ok(/\.js:[0-9]+:[0-9]+/.test(stderr))
   })
 
   it('should only warn once per call site', function () {
@@ -71,8 +86,8 @@ describe('deprecate(message)', function () {
     }
 
     var stderr = captureStderr(callold)
-    stderr.split('deprecated').should.have.length(2)
-    stderr.split('invoke').should.have.length(6)
+    assert.equal(stderr.split('deprecated').length, 2)
+    assert.equal(stderr.split('invoke').length, 6)
   })
 
   it('should warn for different fns on same call site', function () {
@@ -83,10 +98,10 @@ describe('deprecate(message)', function () {
     }
 
     prop = 'old'
-    captureStderr(callold).should.containEql(basename(__filename))
+    assert.ok(captureStderr(callold).indexOf(basename(__filename)) !== -1)
 
     prop = 'old2'
-    captureStderr(callold).should.containEql(basename(__filename))
+    assert.ok(captureStderr(callold).indexOf(basename(__filename)) !== -1)
   })
 
   it('should warn for different calls on same line', function () {
@@ -96,18 +111,18 @@ describe('deprecate(message)', function () {
 
     var stderr = captureStderr(callold)
     var fileline = stderr.match(/\.js:[0-9]+:/)
-    stderr.should.containEql(basename(__filename))
-    stderr.split('deprecated').should.have.length(3)
-    stderr.split(fileline[0]).should.have.length(3)
+    assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+    assert.equal(stderr.split('deprecated').length, 3)
+    assert.equal(stderr.split(fileline[0]).length, 3)
   })
 
   describe('when message omitted', function () {
     it('should generate message for method call on named function', function () {
       function callold() { mylib.automsgnamed() }
       var stderr = captureStderr(callold)
-      stderr.should.containEql(basename(__filename))
-      stderr.should.containEql('deprecated')
-      stderr.should.containEql(' Object.automsgnamed ')
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(stderr.indexOf('deprecated') !== -1)
+      assert.ok(stderr.indexOf(' automsgnamed ') !== -1)
     })
 
     it('should generate message for function call on named function', function () {
@@ -116,17 +131,17 @@ describe('deprecate(message)', function () {
         fn()
       }
       var stderr = captureStderr(callold)
-      stderr.should.containEql(basename(__filename))
-      stderr.should.containEql('deprecated')
-      stderr.should.containEql(' automsgnamed ')
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(stderr.indexOf('deprecated') !== -1)
+      assert.ok(stderr.indexOf(' automsgnamed ') !== -1)
     })
 
     it('should generate message for method call on unnamed function', function () {
       function callold() { mylib.automsg() }
       var stderr = captureStderr(callold)
-      stderr.should.containEql(basename(__filename))
-      stderr.should.containEql('deprecated')
-      stderr.should.containEql(' Object.exports.automsg ')
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(stderr.indexOf('deprecated') !== -1)
+      assert.ok(stderr.indexOf(' exports.automsg ') !== -1)
     })
 
     it('should generate message for function call on unnamed function', function () {
@@ -135,17 +150,65 @@ describe('deprecate(message)', function () {
         fn()
       }
       var stderr = captureStderr(callold)
-      stderr.should.containEql(basename(__filename))
-      stderr.should.containEql('deprecated')
-      stderr.should.containEql(' exports.automsg ')
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(stderr.indexOf('deprecated') !== -1)
+      assert.ok(stderr.indexOf(' exports.automsg ') !== -1)
     })
 
     it('should generate message for function call on anonymous function', function () {
       function callold() { mylib.automsganon() }
       var stderr = captureStderr(callold)
-      stderr.should.containEql(basename(__filename))
-      stderr.should.containEql('deprecated')
-      stderr.should.match(/ exports\.automsganon | <anonymous@[^:]+:[0-9]+:[0-9]+> /)
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(stderr.indexOf('deprecated') !== -1)
+      assert.ok(/ exports\.automsganon | <anonymous@[^:]+:[0-9]+:[0-9]+> /.test(stderr))
+    })
+
+    describe('in strict mode library', function () {
+      it('should generate message for method call on named function', function () {
+        function callold() { strictlib.automsgnamed() }
+        var stderr = captureStderr(callold)
+        assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+        assert.ok(stderr.indexOf('deprecated') !== -1)
+        assert.ok(stderr.indexOf(' automsgnamed ') !== -1)
+      })
+
+      it('should generate message for function call on named function', function () {
+        function callold() {
+          var fn = strictlib.automsgnamed
+          fn()
+        }
+        var stderr = captureStderr(callold)
+        assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+        assert.ok(stderr.indexOf('deprecated') !== -1)
+        assert.ok(stderr.indexOf(' automsgnamed ') !== -1)
+      })
+
+      it('should generate message for method call on unnamed function', function () {
+        function callold() { strictlib.automsg() }
+        var stderr = captureStderr(callold)
+        assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+        assert.ok(stderr.indexOf('deprecated') !== -1)
+        assert.ok(stderr.indexOf(' exports.automsg ') !== -1)
+      })
+
+      it('should generate message for function call on unnamed function', function () {
+        function callold() {
+          var fn = strictlib.automsg
+          fn()
+        }
+        var stderr = captureStderr(callold)
+        assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+        assert.ok(stderr.indexOf('deprecated') !== -1)
+        assert.ok(stderr.indexOf(' exports.automsg ') !== -1)
+      })
+
+      it('should generate message for function call on anonymous function', function () {
+        function callold() { strictlib.automsganon() }
+        var stderr = captureStderr(callold)
+        assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+        assert.ok(stderr.indexOf('deprecated') !== -1)
+        assert.ok(/ exports\.automsganon | <anonymous@[^:]+:[0-9]+:[0-9]+> /.test(stderr))
+      })
     })
   })
 
@@ -157,25 +220,25 @@ describe('deprecate(message)', function () {
     })
 
     it('should log in color', function () {
-      stderr.should.not.be.empty
-      stderr.should.containEql('\x1b[')
+      assert.notEqual(stderr, '')
+      assert.ok(stderr.indexOf('\x1b[') !== -1)
     })
 
     it('should log namespace', function () {
-      stderr.should.containEql('my-lib')
+      assert.ok(stderr.indexOf('my-lib') !== -1)
     })
 
     it('should log deprecation', function () {
-      stderr.should.containEql('deprecate')
+      assert.ok(stderr.indexOf('deprecate') !== -1)
     })
 
     it('should log message', function () {
-      stderr.should.containEql('old')
+      assert.ok(stderr.indexOf('old') !== -1)
     })
 
     it('should log call site', function () {
-      stderr.should.containEql(basename(__filename))
-      stderr.should.match(/\.js:[0-9]+:[0-9]+/)
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(/\.js:[0-9]+:[0-9]+/.test(stderr))
     })
   })
 
@@ -187,60 +250,67 @@ describe('deprecate(message)', function () {
     })
 
     it('should not log in color', function () {
-      stderr.should.not.be.empty
-      stderr.should.not.containEql('\x1b[')
+      assert.notEqual(stderr, '')
+      assert.ok(stderr.indexOf('\x1b[') === -1)
     })
 
     it('should log namespace', function () {
-      stderr.should.containEql('my-lib')
+      assert.ok(stderr.indexOf('my-lib') !== -1)
     })
 
     it('should log timestamp', function () {
-      stderr.should.match(/\w+, \d+ \w+ \d{4} \d{2}:\d{2}:\d{2} \w{3}/)
+      assert.ok(/\w+, \d+ \w+ \d{4} \d{2}:\d{2}:\d{2} \w{3}/.test(stderr))
     })
 
     it('should log deprecation', function () {
-      stderr.should.containEql('deprecate')
+      assert.ok(stderr.indexOf('deprecate') !== -1)
     })
 
     it('should log message', function () {
-      stderr.should.containEql('old')
+      assert.ok(stderr.indexOf('old') !== -1)
     })
 
     it('should log call site', function () {
-      stderr.should.containEql(basename(__filename))
-      stderr.should.match(/\.js:[0-9]+:[0-9]+/)
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(/\.js:[0-9]+:[0-9]+/.test(stderr))
     })
   })
 })
 
 describe('deprecate.function(fn, message)', function () {
-  it('should thrown when not given function', function () {
+  it('should throw when not given function', function () {
     var deprecate = depd('test')
-    deprecate.function.bind(deprecate, 2).should.throw(/fn.*function/)
+    assert.throws(deprecate.function.bind(deprecate, 2), /fn.*function/)
   })
 
   it('should log on call to function', function () {
     function callold() { mylib.oldfn() }
-    captureStderr(callold).should.containEql(' oldfn ')
+    assert.ok(captureStderr(callold).indexOf(' oldfn ') !== -1)
   })
 
   it('should have same arity', function () {
-    mylib.oldfn.should.have.length(2)
+    assert.equal(mylib.oldfn.length, 2)
   })
 
   it('should pass arguments', function () {
     var ret
     function callold() { ret = mylib.oldfn(1, 2) }
-    captureStderr(callold).should.containEql(' oldfn ')
-    ret.should.equal(2)
+    assert.ok(captureStderr(callold).indexOf(' oldfn ') !== -1)
+    assert.equal(ret, 2)
   })
 
   it('should show call site outside scope', function () {
     function callold() { mylib.layerfn() }
     var stderr = captureStderr(callold)
-    stderr.should.containEql(' oldfn ')
-    stderr.should.match(/test.js:[0-9]+:[0-9]+/)
+    assert.ok(stderr.indexOf(' oldfn ') !== -1)
+    assert.ok(/test.js:[0-9]+:[0-9]+/.test(stderr))
+  })
+
+  it('should show call site outside scope from strict lib', function () {
+    function callold() { strictlib.layerfn() }
+    var stderr = captureStderr(callold)
+    assert.ok(stderr.indexOf(' oldfn ') !== -1)
+    assert.ok(/test.js:[0-9]+:[0-9]+/.test(stderr))
   })
 
   it('should only warn once per call site', function () {
@@ -252,11 +322,13 @@ describe('deprecate.function(fn, message)', function () {
     }
 
     var stderr = captureStderr(callold)
-    stderr.split('deprecated').should.have.length(2)
-    stderr.split('invoke').should.have.length(6)
+    assert.equal(stderr.split('deprecated').length, 2)
+    assert.equal(stderr.split('invoke').length, 6)
   })
 
   it('should handle rapid calling of deprecated thing', function () {
+    this.timeout(5000)
+
     function callold() {
       for (var i = 0; i < 10000; i++) {
         mylib.oldfn()
@@ -264,7 +336,7 @@ describe('deprecate.function(fn, message)', function () {
     }
 
     var stderr = captureStderr(callold)
-    stderr.split('deprecated').should.have.length(2)
+    assert.equal(stderr.split('deprecated').length, 2)
   })
 
   it('should warn for different calls on same line', function () {
@@ -274,28 +346,48 @@ describe('deprecate.function(fn, message)', function () {
 
     var stderr = captureStderr(callold)
     var fileline = stderr.match(/\.js:[0-9]+:/)
-    stderr.should.containEql(basename(__filename))
-    stderr.split('deprecated').should.have.length(3)
-    stderr.split(fileline[0]).should.have.length(3)
+    assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+    assert.equal(stderr.split('deprecated').length, 3)
+    assert.equal(stderr.split(fileline[0]).length, 3)
   })
 
   describe('when message omitted', function () {
     it('should generate message for method call on named function', function () {
       function callold() { mylib.oldfnauto() }
       var stderr = captureStderr(callold)
-      stderr.should.containEql(basename(__filename))
-      stderr.should.containEql('deprecated')
-      stderr.should.containEql(' Object.fn ')
-      stderr.should.match(/ at [^:]+test\.js:/)
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(stderr.indexOf('deprecated') !== -1)
+      assert.ok(stderr.indexOf(' fn ') !== -1)
+      assert.ok(/ at [^:]+test\.js:/.test(stderr))
     })
 
     it('should generate message for method call on anonymous function', function () {
       function callold() { mylib.oldfnautoanon() }
       var stderr = captureStderr(callold)
-      stderr.should.containEql(basename(__filename))
-      stderr.should.containEql('deprecated')
-      stderr.should.match(/ <anonymous@[^:]+my-lib\.js:[0-9]+:[0-9]+> /)
-      stderr.should.match(/ at [^:]+test\.js:/)
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(stderr.indexOf('deprecated') !== -1)
+      assert.ok(/ <anonymous@[^:]+my-lib\.js:[0-9]+:[0-9]+> /.test(stderr))
+      assert.ok(/ at [^:]+test\.js:/.test(stderr))
+    })
+
+    describe('in strict mode library', function () {
+      it('should generate message for method call on named function', function () {
+        function callold() { strictlib.oldfnauto() }
+        var stderr = captureStderr(callold)
+        assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+        assert.ok(stderr.indexOf('deprecated') !== -1)
+        assert.ok(stderr.indexOf(' fn ') !== -1)
+        assert.ok(/ at [^:]+test\.js:/.test(stderr))
+      })
+
+      it('should generate message for method call on anonymous function', function () {
+        function callold() { strictlib.oldfnautoanon() }
+        var stderr = captureStderr(callold)
+        assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+        assert.ok(stderr.indexOf('deprecated') !== -1)
+        assert.ok(/ <anonymous@[^:]+strict-lib\.js:[0-9]+:[0-9]+> /.test(stderr))
+        assert.ok(/ at [^:]+test\.js:/.test(stderr))
+      })
     })
   })
 })
@@ -303,27 +395,27 @@ describe('deprecate.function(fn, message)', function () {
 describe('deprecate.property(obj, prop, message)', function () {
   it('should throw when given primitive', function () {
     var deprecate = depd('test')
-    deprecate.property.bind(deprecate, 2).should.throw(/obj.*object/)
+    assert.throws(deprecate.property.bind(deprecate, 2), /obj.*object/)
   })
 
   it('should throw when given missing property', function () {
     var deprecate = depd('test')
     var obj = {}
-    deprecate.property.bind(deprecate, obj, 'blargh').should.throw(/property.*owner/)
+    assert.throws(deprecate.property.bind(deprecate, obj, 'blargh'), /property.*owner/)
   })
 
   it('should throw when given non-configurable property', function () {
     var deprecate = depd('test')
     var obj = {}
     Object.defineProperty(obj, 'thing', {value: 'thingie'})
-    deprecate.property.bind(deprecate, obj, 'thing').should.throw(/property.*configurable/)
+    assert.throws(deprecate.property.bind(deprecate, obj, 'thing'), /property.*configurable/)
   })
 
   it('should log on access to property', function () {
     function callprop() { mylib.propa }
     var stderr = captureStderr(callprop)
-    stderr.should.containEql(' deprecated ')
-    stderr.should.containEql(' propa gone ')
+    assert.ok(stderr.indexOf(' deprecated ') !== -1)
+    assert.ok(stderr.indexOf(' propa gone ') !== -1)
   })
 
   it('should log on setting property', function () {
@@ -331,10 +423,10 @@ describe('deprecate.property(obj, prop, message)', function () {
     function callprop() { val = mylib.propa }
     function setprop() { mylib.propa = 'newval' }
     var stderr = captureStderr(setprop)
-    stderr.should.containEql(' deprecated ')
-    stderr.should.containEql(' propa gone ')
-    captureStderr(callprop).should.containEql(' deprecated ')
-    val.should.equal('newval')
+    assert.ok(stderr.indexOf(' deprecated ') !== -1)
+    assert.ok(stderr.indexOf(' propa gone ') !== -1)
+    assert.ok(captureStderr(callprop).indexOf(' deprecated ') !== -1)
+    assert.equal(val, 'newval')
   })
 
   it('should only warn once per call site', function () {
@@ -346,8 +438,8 @@ describe('deprecate.property(obj, prop, message)', function () {
     }
 
     var stderr = captureStderr(callold)
-    stderr.split('deprecated').should.have.length(2)
-    stderr.split('access').should.have.length(6)
+    assert.equal(stderr.split('deprecated').length, 2)
+    assert.equal(stderr.split('access').length, 6)
   })
 
   it('should warn for different accesses on same line', function () {
@@ -357,31 +449,54 @@ describe('deprecate.property(obj, prop, message)', function () {
 
     var stderr = captureStderr(callold)
     var fileline = stderr.match(/\.js:[0-9]+:/)
-    stderr.should.containEql(basename(__filename))
-    stderr.split('deprecated').should.have.length(3)
-    stderr.split(fileline[0]).should.have.length(3)
+    assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+    assert.equal(stderr.split('deprecated').length, 3)
+    assert.equal(stderr.split(fileline[0]).length, 3)
   })
 
   it('should show call site outside scope', function () {
     function callold() { mylib.layerprop() }
     var stderr = captureStderr(callold)
-    stderr.should.containEql(' propa ')
-    stderr.should.match(/test.js:[0-9]+:[0-9]+/)
+    assert.ok(stderr.indexOf(' propa ') !== -1)
+    assert.ok(/test.js:[0-9]+:[0-9]+/.test(stderr))
+  })
+
+  it('should show call site outside scope from strict lib', function () {
+    function callold() { strictlib.layerprop() }
+    var stderr = captureStderr(callold)
+    assert.ok(stderr.indexOf(' propa ') !== -1)
+    assert.ok(/test.js:[0-9]+:[0-9]+/.test(stderr))
   })
 
   describe('when obj is a function', function () {
     it('should log on access to property on function', function () {
       function callprop() { mylib.fnprop.propa }
       var stderr = captureStderr(callprop)
-      stderr.should.containEql(' deprecated ')
-      stderr.should.containEql(' fn propa gone ')
+      assert.ok(stderr.indexOf(' deprecated ') !== -1)
+      assert.ok(stderr.indexOf(' fn propa gone ') !== -1)
     })
 
     it('should generate message on named function', function () {
       function callprop() { mylib.fnprop.propautomsg }
       var stderr = captureStderr(callprop)
-      stderr.should.containEql(' deprecated ')
-      stderr.should.containEql(' thefn.propautomsg ')
+      assert.ok(stderr.indexOf(' deprecated ') !== -1)
+      assert.ok(stderr.indexOf(' thefn.propautomsg ') !== -1)
+    })
+
+    describe('in strict mode library', function () {
+      it('should log on access to property on function', function () {
+        function callprop() { strictlib.fnprop.propa }
+        var stderr = captureStderr(callprop)
+        assert.ok(stderr.indexOf(' deprecated ') !== -1)
+        assert.ok(stderr.indexOf(' fn propa gone ') !== -1)
+      })
+
+      it('should generate message on named function', function () {
+        function callprop() { strictlib.fnprop.propautomsg }
+        var stderr = captureStderr(callprop)
+        assert.ok(stderr.indexOf(' deprecated ') !== -1)
+        assert.ok(stderr.indexOf(' thefn.propautomsg ') !== -1)
+      })
     })
   })
 
@@ -389,15 +504,15 @@ describe('deprecate.property(obj, prop, message)', function () {
     it('should log on access and set', function () {
       function callold() { mylib.propa }
       function setold() { mylib.propa = 'val' }
-      captureStderr(callold).should.containEql(' deprecated ')
-      captureStderr(setold).should.containEql(' deprecated ')
+      assert.ok(captureStderr(callold).indexOf(' deprecated ') !== -1)
+      assert.ok(captureStderr(setold).indexOf(' deprecated ') !== -1)
     })
 
     it('should not log on set to non-writable', function () {
       function callold() { mylib.propget }
       function setold() { mylib.propget = 'val' }
-      captureStderr(callold).should.containEql(' deprecated ')
-      captureStderr(setold).should.be.empty
+      assert.ok(captureStderr(callold).indexOf(' deprecated ') !== -1)
+      assert.equal(captureStderr(setold), '')
     })
   })
 
@@ -405,18 +520,18 @@ describe('deprecate.property(obj, prop, message)', function () {
     it('should log on access and set', function () {
       function callold() { mylib.propdyn }
       function setold() { mylib.propdyn = 'val' }
-      captureStderr(callold).should.containEql(' deprecated ')
-      captureStderr(setold).should.containEql(' deprecated ')
+      assert.ok(captureStderr(callold).indexOf(' deprecated ') !== -1)
+      assert.ok(captureStderr(setold).indexOf(' deprecated ') !== -1)
     })
 
     it('should not log on access when no accessor', function () {
       function callold() { mylib.propsetter }
-      captureStderr(callold).should.be.empty
+      assert.equal(captureStderr(callold), '')
     })
 
     it('should not log on set when no setter', function () {
       function callold() { mylib.propgetter = 'val' }
-      captureStderr(callold).should.be.empty
+      assert.equal(captureStderr(callold), '')
     })
   })
 
@@ -424,10 +539,21 @@ describe('deprecate.property(obj, prop, message)', function () {
     it('should generate message for method call on named function', function () {
       function callold() { mylib.propauto }
       var stderr = captureStderr(callold)
-      stderr.should.containEql(basename(__filename))
-      stderr.should.containEql('deprecated')
-      stderr.should.containEql(' Object.propauto ')
-      stderr.should.match(/ at [^:]+test\.js:/)
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(stderr.indexOf('deprecated') !== -1)
+      assert.ok(stderr.indexOf(' propauto ') !== -1)
+      assert.ok(/ at [^:]+test\.js:/.test(stderr))
+    })
+
+    describe('in strict mode library', function () {
+      it('should generate message for method call on named function', function () {
+        function callold() { strictlib.propauto }
+        var stderr = captureStderr(callold)
+        assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+        assert.ok(stderr.indexOf('deprecated') !== -1)
+        assert.ok(stderr.indexOf(' propauto ') !== -1)
+        assert.ok(/ at [^:]+test\.js:/.test(stderr))
+      })
     })
   })
 })
@@ -447,50 +573,46 @@ describe('process.on(\'deprecation\', fn)', function () {
   function ondeprecation(err) { error = err }
 
   it('should not write when listener exists', function () {
-    stderr.should.be.empty
+    assert.equal(stderr, '')
   })
 
   it('should emit error', function () {
-    error.should.be.ok
-  })
-
-  it('should emit DeprecationError', function () {
-    error.name.should.equal('DeprecationError')
+    assert.ok(error)
   })
 
   it('should emit DeprecationError', function () {
-    error.name.should.equal('DeprecationError')
+    assert.equal(error.name, 'DeprecationError')
   })
 
   it('should emit error with message', function () {
-    error.message.should.equal('old')
+    assert.equal(error.message, 'old')
   })
 
   it('should emit error with namespace', function () {
-    error.namespace.should.equal('my-lib')
+    assert.equal(error.namespace, 'my-lib')
   })
 
   it('should emit error with proper [[Class]]', function () {
-    Object.prototype.toString.call(error).should.equal('[object Error]')
+    assert.equal(Object.prototype.toString.call(error), '[object Error]')
   })
 
   it('should be instanceof Error', function () {
-    error.should.be.instanceof(Error)
+    assert.ok(error instanceof Error)
   })
 
   it('should emit error with proper stack', function () {
     var stack = error.stack.split('\n')
-    stack[0].should.equal('DeprecationError: my-lib deprecated old')
-    stack[1].should.match(/    at callold \(.+test\.js:[0-9]+:[0-9]+\)/)
+    assert.equal(stack[0], 'DeprecationError: my-lib deprecated old')
+    assert.ok(/    at callold \(.+test\.js:[0-9]+:[0-9]+\)/.test(stack[1]))
   })
 
   it('should have writable properties', function () {
     error.name = 'bname'
-    error.name.should.equal('bname')
+    assert.equal(error.name, 'bname')
     error.message = 'bmessage'
-    error.message.should.equal('bmessage')
+    assert.equal(error.message, 'bmessage')
     error.stack = 'bstack'
-    error.stack.should.equal('bstack')
+    assert.equal(error.stack, 'bstack')
   })
 })
 
@@ -513,37 +635,37 @@ describe('process.env.NO_DEPRECATION', function () {
   it('should suppress given namespace', function () {
     process.env.NO_DEPRECATION = 'old-lib'
     var oldlib = require('./fixtures/old-lib')
-    captureStderr(oldlib.old).should.be.empty
-    captureStderr(oldlib.old2).should.not.be.empty
+    assert.equal(captureStderr(oldlib.old), '')
+    assert.notEqual(captureStderr(oldlib.old2), '')
   })
 
   it('should suppress multiple namespaces', function () {
     process.env.NO_DEPRECATION = 'cool-lib,neat-lib'
     var coollib = require('./fixtures/cool-lib')
-    captureStderr(coollib.cool).should.be.empty
-    captureStderr(coollib.neat).should.be.empty
+    assert.equal(captureStderr(coollib.cool), '')
+    assert.equal(captureStderr(coollib.neat), '')
   })
 
   it('should be case-insensitive', function () {
     process.env.NO_DEPRECATION = 'NEW-LIB'
     var newlib = require('./fixtures/new-lib')
-    captureStderr(newlib.old).should.be.empty
+    assert.equal(captureStderr(newlib.old), '')
   })
 
   it('should emit "deprecation" events anyway', function () {
     process.env.NO_DEPRECATION = 'thing-lib'
     var thinglib = require('./fixtures/thing-lib')
     process.on('deprecation', ondeprecation)
-    captureStderr(thinglib.old).should.be.empty
-    error.namespace.should.equal('thing-lib')
+    assert.equal(captureStderr(thinglib.old), '')
+    assert.equal(error.namespace, 'thing-lib')
   })
 
   describe('when *', function () {
     it('should suppress any namespace', function () {
       process.env.NO_DEPRECATION = '*'
       var multilib = require('./fixtures/multi-lib')
-      captureStderr(multilib.old).should.be.empty
-      captureStderr(multilib.old2).should.be.empty
+      assert.equal(captureStderr(multilib.old), '')
+      assert.equal(captureStderr(multilib.old2), '')
     })
   })
 })
@@ -560,13 +682,13 @@ describe('process.env.TRACE_DEPRECATION', function () {
   it('should trace given namespace', function () {
     var tracelib = require('./fixtures/trace-lib')
     function callold() { tracelib.old() }
-    captureStderr(callold).should.containEql(' trace-lib deprecated old\n    at callold (')
+    assert.ok(captureStderr(callold).indexOf(' trace-lib deprecated old\n    at callold (') !== -1)
   })
 
   it('should not trace non-given namespace', function () {
     var tracelib = require('./fixtures/trace-lib')
     function callold() { tracelib.old2() }
-    captureStderr(callold).should.containEql(' trace-lib-other deprecated old2 at ')
+    assert.ok(captureStderr(callold).indexOf(' trace-lib-other deprecated old2 at ') !== -1)
   })
 
   describe('when output supports colors', function () {
@@ -578,17 +700,17 @@ describe('process.env.TRACE_DEPRECATION', function () {
     })
 
     it('should log in color', function () {
-      stderr.should.not.be.empty
-      stderr.should.containEql('\x1b[')
+      assert.notEqual(stderr, '')
+      assert.ok(stderr.indexOf('\x1b[') !== -1)
     })
 
     it('should log namespace', function () {
-      stderr.should.containEql('trace-lib')
+      assert.ok(stderr.indexOf('trace-lib') !== -1)
     })
 
     it('should log call site in color', function () {
-      stderr.should.containEql(basename(__filename))
-      stderr.should.match(/\x1b\[\d+mat callold \(/)
+      assert.ok(stderr.indexOf(basename(__filename)) !== -1)
+      assert.ok(/\x1b\[\d+mat callold \(/.test(stderr))
     })
   })
 })
@@ -599,7 +721,7 @@ describe('node script.js', function () {
       if (err) return done(err)
       var filename = path.relative(process.cwd(), script)
       stderr = stderr.replace(/\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+/, '__timestamp__')
-      stderr.should.equal('__timestamp__ my-cool-module deprecated oldfunction at ' + filename + ':7:10\n')
+      assert.equal(stderr, '__timestamp__ my-cool-module deprecated oldfunction at ' + filename + ':7:10\n')
       done()
     })
   })
@@ -616,7 +738,7 @@ describe('node script.js', function () {
     it('should suppress deprecation message', function (done) {
       captureChildStderr(['--no-deprecation', script], function (err, stderr) {
         if (err) return done(err)
-        stderr.should.be.empty
+        assert.equal(stderr, '')
         done()
       })
     })
@@ -627,7 +749,7 @@ describe('node script.js', function () {
       captureChildStderr(['--trace-deprecation', script], function (err, stderr) {
         if (err) return done(err)
         stderr = stderr.replace(/\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+/, '__timestamp__')
-        stderr.should.startWith('__timestamp__ my-cool-module deprecated oldfunction\n    at run (' + script + ':7:10)\n    at')
+        assert.ok(stderr.indexOf('__timestamp__ my-cool-module deprecated oldfunction\n    at run (' + script + ':7:10)\n    at') === 0)
         done()
       })
     })

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-depd.git



More information about the Pkg-javascript-commits mailing list