Skip to content

[test-runner] Ability to set query parameters #613

Open
@aomarks

Description

@aomarks

We'd like to be able to use one invocation of wtr to run the same test files multiple times, with some sort of different configuration each time.

Example use cases:

  • Run a test file once with some native feature enabled, and then again with a polyfill force-enabled.
  • Run a test file once with some named module resolving to our development build, and then again with it resolving to our minified build.

Currently we just launch two invocations of wtr to do this, with a different set of plugins. This works fine, but it would be nice during development to be able to run a single --watch command that covers all of our test variations, and also it would improve our CI latency (especially when using Sauce), if we could do it with one invocation.

Two possibilities come to mind as a starting point:

  • A way to specify URL parameters on the file specification/glob, which are passed through to the URL that gets served. This would let us include some JS in the test files that can check this parameter and e.g. conditionally loads a polyfill before the tests.

    files: [
      "tests/**/*.test.js?polyfill=true",
      "tests/**/*.test.js?polyfill=false",
    ],
  • A way to specify sub-suites, with different sets of plugins.

    suites: [
      {
        files: ["tests/**/*test.js"],
        plugins: [resolveLitModulesToDevBuild()],
      },
      {
        files: ["tests/**/*test.js"],
        plugins: [resolveLitModulesToProdBuild()],
      }
    ]

Since a plugin can read URL query parameters, and since a plugin can inject JS, I think you should technically be able to achieve any result with either of these approaches. Though, the query parameter approach seems more natural when you want to toggle some behavior in the test JS, and the plugin approach seems more natural when you want to e.g. rewrite imports -- so maybe both have their place?

Edit: Actually I don't think the URL parameter approach alone can satisfy all use cases, since in order for a plugin to understand the context its executing in, that URL parameter would need to be propagated to the entire module dependency tree. So I think both approaches here, or something like them, may be needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions