Skip to content
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

[Bug]: Fixture array parameter error #32275

Closed
mkrakker opened this issue Aug 22, 2024 · 3 comments
Closed

[Bug]: Fixture array parameter error #32275

mkrakker opened this issue Aug 22, 2024 · 3 comments

Comments

@mkrakker
Copy link

Version

1.46.1

Steps to reproduce

poc.ts:

import { expect, test as base } from '@playwright/test';

type FixtureOptions = {
  data: { foo: string, bar: string }[];
};

const testFixture = base.extend<FixtureOptions>({
  data: [[], { option: false }],
  page: async ({ page, data }, use) => {
    if (!data || !data.length) {
      // data is just { "foo": "foo", "bar": "bar" } instead of an array at this point
      throw new Error(':(');
    }

    await use(page);
  }
});

testFixture.describe('POC', () => {
  testFixture.use({
    data: [
      { foo: 'foo', bar: 'bar'},
      { foo: 'bar', bar: 'foo'}
    ]
  });

  testFixture('Should pass', async ({ page }) => {
    expect(true).toBeTruthy();
  });
});

playwright.config.ts:

import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
  testDir: './tests',
  fullyParallel: false,
  forbidOnly: !!process.env.CI,
  retries: 0,
  workers: 1,
  reporter: 'html',
  use: {
    trace: 'on',
  },

  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    }
  ],
});

Expected behavior

The test passes, as the passed data fixture parameter is an array

Actual behavior

The test fails in the fixture o nthe parameter validation, as data has no length property - in fact it is the first element of the array passed in in use

Additional context

Works fine with 1.45.3

Environment

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 13th Gen Intel(R) Core(TM) i5-1335U
    Memory: 17.32 GB / 31.69 GB
  Binaries:
    Node: 20.12.2 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.14.0 - ~\AppData\Roaming\npm\pnpm.CMD
  IDEs:
    VSCode: 1.92.2 - C:\Program Files\Microsoft VS Code\bin\code.CMD
  Languages:
    Bash: 5.1.16 - C:\Windows\system32\bash.EXE
  npmPackages:
    @playwright/test: 1.46.1 => 1.46.1
    playwright: 1.46.1 => 1.46.1
@Skn0tt
Copy link
Member

Skn0tt commented Aug 23, 2024

Hi there! Passing an array is a common footgun that others have seen before - #32033 is a similar report. We added a note about this to the docs just yesterday, so they're not yet live. But you can take a look here: https://github.com/microsoft/playwright/pull/32261/files#diff-39680f5caa0a24f2a0eaa7c7313f170b4e2d2e15d451d4d47f026bfea933b57fR554

Let me know if that solves it for you!

@mkrakker
Copy link
Author

Hi @Skn0tt ! Indeed wrapping the input array in another array is a feasible workaround, I can confirm this. (also wrapping the array in an object seems to work just fine)
Thanks a lot :)

@Skn0tt Skn0tt closed this as completed Aug 23, 2024
@MindaugasMateika
Copy link
Contributor

Hi there! Passing an array is a common footgun that others have seen before - #32033 is a similar report. We added a note about this to the docs just yesterday, so they're not yet live. But you can take a look here: https://github.com/microsoft/playwright/pull/32261/files#diff-39680f5caa0a24f2a0eaa7c7313f170b4e2d2e15d451d4d47f026bfea933b57fR554

Let me know if that solves it for you!

Hi there! Passing an array is a common footgun that others have seen before - #32033 is a similar report. We added a note about this to the docs just yesterday, so they're not yet live. But you can take a look here: https://github.com/microsoft/playwright/pull/32261/files#diff-39680f5caa0a24f2a0eaa7c7313f170b4e2d2e15d451d4d47f026bfea933b57fR554

Let me know if that solves it for you!

Why it was not listed as a breaking change anywhere in the release notes? I'm upgrading from 1.45 to 1.48.2 and spent like half a day figuring out why TypeError: someOptionArray is not iterable error and why array option is suddenly an object.

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

No branches or pull requests

3 participants