How to create a custom reporter with Mocha - javascript

I am sure I am missing something obvious here!
I have read the instructions here (https://github.com/visionmedia/mocha/wiki/Third-party-reporters), and have taken their code and added as a new node module (i.e. it is within node_modules/my-reporter/reporter.js). However, I can't seem to get mocha to load this reporter.
I have tried numerous variations …
mocha allTests.js -R ./node_modules/my-reporter/reporter.js
mocha allTests.js -R my-reporter
But nothing works :-(
I can successfully load my reporter within a JS file:
my_reporter = require('./node_modules/my-reporter/reporter.js')
console.log(my_reporter);
Has anyone got any hints?

u should provide the reporter like this:
mocha allTests.js -R './node_modules/my-reporter/reporter'
You should not provide the .js file extension as that is the normal convention for including modules.

It appears that if mocha is installed globally (which I believe it almost always is), you have to install your reporter the same way.
If you don't want to publish the reporter as a public module, you can just:
npm pack
npm install /path/to/your/module.gz -g
I've tried putting the reporter everywhere else that would make sense, but was getting "invalid reporter" unless it was installed globally.

Related

Custom Flow type definitions apparently not being read

I have run the following:
$ npm install flow-bin
$ yarn global add flow-typed
$ flow-typed install
Which correctly populates ./flow-typed/npm/ with definitions, some are valid and some are stubs.
But these type definitions for libraries are not showing up in VSCode (with the official flowtype module installed, flowtype.flow-for-vscode—everything coming from the libraries show as typed with any on mouse hover), and running the flow checker from the command line returns no errors, even if I deliberately mis-use a library, such as:
const express = require('express');
express.chicken();
All of the sections in my ./flowconfig file are empty.
I have also tried adding my own definitions to the ./flow-typed/ directory (not the npm subdir) to no avail.
Does anyone have suggestions as to what I could be doing wrong and how to fix it?
Seems to have fixed itself when I restarted my laptop.

How can I use Mocha without removing Ava?

One of my co-workers added this Ava package to our setup, and it's done something I've never seen a Node package do before: interfere with other packages! Now when I try to run Mocha I get:
$ node_modules/mocha/bin/mocha test/
Test files must be run with the AVA CLI:
$ ava node_modules/mocha/bin/_mocha
I get that Ava would like to run my Mocha tests, but if I wanted that I'd run ava mocha not mocha. And because a co-worker is using it I can't simply uninstall the package.
Is there any way I can run plain Mocha tests on a machine with Ava installed?
One of the files in test/ imports ava and the imported code will recognise that it's not being run with the correct tooling and throw an error.
Might be worth subdividing your test/ directory to keep tests associated with their respective runners.
test/
ava/
SomeAvaTests.js
mocha/
SomeMochaTests.js
This way you can safely run mocha test/mocha/ and vice versa without worrying about treading on each other's toes.

how to use jsdoc in local project

Goal
I want to use jsdocs with npm.
Background
I am new to npm and its plugins. Recently I found out about jsdoc and I tried using it, with no success.
What I tried
First I installed the package using npm's command npm install --save jsdoc, and the install completed successfully.
However, when I try to use it in my project (I am inside the project's folder) I type jsdoc example.js and I get the following error:
/home/ubuntu/.nvm/versions/node/v4.4.5/bin/jsdoc: No such file or
directory
This leads me to think that:
I am in the wrong directory. If so, where should I be? (other than the project root folder)
The installation had a problem, even though it was successfull.
I have also tried to run npm jsdoc example.js but I get another error (this time from npm, saying I am not using it correctly).
I also installed jsdoc globally (using the -g flag) and it worked, but I truly want to avoid this because not all projects are using jsdoc.
Summary
To conclude, I am looking for a way to run jsdoc locally to a project with npm. Does anyone know of a way to do this?
To run jsdoc in the command line, the location of the jsdoc needs to be known. So when you have installed jsdoc globally, system would be able to find the file.
However if you want to run it locally, you need to include the file location before the jsdoc command.
For example, try using ./node_modules/jsdoc/jsdoc.js example.js

How to run specific tests with frisby?

We are using frisby to run our integration tests and while developing them, it would be handy to execute one specific one or a group of tests, without having run all of them and see extra noise. Right now I am commenting out all the ones I don't want to run, which is getting tedious.
Is there a way, from the command line, to run specific frisby tests?
So basically, instead of
npm test
I want to be able to say
npm test --name: posts
Or something like that. I found this post about jasmine-only, but I'm not sure it will satisfy my needs.
Thanks so much!
I'm not sure if you're still looking for answer, but this is pretty simple.
Firstly install latest version of jasmine-node from command line: npm install jasmine-node -g
Then to run particular test use: jasmine-node --coffee putTestNameHere
Install jasmine-node module. Execute one file at a time - you can group your test cases in specific file:
jasmin-node moduleTestCases_spec.js
Also, if you want to specify exact test case name to be executed, you can make use of sequenty module. It is a nodejs module, which you can specify the order(and thus the exact test cases to execute).
To run specific test in Frishby just run:
npm test ./folder/filename.js
So lets assume you have an folder say test under that you have a file called api.spec.js
then you will execute like this:
npm test ./test/api.spec.js
Parallely don't forget to specify these below things into your package.json file
"scripts": {
"test": "mocha" }

Custom build with core-js

I'm trying to create a custom build with core-js. Per the documentation, I first ran
npm i core-js && cd node_modules/core-js && npm i
which seemed to be fine. Then, also per the docs I tried
C:\GIT\coreJS_Custom\node_modules\core-js>npm run grunt build:es6.array.from -- --library=on --path=custom uglify
and lots of variations on that theme. It seems to run briefly, with no output at all, and I can't seem to find any generated file. What am I doing wrong?
Also, the above commands were run on the Windows 8.1 cmd terminal.
What's particularly interesting (and frustrating) is that running this
C:\GIT\coreJS_Custom\node_modules\core-js>npm run grunt kjhgjhghkghh
Similarly runs briefly and then seems to succeed.
I'm not sure what my root problem is, but for me, running the grant task on its own, without npm run did the trick
So something like this should be the final product.
C:\GIT\coreJS_Custom\node_modules\core-js>grunt build:es6.array.from --library=on --path="es6-array-from-build-min2" uglify

Categories

Resources