Skip to content

fix(cli): apply duration, parallel, repoRef and forceRebuild from config - #163

Open
NopeCharon wants to merge 1 commit into
expressjs:mainfrom
NopeCharon:fix/config-file-options
Open

NopeCharon wants to merge 1 commit into
expressjs:mainfrom
NopeCharon:fix/config-file-options

Conversation

@NopeCharon

Copy link
Copy Markdown

Closes #162

Problem

Some expf load options set in expf.config.json or a --config file are silently replaced:

  • duration: duration: 60 was spread after ...conf.
  • repoRef / forceRebuild: bin/expf.mjs always sets these keys, to undefined when the flag isn't passed, and ..._opts then overwrites the config values.
  • parallel: default: false in parseArgs always overrides the config.

For example, { "parallel": true, "duration": 2 } still ran a 60 second test against only the first request.

Changes

  • packages/cli/load.mjs: options are applied in the order defaults (including duration: 60), then config, then flags. Flags that are undefined are dropped first, so a flag that wasn't passed no longer hides the config value. Flags passed on the command line still take precedence.
  • packages/cli/bin/expf.mjs: removed default: false from --parallel. An unset value is still falsy, which is all @expressjs/perf-requests checks for. load.yml passes --parallel explicitly, so CI behaves the same.
  • README.md: the options table described --config as a "JSON string with package overrides". It now describes it as a path to a JSON config file and adds the missing --[no-]parallel row. A short "Configuration File" section explains keys, lookup and precedence.

Testing

  • New tests in packages/cli/test/load.test.mjs use a fixture config and a mock runner that echoes the options it receives. They cover config values passing through when the flags are undefined, flags overriding the config, and the 60 second default. The config test fails on main. npm test in packages/cli passes (5 tests) on Node 24.
  • End to end with the real local runner, using a config of { "parallel": true, "duration": 2, ... }:
    • On main, it printed "Using only the first request from the test set" and was still running after 15 seconds.
    • With this change, it finished in about 5 seconds with four 2-second results (/, /foo, /bar, /bar/baz/).

This PR and #161 both touch load.mjs (in different hunks) and both append tests to load.test.mjs. I'll rebase whichever one merges second.

Several options set in `expf.config.json` (or a file passed with
`--config`) were silently replaced:

- `duration`: the hard-coded `duration: 60` default was spread after
  the config, so a configured duration always became 60.
- `repoRef` / `forceRebuild`: `bin/expf.mjs` always assigns the renamed
  flags, so when they weren't passed the keys held `undefined`, and
  spreading `_opts` overwrote the configured values.
- `parallel`: the option was declared with `default: false`, so
  `parallel: false` was always passed and overrode the config.

`load.mjs` now applies options in the order defaults, then config, then
flags, and drops flags whose value is `undefined` (i.e. not passed).
The `default: false` is removed from `--parallel`. An unset value is
still falsy, which is all `@expressjs/perf-requests` checks for. Flags
passed on the command line still take precedence over the config, and
`duration` still defaults to 60.

The README options table described `--config` as a "JSON string with
package overrides". It now describes it as a path to a JSON config
file, adds the missing `--[no-]parallel` row, and gets a short section
on how the config file works.

Tests cover config values reaching the runner when the flags are
undefined, flags overriding the config, and the 60 second default
duration. The mock runner now echoes the relevant options.

Closes expressjs#162

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

expf load ignores duration, parallel, repoRef and forceRebuild from the config file

1 participant