How to combine mocha tests with mocha-phantomjs tests - javascript

Test cases:
server/
appTest.js
client/
clientTest.js
clientBundle.js
clientTest.html
All are mocha tests. For client tests, I use sinon, and webpack them to generate a bundle - clientBundle.js and run it using mocha-phantomjs for headless testing.
Now I have defined npm test as mocha test/server && mocha-phantomjs test/clientTest.html. It gives me results for both of them separately. How can I combine them into one - say mocha test/all.js.
Tried require()s inside test/all.js. mocha-phantomjs cannot be used as a library inside node. It can only be used as a CLI.

Related

Jest ---outputFile removes CLI coverage output

We use jest for unit testing in our repo, and include config for code coverage:
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts', 'infrastructure/**/*.ts'],
Normally this results in CLI output for coverage when running the tests. Recently however we've added Danger JS integration on our PR build, and the plugin we're using to report on Jest tests relies on the --outputFile switch for the jest command i.e. jest --outputFile test-results.json --json.
With --outputFile specified code coverage is still run and results are put in the coverage directory, but the CLI output doesn't include coverage, only pass / fail information. Is it possible to have both the outputFile and coverage to stdout?

Override Mocha globals with Jest in directory

I have a repo where I am using cypress for E2E tests and Jest for unit/integration tests. The folder structure is similar to:
> src
> utils
time.ts
time.spec.ts
> cypress
I am using jest for the tests in src and cypress is hard coded to use mocha
The current issue is - because cypress is exporting mocha as the default global for describe and expect - i have to explicitly import describe/expect from #jest/globals
Is there a config in either js, mocha or jest where i can specify only use mocha for cypress folder and jest for src folder?

Playwright JS: How do I convert my test files/code/directory from Jest test runner to Playwright test runner?

1- File names are like login.test.js but in playwright test runner file name should be login.spec.js
2- Directory is Login(Component) -> specs -> login.test.js but in playwright test runner it should be like tests/login.spec.js
3- In my code I use jest keywords for example describe but in Playwright test runner it is test.describe
4- The playwright test runner config file is not supported in my project because it uses Module export. It gives error while reading config file.
So in this situation how can I move my project to Playwright Test Runner?
Thank in advance.
Not really. By default, Playwright Test runs .*(test|spec)
In Playwright Test's config you can specify a directory that will be recursively scanned for test files. Use testDir property for that.
Yep, you have to add test prefix for almost all methods such as describe, test, beforeAll, beforeEach, afterAll, afterEach.
I believe that issue was fixed in this PR

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.

Run and add unit tests to nodejs project

I want to run the tests related to this project on github, see folder test on https://github.com/node-opcua/node-opcua . Unfortunately I have no idea which testing framework was used and how to run all the tests?
First, run npm install
This will install the required dependencies.
You can then use
npm test
See here:
https://github.com/node-opcua/node-opcua/blob/master/package.json#L15
That will run the tests using Mocha.

Categories

Resources