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

[FR]: Add support for --test_filter flag #196

Open
gregmagolan opened this issue Nov 10, 2023 · 3 comments
Open

[FR]: Add support for --test_filter flag #196

gregmagolan opened this issue Nov 10, 2023 · 3 comments
Labels
enhancement New feature or request untriaged Requires traige

Comments

@gregmagolan
Copy link
Member

gregmagolan commented Nov 10, 2023

What is the current behavior?

Not supported

Describe the feature

When --test_filter is set, Bazel will encode its value in the TESTBRIDGE_TEST_ONLY environment variable (see Test Encyclopedia). rules_jest should read this value if it is set and filter test specs accordingly.

@gregmagolan gregmagolan added the enhancement New feature or request label Nov 10, 2023
@github-actions github-actions bot added the untriaged Requires traige label Nov 10, 2023
@Wenqer
Copy link

Wenqer commented Nov 12, 2023

A possible solution is to pass into https://jestjs.io/docs/cli#--filterfile something like:

const jestTestFilter: Filter = async testPaths => {
  if ('TESTBRIDGE_TEST_ONLY' in process.env) {
    const issuesFilterRegexp = new RegExp(process.env.TESTBRIDGE_TEST_ONLY!)
    const filteringFunction = (testPath: string) => issuesFilterRegexp.test(testPath)

    const allowedPaths = testPaths.filter(filteringFunction).map(test => ({
      test,
      message: `This test suite was selected by value --test_filter=${process.env.TESTBRIDGE_TEST_ONLY}`
    }))

    return {
      filtered: allowedPaths
    }
  } else {
    return {
      filtered: testPaths.map(test => ({ test }))
    }
  }
}

module.exports = jestTestFilter

// taken from @jest/core
type Filter = ( testPaths: Array<string> ) => Promise<{ filtered: Array<FilterResult> }>

type FilterResult = {
  test: string
  message?: string
}

However, we should not enable sharding when --test_filter= is used. Is it possible to set shard_count to zero when --test_filter contains a non-default value? Or the only way to go is always to pass --test_sharding_strategy=disabled?

@jbedard
Copy link
Member

jbedard commented Nov 28, 2023

@Wenqer what was the reason for not using sharding when tests are filtered?

@Wenqer
Copy link

Wenqer commented Dec 5, 2023

@jbedard Specifying the test filter usually means that we will execute much fewer suite files. In most situations, it is used to test only a single suite, and in such cases, all other shards will return exit code 1 because spawned with an empty suites list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request untriaged Requires traige
Projects
Status: No status
Development

No branches or pull requests

3 participants