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

Create Plugin: Extend the playwright config file #1495

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

oshirohugo
Copy link
Contributor

@oshirohugo oshirohugo commented Jan 28, 2025

What this PR does / why we need it:

This PR move the existing playwright config to ./config, this will make updating the default playwright config easier.

Which issue(s) this PR fixes:

Closes #1366

Special notes for your reviewer:

The way the docs are written right now is still applicable to the new playwright config that extends the one from ./config therefore they were not modified.

@oshirohugo oshirohugo added enhancement New feature or request create-plugin related to the create-plugin tool minor Increment the minor version when merged labels Jan 28, 2025
@oshirohugo oshirohugo self-assigned this Jan 28, 2025
@oshirohugo oshirohugo requested a review from a team as a code owner January 28, 2025 16:03
@oshirohugo oshirohugo requested a review from s4kh January 28, 2025 16:03
Copy link

github-actions bot commented Jan 28, 2025

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged but will not trigger a new release. To trigger a new release add the release label before merging.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@oshirohugo oshirohugo requested review from jackw and sunker January 28, 2025 16:04
Copy link
Contributor

@sunker sunker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit sceptical to this. This will make it a little harder to overview and edit the Playwright config for plugin developers. And to my knowledge, Playwright don't offer any abstraction to merge configs (the way for example Webpack does with [https://www.npmjs.com/package/webpack-merge]).

Now that we're soon to release the new create-plugin update cmd that allows us to safely manipulate files outside the .config dir, is this really necessary? cc @jackw who initially raised this issue.

@mckn
Copy link
Collaborator

mckn commented Jan 29, 2025

I'm a bit sceptical to this. This will make it a little harder to overview and edit the Playwright config for plugin developers. And to my knowledge, Playwright don't offer any abstraction to merge configs (the way for example Webpack does with [https://www.npmjs.com/package/webpack-merge]).

Now that we're soon to release the new create-plugin update cmd that allows us to safely manipulate files outside the .config dir, is this really necessary? cc @jackw who initially raised this issue.

Merging the configs isn't a problem since playwright expects the default object exposed from that file to be the config. So you can use what ever merge util you want to merge multiple configs.

But I agree with your thoughts regarding the migrations. However, it might not be easy to migrate a file that is changed by the user. So moving the base to .config folder might be a good idea regardless. WDYT?

@jackw
Copy link
Collaborator

jackw commented Jan 30, 2025

I'm a bit sceptical to this. This will make it a little harder to overview and edit the Playwright config for plugin developers. And to my knowledge, Playwright don't offer any abstraction to merge configs (the way for example Webpack does with [https://www.npmjs.com/package/webpack-merge]).

As others have also pointed out we can rely on spreading these configs but I believe Playwright does have some concept of merging configs via defineConfig which can take multiple configs. e.g. defineConfig(defaultConfig, {});.

However, the playwright team decided that the projects property should override which would result in needing to do:

export default defineConfig(defaultConfig, {
  projects: [
    ...defaultConfig.projects!,
    {
      name: 'firefox',
      use: { ...devices['Desktop Firefox'], storageState: 'playwright/.auth/admin.json' },
      dependencies: ['auth'],
    },
  ],
});

Whilst it was originally designed for webpack, webpack-merge isn't webpack specific. You can use it for any config including playwrights:

import { merge } from 'webpack-merge';
import defaultConfig from './.config/playwright.config';

const config = merge(defaultConfig, {
  projects: [
    {
      name: 'firefox',
      use: { ...devices['Desktop Firefox'], storageState: 'playwright/.auth/admin.json' },
      dependencies: ['auth'],
    },
  ],
});

export default defineConfig(config);

Now that we're soon to release the new create-plugin update cmd that allows us to safely manipulate files outside the .config dir, is this really necessary?

Within create-plugin, we have the concept of "put default configs in .config directory and extend in files in root of project" and I opened the issue to align our playwright config with this concept. I also agree with @mckn that even with migrations it's much easier to update a file in the .config directory as we consider them ours and document in the files and in our docs website that touching them is a bad idea.

@@ -0,0 +1,53 @@
import type { PluginOptions } from '@grafana/plugin-e2e';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import type { PluginOptions } from '@grafana/plugin-e2e';
/*
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
*
* In order to extend the configuration follow the steps in
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-playwright-config
*/
import type { PluginOptions } from '@grafana/plugin-e2e';

If we decide to do this I think we should update the docs site in this PR too with instructions.

},
],

} as PlaywrightTestConfig<PluginOptions>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is necessary. I think you can export the defineConfig<PluginOptions>({}) in this file then use defineConfig again in the root.

@oshirohugo oshirohugo requested review from jackw and sunker February 3, 2025 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-plugin related to the create-plugin tool enhancement New feature or request minor Increment the minor version when merged
Projects
Status: 🔬 In review
Development

Successfully merging this pull request may close these issues.

Feat: Extend the playwright config file
4 participants