How to get "should.be.false" syntax pass jslint? - node.js

I am writing JS UT for my NodeJS code. I am using Chai as the assertion library, and I prefer the should syntax. I also use jslint to check the JS file syntax, even the JS files for UT.
Now I have a problem with jslint and Chai. In Chai, you can use:
myvalue.should.be.true;
But jslint give me:
#1 Expected an assignment or function call and instead saw an expression.
I know jslint comes with many options, but I just cannot find the right one to turn off this check.

Just to make it clear to other readers:
You can add /*jshint expr: true*/ to the top of the test files, so it only allows it in the test files.
In the rare case that you use that kind of expressions in your code, you can add the expr: true option to the jshint config options.

You can also use myvalue.should.equal(true) instead.

It turns our jslint is unable to solve my problem. And due to many restrictions of jslint, I turned to jshint, and the option expr saved me :P

Related

Passing assymmetric matchers highlighted as wrong in the diff in Jest using toMatchBodySnapshot

When I use .toMatchSnapshot() if one matcher fails they are all highlighted in the diff making it hard to debug a test with multiple matchers. Passing assymmetric matchers are not supposed to be highlighted anymore according to https://github.com/facebook/jest/pull/9257.
When I use my debugger it looks like the code never makes it to the printDiffOrStringify from .toMatchSnapshot(). It uses other methods instead to print the diff.
Interested to hear if anyone else has dealt with this issue before I open a bug. Maybe I'm missing something. In the PR it sounds like this was solved generally for all expect functions.

Difference between lib and lib-cov in express?

I'm new to Node.js.
module.exports = process.env.EXPRESS_COV
? require("./lib-cov/express")
: require("./lib/express");
I know EXPRESS_COV returns a Boolean value, but what is the difference between lib-cov/express and lib/express?
process.env.EXPRESS_COV would be true when you're running tests and want to see the code coverage of those tests (i.e. how many lines of your codebase are actually executed when the tests are run). Mocha, the test framework used for express, achieves this through the use of jscoverage.
JSCoverage parses through your source code and adds a bunch of lines that look like this:
$_jscoverage[filename][line]++;
Naturally, that's rather confusing to have in one's source code, not to mention adding a lot of bulk. So we'd never want JSCoverage processed files in our codebase. Fortunately, JSCoverage places the modified files in a different directory. In this case, ./lib-cov/ instead of ./lib/. That way, we can see how effective our tests are and not clutter up our code.
For details on how this whole rigamarole runs, see TJ Holowaychuk's article.
If you want to avoid all of this, you can use Istanbul instead, as it's much simpler and doesn't require exceptions in index.js

requirejs + r.js disable case sensitivity

Is there a way/parameter that turns off case sensitivity in requirejs, for that matter is there a r.js switch to disable case sensitivity.
If i define a module in x.js
if i ask for it via define('x',function(x){}) or define('X',function(x){}) this will cause two objects in requirejs.s.contexts._.defined[x and X]
Is there a way to-lower all of this and not worry that someone will uppercase a character.
For that matter r.js minifies by walking the dependency tree is there a switch to make it not case sensitive so that i don't get two define('x'...define('X'.. modules in the minified output.
No, there's no flag or setting you can turn on to do this. And having read RequireJS' code, I think this would be a significant enterprise to make it case-insensitive. It would require more than just overriding a few functions here and there. This applies to require.js and r.js.
In an old thread, James Burke mentioned using map but that's not the same thing as case insensitivity.

How do you access the "special-keys" module from an Intern functional test?

How can you access the "special-keys" module from an Intern functional test?
I've tried specifying the path in the opening define statement of the test, I've also tried updating the "loader" attribute in the intern.js configuration file, but with no success so far. This must be a fairly common use case for a functional test but I've not had any luck so far and can find any examples in the source or the Git Wiki.
In Intern 1.3+ you may access that module through intern/dojo/node!wd/lib/special-keys. Alternatively you may simply use the escape codes directly in your type/keys strings.

alternative for module.exports

I've got a question that might sound strange.
We are using node.js, but the way we are writing javascript code is in a functional style. We have a lint tool that reports illegal use of the assignment expression. We can eleminate them all except for the 'module.exports = xxx' statement.
Is there an other way to load modules in node.js?
for example; the following statement would be fine as a solution as it is not an assignment expression but a variable declaration:
var exports = xxx;
if there is a way that nodejs would pick up this 'exports' variable, then we're done.
gr,
Coen
the following did the trick for me:
vm.runInThisContext
Looks like changing lint tool is the best way. :)
However you can use different module loader (there are some AMD implementations for node.js out there) that's pure functional.

Resources