Skip to content

Add test runner configuration #48852

Closed as not planned
Closed as not planned
@remcohaszing

Description

@remcohaszing

What is the problem this feature will solve?

Currently the test runner can be configured using command line arguments and / or a custom script that calls run(). These commands can get long, making them hard to read. For example:

{
  "scripts": {
    "test": "c8 node --test --test-reporter @reporters/junit --test-reporter-destination=junit.xml --test-reporter spec --test-reporter-destination stdout"
  }
}

What is the feature you are proposing to solve the problem?

I propose to add the key test to package.json. Running node --test will read this key and merge the configuration with other configuration options. The test key accepts the same options as run(), plus the reporters field, which is a key-value pair of reporters and their output file.

The above example, could be changed to:

{
  "scripts": {
    "test": "c8 node --test"
  },
  "test": {
    "reporters": {
      "@reporters/junit": "junit.xml",
      "spec": "stdout"
    }
  }
}

This makes it nicer to work with TypeScript interpreters. (Refs privatenumber/tsx#257.) For example:

{
  "scripts": {
    "test": "c8 tsx --test"
  },
  "test": {
    "testNamePatterns": "test/*.ts"
    "reporters": {
      "@reporters/junit": "junit.xml",
      "spec": "stdout"
    }
  }
}

The test field can also be defined using a JSON schema (outside of Node.js), so editors get validation and completion.

What alternatives have you considered?

It could be defined in a separate file. I think a key in package.json makes sense though, because it’s already used to configure Node.js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions