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

none browser provider #3084

Closed
4 tasks done
Aslemammad opened this issue Mar 27, 2023 · 9 comments
Closed
4 tasks done

none browser provider #3084

Aslemammad opened this issue Mar 27, 2023 · 9 comments
Labels
enhancement New feature or request feat: browser Issues and PRs related to the browser runner

Comments

@Aslemammad
Copy link
Member

Clear and concise description of the problem

While working on landing #3079, I found out that the initial feature of the browser mode which simply is just starting a server and waiting for the user to navigate to that URL in their own browser is removed! I believe we need to have it again since it's a huge DX win and can play really well with vitest ui for the users.

Suggested solution

Having a new provider as @sheremet-va said which handles this case, I assume not so much should be gone into this browser provider and only the provider methods should be filled (for the sake of the provider)! I'd name this provider the none provider which does not open any browser for you as wd/playwright does.

Alternative

It was there before #2999.

Additional context

#3079

Validations

@Aslemammad Aslemammad added enhancement New feature or request feat: browser Issues and PRs related to the browser runner labels Mar 27, 2023
@sheremet-va
Copy link
Member

Before implementing this feature I would recommend outlining:

  • how it works
  • what does it achieve (without buzzwords)
  • who it will be useful for

I would also recommend asking other community members if we need such a feature.

@Aslemammad
Copy link
Member Author

I agree, I hope I can get back to it soon.

@Aslemammad
Copy link
Member Author

As a provider, this feature will not require any automated browser to run, unlike webdriverio or playwright provider. Instead, we only need the browser server and its URL, which is currently available, to be given to the user. Therefore, the user can simply copy the URL and open it in their own browser. I expect less work in the openPage field for this one.

This approach will result in a faster response and a better and faster Developer Experience, especially for those who have their browsers next to their IDEs. Moreover, there will be no need for any dependency, and it can work in any environment and browser, which means that the user will not be limited to the browsers provided by Playwright or Webdriverio.

I understand that some of you may be concerned about isolation issues, such as extensions that the user has on their system. However, I do not see this as an issue since Vitest has a non-safe mode flag called --no-isolate next to the safe mode --isolate. Some users, including myself, may prefer the non-safe mode sometimes because of the experience it provides.

I believe that this new feature will be very useful for users who do TDD and those who use more special browsers instead of the regular ones. Also, it has the potential to work in stackblitz, which is currently not possible with other providers. I think this feature has the potential to be explored further and be accessed globally using a server that serves the vitest browser server.

@christian-bromann
Copy link
Contributor

This sounds like a cool feature for the use case of writing unit / UI / component tests. In this case just spinning up my local browser that maybe already include some Chrome Devtools plugins can help accelerate my work writing tests. However in CI or when I want to just run the test, this would be not my default choice. So I think it should be careful documented for what purpose this should be used for and running browser tests through WebDriver should stay the default. Aside, great idea 👍

@userquin
Copy link
Member

userquin commented Apr 16, 2023

I like the idea, we only need a browser.

How about web containers? How can I test browser on StackBlizt?

On local you can run browser test with webdriverio on Chrome and them open Firefox and copy/paste the url.

@Aslemammad
Copy link
Member Author

How about web containers? How can I test browser on StackBlizt?

I believe this would be possible with the none provider.

@sheremet-va
Copy link
Member

sheremet-va commented Apr 27, 2023

There is openBrowser function in Vite, maybe we can just reuse it? This will effectively do what we did before the CI providers were implemented.

@userquin
Copy link
Member

userquin commented Jun 26, 2023

The problem with openBrowser is that we need to configure server.open = true | <url-path> before starting the dev server, if the dev server is started without previous configuration, it will not work (tested and not working): so, to make it working the none provider should be checked in the server integration for the browser to configure the open flag before starting it:

// packages/vitest/src/integrations/browser/server.ts
        enforce: 'post',
        name: 'vitest:browser:config',
        async config(config) {
          const browser: Pick<BrowserConfigOptions, 'api' | 'enabled' | 'provider'> = config.test?.browser ?? {}
          const server = resolveApiServerConfig(browser) || {
            port: defaultBrowserPort,
          }

          config.server = server
          config.server.fs ??= {}
          config.server.fs.strict = false

          if (browser.enabled === true && browser.provider === 'none')
            config.server.open = true

          return {
            resolve: {
              alias: config.test?.alias,
            },
          }
        },
      },

@bjarkihall
Copy link

Can this issue be closed since #4427 was merged?

@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feat: browser Issues and PRs related to the browser runner
Projects
None yet
5 participants