Skip to content

Commit

Permalink
chore(readme): add react-scripts fix to readme (#416)
Browse files Browse the repository at this point in the history
* add typescript import fix to readme

* Update README.md

Co-authored-by: Tony Brix <tony@brix.ninja>

* Update README.md

Co-authored-by: Tony Brix <tony@brix.ninja>

* Update README.md

Co-authored-by: Raptoria <tina.lacey@gatech.edu>
Co-authored-by: Tony Brix <tony@brix.ninja>
  • Loading branch information
3 people committed Jun 4, 2021
1 parent a893edf commit 5888cef
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ describe('Google', () => {
})
```

If you are using `react-scripts`, you will need to pass the environment via command line:

```js
"test": "react-scripts test --env=puppeteer",
```

or alternatively include the following comment at the top of each test file:

```js
/**
* @jest-environment puppeteer
*/
```

### Running puppeteer in CI environments

Most continuous integration platforms limit the number of threads one can use. If you have more than one test suite running puppeteer chances are that your test will timeout. This is because jest will try to run puppeteer in parallel and the CI platform won't be able to handle all the parallel jobs in time. A fix to this is to run your test serially when in a CI environment. Users have discovered that [running test serially in such environments can render up to 50%](https://jestjs.io/docs/en/troubleshooting#tests-are-extremely-slow-on-docker-and-or-continuous-integration-ci-server) of performance gains.
Expand Down Expand Up @@ -203,6 +217,52 @@ module.exports = {
}
```

You may want to consider using multiple projects in Jest since setting your own `setupFilesAfterEnv` and `globalSetup` can cause globals to be undefined.

```js
module.exports = {
projects: [
{
displayName: 'integration',
preset: 'jest-puppeteer',
transform: {
'\\.tsx?$': 'babel-jest',
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub'
},
moduleNameMapper: {
'^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub'
},
modulePathIgnorePatterns: ['.next'],
testMatch: [
'<rootDir>/src/**/__integration__/**/*.test.ts',
'<rootDir>/src/**/__integration__/**/*.test.tsx'
]
},
{
displayName: 'unit',
transform: {
'\\.tsx?$': 'babel-jest',
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub'
},
moduleNameMapper: {
'^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub'
},
globalSetup: '<rootDir>/setupEnv.ts',
setupFilesAfterEnv: ['<rootDir>/setupTests.ts'],
modulePathIgnorePatterns: ['.next'],
testMatch: [
'<rootDir>/src/**/__tests_/**/*.test.ts',
'<rootDir>/src/**/__tests__/**/*.test.tsx'
]
}
]
};
```

### Extend `PuppeteerEnvironment`

Sometimes you want to use your own environment, to do that you can extend `PuppeteerEnvironment`.
Expand Down

0 comments on commit 5888cef

Please sign in to comment.