-
Notifications
You must be signed in to change notification settings - Fork 73
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
New API #76
Conversation
Thats a nice idea! So you are just replacing the implementation for multiple browsers as far as I've seen right? |
@mxschmitt yeah! That is what I'm thinking about. it('should display "google" text on page', async () => {
const titles = await page.title()
// That is not the best way
titles.forEach(title => expect(title).toBe('What browser am I using? Is my browser up to date?'))
// It will just return result for all browsers in array
const {firefox, webkit, chrome} = await page.$eval('.string-major', el => el.innerHTML)
}) I'm trying to improve it, but not sure that it will be possible to simplify it more |
One Idea would be to force the user that he needs to make ["chromium", "firefox", "webkit"].forEach(browserName => {
const page = jestPlaywright.getBrowser(browserName)
describe(`Testing browser ${browserName}`, () => {
it("should do XYZ", async() => {
})
})
}) idk. Then reporting would also be kinda better afaik. |
Some new thoughts here. I just added helper proxy to simplify test process: describe('Google', () => {
beforeAll(async () => {
// It will navigate all browsers to url
await page.goto('https://whatismybrowser.com/');
});
it('should display "google" text on page', async () => {
const titles = await page.title();
// It will expect toBe for all browsers
// Passed tests
expectAllBrowsers(titles).toBe('What browser am I using? Is my browser up to date?')
// Failed tests
const myBrowser = await page.$eval(
'.string-major',
el => el.innerHTML,
);
expectAllBrowsers(myBrowser).toContain('Chrome')
});
}); I just think about nice error message here. For now it will be:
|
cool! let's maybe ask the users who are actually using this feature what they think about that before we merge? |
@mxschmitt yeah! I just want to support |
…/jest-playwright into New-API � Conflicts: � package-lock.json � package.json � src/PlaywrightEnvironment.ts
…into New-API � Conflicts: � package-lock.json � src/PlaywrightEnvironment.ts
…/jest-playwright into New-API � Conflicts: � src/PlaywrightEnvironment.ts
Pull Request Test Coverage Report for Build 47062a08620269e9ec26ff327fa6d35919c56745-PR-76
💛 - Coveralls |
src/PlaywrightEnvironment.ts
Outdated
@@ -1,6 +1,9 @@ | |||
/* eslint-disable no-console */ | |||
import NodeEnvironment from 'jest-environment-node' | |||
import { Config as JestConfig } from '@jest/types' | |||
import Expect = jest.Expect | |||
import playwright, { Browser, BrowserContext, Page } from 'playwright' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please import types from playwright-core
Some updates here. Just tried to use it with jest-circus runner, it is ok. But for some reason it needs to run with forceExit and detectOpenHandles options. Still working on it jest --forceExit --detectOpenHandles |
…into New-API � Conflicts: � src/PlaywrightEnvironment.ts
Some updates. I got passed tests on local machine. But got some issues with import path from 'path'
jest.setTimeout(10000)
describe('Example HTML file', () => {
it('should detect the heading "Example" on page', async () => {
await page.goto(`file:${path.join(__dirname, 'example.html')}`)
const browser = await page.$eval('h1', (el) => el.textContent)
expectAllBrowsers(browser).toBe('Example')
})
}) Also I'm thinking about adding @mxschmitt your thoughts?) |
@@ -0,0 +1,4 @@ | |||
module.exports = { | |||
USE_NEW_API: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why no camel case here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mxschmitt I think that snake style will show that it's experimental feature
src/PlaywrightEnvironment.ts
Outdated
@@ -1,16 +1,29 @@ | |||
/* eslint-disable no-console */ | |||
import NodeEnvironment from 'jest-environment-node' | |||
import { Config as JestConfig } from '@jest/types' | |||
import Expect = jest.Expect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import Expect = jest.Expect |
const getResult = <T>( | ||
data: T[], | ||
instances: BrowserType[] | Array<keyof typeof playwright.devices>, | ||
) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) => { | |
): any => { |
data: T[], | ||
instances: BrowserType[] | Array<keyof typeof playwright.devices>, | ||
) => { | ||
const result: any = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const result: any = {} | |
const result: any = {} // eslint-disable-line no-explicit-any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nits. Would be cool to clean the ESLint warnings and use pragmas for the any
cases. Then we can merge in my mind.
Yeah! I agree but it seems challenging for me) To fix whole TS warnings |
Feel free to use |
I'll close it, cause I suppose using custom jest-runner is better solution for running tests for multiple browsers support |
Thinking about rewriting jest-playwright with new API:
Using
jest-playwright --parallel
command is kind of hack, so I think about replacing it.To run tests for specified browsers in you config you should do:
jest-playwright.config.js:
In tests:
Let me know what do you think about it?