Commit Graph

22 Commits

Author SHA1 Message Date
Sebastian Poxhofer fbedd41e82 test: replace env operation with vi.stubEnv() (#45490)
* test: replace manual process.env mutation with vi.stubEnv

Enable Vitest's `unstubEnvs` so env stubs are reverted automatically
before every test, and convert the manual `process.env.X = ...` /
`delete process.env.X` pairs in specs to `vi.stubEnv()`.

This removes the hand-written `afterEach` cleanup blocks and the
`const OLD_ENV = process.env` / `process.env = { ...OLD_ENV }`
save-restore dance, which silently leaked state between tests when a
test set a variable without a matching delete.

Left as-is (incompatible with `unstubEnvs`, which unstubs before each
test, not after):
- module top-level env writes (cocoapods, gomod, post-update, pip-compile
  and bundler artifacts specs)
- `beforeAll` env writes -- the two in `util/http` moved to `beforeEach`

* test: stop asserting on ambient environment variables

Three specs asserted on values that the surrounding environment can
override, so they only passed on a machine that happened not to set them:

- `util/exec/env`: `getChildProcessEnv()` forwards every entry of
  `basicEnvVars`, but the spec only seeded a subset. Any other forwarded
  variable that was set ambiently (e.g. a lowercase `http_proxy`) leaked
  into the `toEqual` assertion. Clear all of them first.
- `util/git/index`: `process.env.GIT_SSH_COMMAND` deliberately overrides
  the default that the two env-inheritance tests assert on. Clear it.
- `logger/pretty-stdout`: the colorized level strings are built at import
  time, so the `beforeEach` setting `FORCE_COLOR` could never affect them
  -- it was dead code, and the test silently assumed a terminal without
  colour support. Derive the expectation the same way the module does.

* test(datasource/nuget): use a throwaway cache dir for nupkg downloads

The `determine source URL from nupkg` tests do not mock the filesystem,
so they really wrote downloaded packages into a fixed `/tmp/cache` path.
That fails wherever the system tmpdir is not writable, and two checkouts
running the suite at once would share the same directory.

Use `tmp.dir({ unsafeCleanup: true })` and clean it up afterwards, which
is the pattern the other specs that touch disk already use.

* feat(lint): add renovate/prefer-stub-env rule

Enforces in specs what the migration to `vi.stubEnv` established:

- assigning to or deleting `process.env.X` inside `beforeEach`, `afterEach`,
  `it` or `test` is reported, with a fixer that rewrites it to `vi.stubEnv()`
- module scope, `describe` bodies and `beforeAll` / `afterAll` are left alone:
  `unstubEnvs` reverts stubs *before* each test, so a stub created there is
  gone by the time the first test runs, and those must keep assigning directly
- replacing the `process.env` object is reported everywhere and never fixed.
  `vi.stubEnv()` captures the original object when the worker starts, so after
  a reassignment its deletes silently target the old object

The rule found 28 further violations in specs the earlier sweep missed, since
that one was anchored on `delete process.env`. Twelve were auto-fixed; the
rest replaced `process.env` wholesale and are now `clearEnv()` from test/util.

`util/exec/index.spec.ts` opts out with a comment: it asserts on the whole
child env, and `vi.stubEnv()` cannot express that because it maps `PROD`,
`DEV` and `SSR` onto '' instead of deleting them.
2026-08-28 09:26:20 +00:00
Jamie Tanna e456197add fix(logger): only truncate metaFields when they're string values (#45478)
When certain meta fields are logged, we pull them out of the meta fields
and into the log line, such as:

    DEBUG: Branch is not pending, removing pending upgrades (branch="renovate/express-4.x")

However, this also would affect non-string values such as:

    DEBUG: Git operations statistics (branch="[object Object]")

This only affects the "pretty" logs, but would mean no `branch` metadata
appears.

Instead, we can only include them when they're a string.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-08-26 12:13:22 +00:00
Jamie Tanna 4c8a1bd59d refactor(logger): remove unused dependencies as a stringified metaField (#45477)
As part of future changes, we need to correct the stringification logic
when `branch` is an object.

While looking at this, we noticed that `dependencies` is - likely - an
array of items being handled by `.toString()`ing them.

However, there's no existing cases in the codebase of this behaviour, so
we can remove it from `metaFields`.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-08-26 12:13:22 +00:00
Jamie Tanna 1d489438f8 test(logger): add coverage of current metaFields stringifying behaviour (#45476)
As part of future changes, we need to correct the stringification logic
when `branch` is an object.

Before we do this, we can make sure we have full coverage of the
existing behaviour.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-08-26 12:13:21 +00:00
Sebastian Poxhofer 0793274b86 refactor: prefer templates rather than + in test files (#43441)
refactor: prefer templates rather than `+`
2026-05-19 09:52:28 +00:00
Felipe Santos cec112a2eb fix(log): last log lines of config-validator not being written to file (#43052)
* fix(log): last log lines of config-validator not being written to file

* Use simpler write

* Simplify RenovateStream now that it only writes to stdout

* Rename RenovateStream to PrettyStdoutStream

* Simplify comment
2026-05-04 16:51:56 +00:00
Felipe Santos 1c886e043e fix(logger): log file using pretty format not working (#42319)
* fix(logger): throwing when logging to file using pretty format

* Fix review comments

* Fix previously existing tests too

* Keep file.path

* Custom handle err.stack for readability

* Delete `file.path` since bunyan doesn't use it anyway

* Restore append flag for consistency with JSON format
2026-04-14 18:36:05 +00:00
Sergei Zharinov 930cf6633c refactor: Rewrite imports with .ts extensions (#40700)
fix: Additional vi.mock path corrections and prettier formatting
2026-01-26 22:48:17 +00:00
Dueen Eduarda 3c5f00625f refactor: replace chalk with node util for styling in logger (#40366)
refactor: replace chalk with util for styling in logger
2026-01-15 18:04:26 +00:00
Michael Kriese 997c23502e test: migrate to vitest (#34475)
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
2025-02-26 09:35:54 +00:00
Sergei Zharinov b69416ce17 refactor(prettier): Force trailing commas (#25631) 2023-11-07 15:50:29 +00:00
Michael Kriese 64f5bd5f03 test: enforce lint style rules (#15085) 2022-04-12 14:49:49 +00:00
renovate[bot] b34b099899 chore(deps): update dependency eslint-plugin-jest to v25.3.2 (#13353)
* chore(deps): update dependency eslint-plugin-jest to v25.3.2

* chore: fix test lint issues

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2022-01-04 09:57:35 +00:00
Oleg Krivtsov 29dde2f694 test: improve test readability with expect-more-jest (#12329) 2021-10-27 07:24:36 +02:00
Sergei Zharinov 5f4b9f9a3a test: Fix test descriptions and enforce it via new linting rule (#11285) 2021-08-18 05:46:56 +00:00
Sergei Zharinov 08aa52ccc9 refactor(config): Reify snapshot tests (#11220) 2021-08-11 19:42:52 +02:00
Sergei Zharinov 1392955a04 refactor: Identify tests relying on single snapshots (#11150)
Co-authored-by: Jamie Magee <jamie.magee@gmail.com>
2021-08-07 23:43:34 +00:00
Michael Kriese 7daa93a78d refactor: extract types to new files (#9951) 2021-05-11 12:51:21 +02:00
Sergei Zharinov ce51f05cef feat(test): Detect test utils callers and simplify helpers (#9707) 2021-04-26 16:15:03 +02:00
Sergei Zharinov 72d97ec2f4 refactor(workers): Enforce getName usage (#9525) 2021-04-13 10:25:51 +00:00
Michael Kriese 74d7691bef refactor: optimize type usage (#8947) 2021-03-02 21:44:55 +01:00
Rhys Arkins 364163e7a0 fix: move tests into lib (#5635) 2020-03-05 21:57:24 +01:00