Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'CHAI_COV' of undefined #28

Closed
superfeedr opened this issue Feb 27, 2012 · 17 comments
Closed

Uncaught TypeError: Cannot read property 'CHAI_COV' of undefined #28

superfeedr opened this issue Feb 27, 2012 · 17 comments

Comments

@superfeedr
Copy link

Hello,

We are using chai.js with mocha and we run our tests in the browser...
It looks like a recent version of Chai introduced a little bug: Uncaught TypeError: Cannot read property 'CHAI_COV' of undefined.

It looks like it's coming from the fact that you now use process.env.CHAI_COV to load the appropriate library... and process.env does not seem to exist in the browser.

@vesln
Copy link
Member

vesln commented Feb 27, 2012

The process.env is located in ./index.js and it should not be a problem. In order to use chai in the browser you need to load only ./chai.js, which is the compiled version of chai for browser use only. Full, working example: http://chaijs.com/support/tests/

@logicalparadox
Copy link
Member

You can also hot link to http://chaijs.com/chai.js for the most recent version, just fyi. Let us know if this fixes your problem.

@superfeedr
Copy link
Author

Thanks guys for the response. The problem is that since we use var should = require('chai').should();, we do not get to decide what to include chai.js instead of index.js.
This sounds counter-intuitive since I said we test in the browser, but we do actually use browserify to put our node code in the browser :)

@logicalparadox
Copy link
Member

oh! well that makes sense! I will make a work around to check to see if process and process.env exist so that you can still use via browserify.

@logicalparadox
Copy link
Member

In release 0.4.2. If you have further problems with a browserify implementation, please reopen this issue.

@superfeedr
Copy link
Author

Awesome; that fixed the issue!

@logicalparadox
Copy link
Member

Great!

@ricardobeat
Copy link

chai@1.3.0

Cannot find module: "./lib-cov/chai" from directory ".../node_modules/chai"

The require('./lib-cov/chai') is interpreted by browserify but ./lib-cov doesn't seem to be included in the NPM package.

@logicalparadox
Copy link
Member

We leave the coverage lib out of the npm dist. This issue should have been resolved by the commit 9 months ago to index.js.

@domenic - I saw you have been doing some browserify work lately. Have you had this issue?

@ricardobeat
Copy link

@logicalparadox that commit only fixes the process issue. Browserify tries to bundle ./lib-cov/chai, since it can't figure out conditional requires.

@logicalparadox
Copy link
Member

The error that is being thrown is from browserify's "compile" sequence, not at run time then?

@domenic
Copy link
Contributor

domenic commented Nov 19, 2012

Hmm this is a tough one. Personally I've always hated the conditional require of lib-cov; I think it's a very shoddy and intrusive way of doing code coverage. Is there a way to not do that? Failing that, we could add

"browserify": "./lib/chai"

to package.json; that might fix things.

@logicalparadox
Copy link
Member

The other idea im liking even more is to have the package.json main be './lib/chai' and leave the conditionals for coverage support to our test bootstrap.

@domenic
Copy link
Contributor

domenic commented Nov 21, 2012

+1 to that

@domenic domenic reopened this Nov 26, 2012
@domenic
Copy link
Contributor

domenic commented Nov 26, 2012

@logicalparadox I actually need this for a new project. I verified that the fix to change main to ./lib/chai works great. Do you want to commit it, and update the testing bootstrap, or should I just push that change?

@logicalparadox
Copy link
Member

Go ahead and push. The tests will still require ./index.js so I can check coverage when I need to. Ill push an update out this evening.

@tjwebb
Copy link

tjwebb commented Nov 2, 2013

still does not work

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

No branches or pull requests

5 participants