-
Notifications
You must be signed in to change notification settings - Fork 75
Allow jest-playwright settings in jest.config.js #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jhildenbiddle thank you for your suggestion. Looks interesting and useful. Not sure that it will be easy to implement, but I take it after #216 |
Just made some research on it. Seems like that jest doesn't pass any custom values defined it your // jest.config
module.exports = {
...,
preset: "jest-playwright-preset",
globals: {
jestPlaywright: {
...
}
}
} Also IDK what we should do if we defined some options in jest.config and also in jest-playwright.config |
Interesting. I'm surprised Jest is so strict about unknown properties in the config, but I suppose it's necessary to provide the kind of warnings shown in your screenshot. I wonder if there's a way for Jest plugin/preset/etc. authors to whitelist new config properties that they want to make available in file someArrayCheckedByJest: [
'jestPlaywright',
'someOtherJestAddon'
];
``
Storing property names in an array would suppress the warnings, but it wouldn't provide any assistance to end users when needed as Jest does with its own config properties. To resolve this, a more robust implementation would allow devs to provide messages of different types, each with their own condition(s) that would determine if/when to display them:
```js
someObjectCheckedByJest: {
jestPlaywright: {
name: 'jest-playwright',
description: 'A Jest preset that simplifies running tests with Playwright',
url: 'https://github.com/playwright-community/jest-playwright',
messages: [
{
type: 'info',
message: 'Info message',
test(jestConfig) {
/* Code that returns true when condition is met */
}
},
{
type: 'warning',
message: 'Warning message',
test(jestConfig) {
/* Code that returns true when condition is met */
}
},
{
type: 'error',
message: 'Error message',
test(jestConfig) {
/* Code that returns true when condition is met */
}
}
]
},
someOtherJestAddon: {
name: 'Some other Jest Addon',
description: 'This is some other add-on for Jest',
url: 'https://github.com/username/repo',
messages: [
// ...
]
}
} If this sounds interesting, I'd be happy to file the issue / feature request in the main Jest repo.
Seems like a good workaround for now. Personally, I'd prefer to not add globals unless absolutely necessary, but this is better than nothing.
I'd do whatever Jest does when configurations are provided in both |
FWIW, if you're interested in pursuing custom properties in |
As I know there is no ability to customize config with new config properties.
I think that it has sense. Maybe core jest team can help with it.
We can wait for an answer from jest about ability to support new config properties. I suppose that I won't be able to make it this week. And there is #216 that I want to implement before this. So maybe it's better to wait for a better solution, instead of using
OK. That's reasonable to make it in Jest style.
I need to check it |
Also I found that // jest.config.js:
module.exports = {
...,
globals: {
'ts-jest': {
...,
},
},
}; |
Very interesting. I wonder if that was the guidance from the Jest team, if the TypeScript team opted to do that to make configuration data available globally, or if they were in the same "we want just use |
@mmarkelov -- What about leveraging Jest's
Perhaps I'm misunderstanding the difference between "environment" and "preset", but my understanding is that when Jest is configured with // jest.config.js
module.exports = {
preset: 'jest-playwright-preset',
testEnvironmentOptions: {
// jest-playwright options here...
browsers: [
'chromium',
'firefox',
'webkit',
]
}
}; |
@jhildenbiddle I need to check it out. I'm not sure that it will help, cause we also need to pass config to PlaywrightRunner |
@jhildenbiddle just added this ability with #282 // jest.config.js
testEnvironmentOptions: {
...,
'jest-playwright': {
...
}
}, |
@mmarkelov -- Tested and working great on v1.3.1. Much cleaner (IMHO). Thanks! |
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
While not a critical issue, allowing jest-playwright settings to live inside of the standard
jest.config.js
file would simplify the configuration (fewer config files) and make it easier to understand how Jest is configured by allowing more (hopefully, all) settings to live in one place.As a real-world example, I am currently working on an open-source project that uses
jest-playwright
for e2e tests but only Jest for unit and integration tests. You can view the work-in-progress implementation here:I'm using Jest's
projects
option to unify configurations for all test types. Because jest-playwright's config exists in a separate file that only applies to a single test type (e2e), I've movedjest-playwright.config.js
into the/tests/e2e/config/
folder, which means my Jest configuration is now split between/jest.config.js
and/tests/e2e/config/jest-playwright.config.js
. Everything works as expected, but understanding the overall test setup is more difficult for new contributors because configuration files are scattered throughout the project.Describe the solution you'd like
Allow jest-playwright settings live in
jest.config.js
using a"jest-playwright"
property name:Jest-playwright settings should also be allowed to live under a camelCase
jestPlaywright
property name. This format is consistent with Jest's property name convention:The configuration should also work for those using Jest's
projects
option. Hopefully this will "just work" because of how Jest operates, but I wanted to mention it since Jest projects provide an easy way to isolate jest-playwright to e2e tests.(Note above that I personally prefer the camelCase
jestPlaywright
property name for consistency).The text was updated successfully, but these errors were encountered: