Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

TypeError: assert._capt is not a function #42

Closed
searls opened this issue Apr 9, 2016 · 9 comments
Closed

TypeError: assert._capt is not a function #42

searls opened this issue Apr 9, 2016 · 9 comments

Comments

@searls
Copy link

searls commented Apr 9, 2016

I tried to add this really simply to my vanilla Node.js module using intelli-espower-loader, but right from the jump I got this error: "TypeError: assert._capt is not a function"

Any root causes?

To reproduce, you can check out this repo at this commit: testdouble/scripty@4a00d0f

@twada
Copy link
Member

twada commented Apr 9, 2016

I assume that you are still using normal assert module, not power-assert.

In this case, please change here,

from

global.assert = require('assert')

to

global.assert = require('power-assert')

@searls
Copy link
Author

searls commented Apr 9, 2016

Ohhhhh, duh. Thank you.

@searls searls closed this as completed Apr 9, 2016
@twada
Copy link
Member

twada commented Apr 11, 2016

Added to FAQ. Thanks!

@twada
Copy link
Member

twada commented Apr 12, 2016

FYI: if you are using Babel, you can use babel-plugin-empower-assert to solve this problem.

With babel-plugin-empower-assert, you can enhance normal assert to power-assert with .babelrc settings.

{
  "presets": [
    . . .
  ],
  "env": {
    "development": {
      "plugins": [
        "babel-plugin-empower-assert",
        "babel-plugin-espower"
      ]
    }
  }
}

@searls
Copy link
Author

searls commented Apr 12, 2016

Thanks @twada. To be honest I still wasn't able to get past this bug when writing a vanilla library. I tried using the "intelli" loader and then power-assert but it didn't work. My only theory is that maybe the loader has to be loaded in a separate file from any requires of power-assert?

The repo in question is the same one: github.com/testdouble/scripty if you have a minute to advise me (I'm using a very minimal testing lib that doesn't provide much abstraction)

@twada
Copy link
Member

twada commented Apr 12, 2016

@searls Thank you for your question. I've cloned your repo and enabled power-assert.
Your scripty/decorate-assertions.js is tricky a bit so I should use my WIP branch of espower

Here is the patch.

diff --git a/package.json b/package.json
index 93aaeee..938157b 100644
--- a/package.json
+++ b/package.json
@@ -30,7 +30,10 @@
   },
   "homepage": "https://github.com/testdouble/scripty#readme",
   "devDependencies": {
+    "espower": "power-assert-js/espower#embedded-recorder",
+    "espower-loader": "^1.0.0",
     "intercept-stdout": "^0.1.2",
+    "power-assert": "^1.3.1",
     "rimraf": "^2.5.2",
     "semver": "^5.1.0",
     "standard": "^6.0.8",
diff --git a/test/safe-helper.js b/test/safe-helper.js
index 118208e..21a2d6b 100644
--- a/test/safe-helper.js
+++ b/test/safe-helper.js
@@ -1,5 +1,10 @@
+require('espower-loader')({
+  cwd: process.cwd(),
+  pattern: 'test/safe/**/*.js'
+})
+
 var decorateAssertions = require('./decorate-assertions')
-global.assert = decorateAssertions(require('assert'))
+global.assert = decorateAssertions(require('power-assert'))

 var log = require('../lib/log')

diff --git a/test/unit-helper.js b/test/unit-helper.js
index c695b96..700cb61 100644
--- a/test/unit-helper.js
+++ b/test/unit-helper.js
@@ -1,7 +1,12 @@
+require('espower-loader')({
+  cwd: process.cwd(),
+  pattern: 'lib/**/*.test.js'
+})
+
 global.td = require('testdouble')

 var decorateAssertions = require('./decorate-assertions')
-global.assert = decorateAssertions(require('assert'))
+global.assert = decorateAssertions(require('power-assert'))

 var log = require('../lib/log')

Thanks.

@popomore
Copy link

popomore commented Sep 9, 2016

Same question, why can't use intelli-espower-loader with assert?

@twada
Copy link
Member

twada commented Dec 8, 2016

@popomore Now you can use intelli-espower-loader (espower-loader) with assert

see: espower-loader's CHANGELOG

@popomore
Copy link

popomore commented Dec 8, 2016

@twada Good Job

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants