Closed hongbo-miao closed 3 years ago
First just want to say this tool is soooooo awesome! Thanks!
Thanks!
And thanks for providing so much detail in your issue report 😀.
One important pre-requisite for running tests for all projects in a mono-repo is for your projects to all use the same test runner. It looks like this is true in your case as from what I can tell, all of your projects are using jest.
What you need to do is configure jest to run from your mono-repo root. For example, something like:
root/jest.config.js
module.exports = {
projects: [
'<rootDir>/api/',
'<rootDir>/web/',
'<rootDir>/mobile/',
],
}
Once jest is working from the commandline from your project root, you should be able to start Wallaby using Automatic Configuration
on your project root and everything will work for you.
I'll close the issue out as this should solve your problem but if you run into problems, let us know and we'll re-open.
Hi @smcenlly thanks for the quick response.
I saw failed tests become like
Failed to read HOST.
at api/src/reliability/utils/createCircuitBreaker.test.ts:1:1
Failed to read HOST.
at api/src/security/middlewares/corsMiddleware.test.ts:1:1
Failed to read HOST.
at api/src/security/middlewares/helmetMiddleware.test.ts:1:1
Unexpected token '.'
at Object.<anonymous> web/src/shared/components/Image.test.tsx:3:1
Failed to read HOST.
at api/src/shared/utils/isDevelopment.test.ts:1:1
Failed to read HOST.
at api/src/shared/utils/isProduction.test.ts:1:1
Unexpected token '.'
at Object.<anonymous> web/src/App/components/App.test.tsx:3:1
Unexpected token '.'
at Object.<anonymous> web/src/App/components/Copyright.test.tsx:3:1
Unexpected token '<'
at Object.<anonymous> web/src/App/components/Footer.test.tsx:3:1
It seems having two kinds of issues:
tsx
files in /web
(create-react-app app).Failed to read HOST
in /api
(Node.js app), I think it is because I am using dotenv-flow. To load .env.test
, I need pass NODE_ENV=test
for Node.js.For second issue, I then tried to add
module.exports = function (wallaby) {
process.env.NODE_ENV = 'test';
return {
autoDetect: true,
};
};
and use custom config file like
However, it still gives exact same error. Any idea? Thanks
Can you please confirm that you have first ensured that npx jest
is working outside of Wallaby from your project root?
This is the first step that you need to take and is unrelated to Wallaby. For Wallaby to run your tests for your entire repo, Jest also has to be able to run your tests.
Oh I got same errors when I run npx jest
directly in the root folder.
However, if I run npx jest
individually in each folder, it gives me results:
/api
(Node.js app): succeed
https://github.com/Hongbo-Miao/hongbomiao.com/blob/main/api/package.json#L17
"test": "jest",
/mobile
(React Native app): succeed
https://github.com/Hongbo-Miao/hongbomiao.com/blob/main/mobile/package.json#L15
"test": "jest",
/web
(create-react-app app): failed
https://github.com/Hongbo-Miao/hongbomiao.com/blob/main/web/package.json#L15
"test": "react-scripts test --watchAll=false",
Copy from previous comment: currently when I run Wallaby, I have errors from /web
and /api
:
Failed to read HOST.
at api/src/reliability/utils/createCircuitBreaker.test.ts:1:1
Failed to read HOST.
at api/src/security/middlewares/corsMiddleware.test.ts:1:1
Failed to read HOST.
at api/src/security/middlewares/helmetMiddleware.test.ts:1:1
Unexpected token '.'
at Object.<anonymous> web/src/shared/components/Image.test.tsx:3:1
Failed to read HOST.
at api/src/shared/utils/isDevelopment.test.ts:1:1
Failed to read HOST.
at api/src/shared/utils/isProduction.test.ts:1:1
Unexpected token '.'
at Object.<anonymous> web/src/App/components/App.test.tsx:3:1
Unexpected token '.'
at Object.<anonymous> web/src/App/components/Copyright.test.tsx:3:1
Unexpected token '<'
at Object.<anonymous> web/src/App/components/Footer.test.tsx:3:1
Here are two following issues:
/web
(create-react-app app), the test script is special (react-scripts test --watchAll=false
), which kind of making sense to fail in Wallaby. Maybe I need some custom config for Wallaby?npx jest
directly in /api
, it does succeed, however, this fails in Wallaby with automatic config.The latest try is at https://github.com/Hongbo-Miao/hongbomiao.com/pull/2370
Will keep trying.
For /web (create-react-app app), the test script is special (react-scripts test --watchAll=false), which kind of making sense to fail in Wallaby. Maybe I need some custom config for Wallaby?
If running from a mono-repo, in order to make jest run from the command line for your mono-repo, you will need to have a jest.config for your react project. I'm not entirely sure how to do this without ejecting but you may find some advice on google, etc.
If I run npx jest directly in /api, it does succeed, however, this fails in Wallaby with automatic config.
Wallaby will also work for you if you run it directly on API. Please see the settings from the screenshot below to run on the API folder only. Configuration Type: Automatic
, Root Path: <api folder>
.
The key to getting this working is to get jest running from the CLI from your mono-repo root (completely separate to Wallaby). Then Wallaby will work for you too.
Thanks @smcenlly I will report back for what I found once I succeed! Close for now.
First just want to say this tool is soooooo awesome! Thanks!
Issue description or question
My repo is at https://github.com/Hongbo-Miao/hongbomiao.com
It is a mono repo.
api
- Node.js appweb
- create-react-app appmobile
- react native appI am trying to use Wallaby in
api
which is a Node.js app first.First try
My first try is at https://github.com/Hongbo-Miao/hongbomiao.com/pull/2370 it gives me error like
I am using dotenv-flow for my
api
app, however, I setprocess.env.NODE_ENV = 'test';
in the beginning ofwallaby.conf.js
already.Second try
My second try is at https://github.com/Hongbo-Miao/hongbomiao.com/tree/wallaby-api
I am moving
wallaby.conf.js
under/api
folder, however, this won't let me use the open source license any more, so I am using a trial license.But still it gives me same error.
How should I setup Wallaby for a mono repo? Thanks
Another question, should I only use one
wallaby.js
in the root folder? But then how can I give different settings for each app inside of each sub folder.Any guide will be great. Thanks!
To reproduce, you can clone the repo and setup by
npm run setup
. To testapi
, you can can docd api && npm run test
.Wallaby diagnostics report
Click to here expand Wallaby diagnostics report!
```js { editorVersion: 'IntelliJ IDEA 2021.1.1', pluginVersion: '1.0.216', editorType: 'IntelliJ', osVersion: 'darwin 20.3.0', nodeVersion: 'v14.16.0', coreVersion: '1.0.1067', checksum: 'YWQ5NDViZDYxYTg5NDRiOTRjNzFmNmVjYTRiMGJkYWUsMTYyMTkwMDgwMDAwMCwx', config: { files: [ { pattern: 'api/src/**/*.ts', ignore: false, trigger: true, load: true, instrument: true, order: 1 }, { pattern: 'api/src/**/*.test.ts', ignore: true, trigger: true, load: true, instrument: true } ], tests: [ { pattern: 'api/src/**/*.test.ts', ignore: false, trigger: true, load: true, test: true, order: 2 } ], env: { type: 'node', params: {}, runner: '