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

fix(browser): fix testNamePattern config #4909

Merged
merged 2 commits into from
Jan 9, 2024

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Jan 9, 2024

Description

I added a quick workaround similar to child/forks pool, such as:

function parsePossibleRegexp(str: string | RegExp) {
const prefix = '$$vitest:'
if (typeof str === 'string' && str.startsWith(prefix))
return parseRegexp(str.slice(prefix.length))
return str
}
function unwrapConfig(config: ResolvedConfig) {
if (config.testNamePattern)
config.testNamePattern = parsePossibleRegexp(config.testNamePattern) as RegExp
return config
}

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Sorry, something went wrong.

Copy link

netlify bot commented Jan 9, 2024

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit a9d11fd
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/659cad6b5a400100089cdfb4

@hi-ogawa hi-ogawa force-pushed the fix-browser-testNamePattern branch from 8842faa to 76b6195 Compare January 9, 2024 01:54

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Comment on lines +117 to +118
if (vitestOrWorkspace instanceof WorkspaceProject)
return wrapConfig(vitestOrWorkspace.getSerializableConfig())
Copy link
Contributor Author

@hi-ogawa hi-ogawa Jan 9, 2024

Choose a reason for hiding this comment

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

For now, I added this only for browser mode testing but not for vitest ui client since vitest ui doesn't seem to make use of testNamePattern.

Alternatively, we could fix this in serialization layer, but it didn't feel appropriate to put this custom logic in @vitest/ws-client unless maybe changing serialization library entirely to cover RegExp, Error, etc... so that there's no need for custom logic.

serialize: stringify,
deserialize: parse,

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@hi-ogawa hi-ogawa marked this pull request as ready for review January 9, 2024 02:34
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.

Browser mode does not take --testNamePattern into account.
2 participants