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?
Related
I am currently working on a Typescript project that has unit tests defined utilising Jest. The project uses Yarn 2 for execution but the tests have a dependancy which requires utilisation of moduleNameMapper in the jest.config.js.
As Yarn 2 works without any installs in node_modules, how can I use moduleNameMapper to point to a dependancy? Is there a new mapping required or some new Jest specific functionality?
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
I'm in a project where the babel config is in a subfolder:
config
|- babel.json
package.json
When I run jest it breaks
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
[...]
If I move babel.json to the root folder as .babelrc then all tests work.
Can I tell jest to look for a specific babel config file or does it need to be in the root?
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.
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.