Skip to content

feat(test runner): improve fixture typings for function fixtures#9138

Merged
dgozman merged 1 commit into
microsoft:masterfrom
dgozman:function-fixture-types
Sep 25, 2021
Merged

feat(test runner): improve fixture typings for function fixtures#9138
dgozman merged 1 commit into
microsoft:masterfrom
dgozman:function-fixture-types

Conversation

@dgozman
Copy link
Copy Markdown
Collaborator

@dgozman dgozman commented Sep 24, 2021

When fixture value R is a function, TypeScript sometimes confuses function R and function async ({}, use) => {}. This leads to any types in the latter because it could be either of the functions as TS thinks.

The solution is to only accept the second syntax, assuming that noone passes fixture value that is a function as is:

// This will stop working.
test.extend<{ foo: (x: number) => number }>({
  foo: x => 2 * x,
});

// This will get inferred types and autocomplete.
test.extend<{ foo: (x: number) => number }>({
  foo: async ({}, use) => {
    await use(x => 2 * x);
  },
});

Fixes #9116.

When fixture value `R` is a function, TypeScript sometimes confuses
function `R` and function `async ({}, use) => {}`. This leads to
`any` types in the latter because it could be either of the functions
as TS thinks.

The solution is to only accept the second syntax, assuming that noone
passes fixture value that is a function as is:

```js
// This will stop working.
test.extend<{ foo: (x: number) => number }>({
  foo: x => 2 * x,
});

// This will get inferred types and autocomplete.
test.extend<{ foo: (x: number) => number }>({
  foo: async ({}, use) => {
    await use(x => 2 * x);
  },
});
```
@dgozman dgozman merged commit d22dd4a into microsoft:master Sep 25, 2021
sidharthv96 added a commit to sidharthv96/playwright that referenced this pull request Sep 28, 2021
* upstream/master: (26 commits)
  browser(webkit): disable COOP support (microsoft#9185)
  fix(test runner): proper serial mode with beforeAll/afterAll failures (microsoft#9183)
  chore: remove browserType.connect from .net - not yet ready (microsoft#9182)
  test: canvas updates are reflected on screenshots (microsoft#9180)
  chore: dedupe return types in the dotnet api generator (microsoft#9181)
  docs: mention empty string in `userDataDir` (microsoft#9069)
  feat(expect): toContainText(array) (microsoft#9160)
  chore: enable object-curly-spacing in ESLint (microsoft#9168)
  feat(chromium): roll to r925110 (microsoft#9175)
  chore: render expect in trace viewer (microsoft#9141)
  devops: use Node.js 16 when rolling browsers
  docs(python): add docs about threading (microsoft#8829)
  browser(chromium): roll to r925110 (microsoft#9171)
  chore(test-runner): launch -> webServer (microsoft#9167)
  docs: cleanup test.describe.parallel.only doc (microsoft#9159)
  chore: remove FatalDOMError (microsoft#9119)
  feat(test runner): improve fixture typings for function fixtures (microsoft#9138)
  fix(expect): produce "waiting for selector" log, corner cases (microsoft#9140)
  fix: increase recent logs buffer (microsoft#9143)
  test: unflake a few tests (microsoft#9142)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Second worker fixture has no auto-completion

2 participants