Closed dimtim closed 4 years ago
When using automatic configuration to run your project's tests, Wallaby will perform the same logic as if you were running jest from the command-line using npx jest
. Right now, when you run your project's tests using npm test
, lerna
is actually running your tests for you on each individual project. In contrast, Wallaby runs on your entire project (e.g. entire mono-repo). The context for running your tests is therefore a little different with the current working directory being your mono-repo root with Wallaby and the current working directory being your package project root with lerna.
We took a look at the apollo-universal-starter-kit stable branch. We ran into a few problems with tests not passing from the command-line (using yarn test
), but were not sure if this was a problem because we were using Windows, or there are other problems in the default stable branch that need to be fixed. We did make some progress towards getting this working but got stuck with graphql/apollo-starter specific problems that we are not familiar with solving.
Unfortunately we do not have an example configuration that we can provide to you for the apollo starter kit. To get Wallaby working with the apollo-universal-starter-kit
we recommend first getting jest
working from the root of the mono-repo in watch mode using npx jest --watch
. You will need to create a jest.config.js
file in the project root, similar to:
mono-repo root jest.config.js
module.exports = ({
"projects": [
"packages/*"
]
})
After configuring the root config, we ran into some other problems because the jest configuration for each package (e.g. packages\server\jest.config.js
) is assuming that the current working directory is the package directory (e.g. packages\server
) while running from the root, jest's current working directory is your mono-repo root. We needed to update your jest.config.js
babel transform to fix this:
package jest.config.js transform change
transform: {
'\\.(gql|graphql)$': 'jest-transform-graphql',
'locales[\\/]index.[jt]s': '<rootDir>/jest-transform-i18next',
- '.*': 'babel-jest'
+ '.*': ['babel-jest', { root: __dirname }]
},
After making this change, we ran into some other problems related to apollo-universal-starter-kit
that we weren't exactly sure how to solve that are related to how graphql is being used by jest (please note that none of these problems were related to Wallaby itself). We then got an error running tests using npx jest
from the project root. Unfortunately this is as far as we got as we simply aren't familiar enough with graphql or what the apollo starter kit is doing.
Network error: request to http://localhost/:undefined/graphql failed, reason: connect ECONNREFUSED 127.0.0.1:80
at new ApolloError (node_modules/apollo-client/bundle.umd.js:92:26)
at node_modules/apollo-client/bundle.umd.js:1587:34
at node_modules/apollo-client/bundle.umd.js:2007:15
at Set.forEach (<anonymous>)
at node_modules/apollo-client/bundle.umd.js:2005:26
at Map.forEach (<anonymous>)
at QueryManager.broadcastQueries (node_modules/apollo-client/bundle.umd.js:2003:20)
at node_modules/apollo-client/bundle.umd.js:1482:29
One more point to note (and it may have been related to our attempts to change configuration and get everything running) was that the tests seemed brittle/fragile and would sometimes fail for other reasons (network issues, port already in use, etc.). Sometimes such issues are caused by your tests/test framework expecting the process to be terminated after your tests execute while by default, Wallaby re-uses processes to decrease test times. If you run into these problems, you may configure Wallaby to use a single process, and to recycle the process between each test run. You may add Wallaby workers configuration to your package.json
in your project root to fix this:
...
"wallaby": {
"workers": {
"initial": 1,
"regular": 1,
"restart": true,
}
}
...
If you are able to resolve these problems using jest from the command-line then Wallaby should also work for you.
If/when you get npx jest
working from the command-line, if you have problems with wallaby, please let us know and we can re-open this issue or else you may create a new issue.
Issue description or question
I'm trying to use Wallaby.js in project based on Apollo Universal Starter Kit but get errors with automatic configuration. Can you please suggest configuration file that can be used with this project.
Wallaby diagnostics report