From 3e8fc94d43b375619130d16f5e63deb9e70bb526 Mon Sep 17 00:00:00 2001 From: Jamie Rolfs Date: Thu, 22 Sep 2022 15:01:08 -0700 Subject: [PATCH 1/2] ci(actions): remove Node 12 and add Node 18 to the matrix Playwright dropped support for Node 12 in a non-breaking release, but it's leaving LTS soon anyways. --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6050de1..7fb6b4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: ['12', '14', '16'] + node: ['14', '16', '18'] # TODO: technically we still support down to 1.12 but `locator.waitFor` # was introduced in 1.16 so anything earlier blows up type-checking. # This minimum will be bumped in the next breaking release that will be @@ -68,7 +68,7 @@ jobs: npm why @playwright/test npm run test:legacy - # Only release on Node 14 + # Only release on Node 16 - name: Upload Coverage / Release / Playwright run: npm run ci-after-success @@ -99,13 +99,13 @@ jobs: run: echo ::set-output name=branch::${GITHUB_REF#refs/*/} - name: Release / Playwright Test (latest) - if: ${{ matrix.node == '14' && matrix.playwright == 'latest' && steps.did-release.outputs.released == 'true' && steps.branch.outputs.branch == 'main' }} + if: ${{ matrix.node == '16' && matrix.playwright == 'latest' && steps.did-release.outputs.released == 'true' && steps.branch.outputs.branch == 'main' }} run: | npm run prepare:playwright-test npm publish --access=public - name: Release / Playwright Test (pre-release) - if: ${{ matrix.node == '14' && matrix.playwright == 'latest' && steps.did-release.outputs.released == 'true' && steps.branch.outputs.branch != 'main' }} + if: ${{ matrix.node == '16' && matrix.playwright == 'latest' && steps.did-release.outputs.released == 'true' && steps.branch.outputs.branch != 'main' }} run: | npm run prepare:playwright-test npm publish --access=public --tag=${{ steps.branch.outputs.branch }} From 480ce66fa91149d80b2839bb7d93ba55a928d09f Mon Sep 17 00:00:00 2001 From: Jamie Rolfs Date: Wed, 21 Sep 2022 18:50:00 -0700 Subject: [PATCH 2/2] fix(fixture): support function `TextMatch` argument in queries --- lib/fixture/helpers.ts | 6 ++++++ test/fixture/locators.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/fixture/helpers.ts b/lib/fixture/helpers.ts index cd4fef4..ec2571d 100644 --- a/lib/fixture/helpers.ts +++ b/lib/fixture/helpers.ts @@ -1,5 +1,6 @@ const replacer = (_: string, value: unknown) => { if (value instanceof RegExp) return `__REGEXP ${value.toString()}` + if (typeof value === 'function') return `__FUNCTION ${value.toString()}` return value } @@ -11,6 +12,11 @@ const reviver = (_: string, value: string) => { return new RegExp(match![1], match![2] || '') } + if (value.toString().includes('__FUNCTION ')) { + // eslint-disable-next-line @typescript-eslint/no-implied-eval + return new Function(`return (${value.split('__FUNCTION ')[1]}).apply(this, arguments)`) + } + return value } diff --git a/test/fixture/locators.test.ts b/test/fixture/locators.test.ts index 1076774..edb88bd 100644 --- a/test/fixture/locators.test.ts +++ b/test/fixture/locators.test.ts @@ -40,6 +40,28 @@ test.describe('lib/fixture.ts (locators)', () => { expect(await locator.textContent()).toEqual('Hello h1') }) + test('supports function style `TextMatch`', async ({screen}) => { + const locator = screen.getByText( + // eslint-disable-next-line prefer-arrow-callback, func-names + function (content, element) { + return content.startsWith('Hello') && element?.tagName.toLowerCase() === 'h3' + }, + ) + + expect(locator).toBeTruthy() + expect(await locator.textContent()).toEqual('Hello h3') + }) + + test('supports arrow function style `TextMatch`', async ({screen}) => { + const locator = screen.getByText( + (content, element) => + content.startsWith('Hello') && element?.tagName.toLowerCase() === 'h3', + ) + + expect(locator).toBeTruthy() + expect(await locator.textContent()).toEqual('Hello h3') + }) + test('should handle the get* methods', async ({queries: {getByTestId}}) => { const locator = getByTestId('testid-text-input')