Skip to content

Fix tests#205

Merged
thim81 merged 2 commits intothim81:mainfrom
guilhas07:fix-tests
Mar 31, 2026
Merged

Fix tests#205
thim81 merged 2 commits intothim81:mainfrom
guilhas07:fix-tests

Conversation

@guilhas07
Copy link
Copy Markdown
Contributor

fix(test): normalize no-sort/no-bundle option handling in test runner

Problem:

  1. sort and bundle were unconditionally derived from no-sort/no-bundle,
    ignoring explicit sort/bundle values set directly in options.yaml
  2. The no-bundle delete guard incorrectly checked no-sort as its first
    condition.

Solution:

Default sort and bundle to true, and only translate the no-X keys when they
are actually present in the options file.

Test

To test, with the other fix applied, after a destroyOutput=true run:
npx jest bin/cli.test.js --no-coverage -t "should not bundle reference"

fix(test): destroyOutput regeneration double serialization and output file mutation

Problem:

When running with destroyOutput set the following problems arise:

  1. test/test.js called writeFile(outputFilename, result, options) where result is already
    a serialized string returned by run(), effectivelly double encoding it.
    The next test run (npx jest test/test.js) would load this corrupted content as the
    expected snapshot, causing all JSON test cases in test.js to fail.

  2. test/utils/test-utils.js loadTest() ran the CLI without overriding --output, so the
    CLI used the output path from options.yaml. Which during a run with
    deleteOutput set, would silently overwrite and mask
    the corruption from (1) while still producing test failures.

Solution:

  • Write the already-serialized result string directly with fs.writeFileSync in test.js.
  • Pass --output in loadTest so the CLI writes to a temp file instead of the
    shared output. Output file mutation is now exclusive owned by test.js.

… file mutation

Problem:
When running with destroyOutput set the following problems arise:

1. test/test.js called writeFile(outputFilename, result, options) where result is already
   a serialized string returned by run(), effectivelly double encoding it.
   The next test run (`npx jest test/test.js`) would load this corrupted content as the
   expected snapshot, causing all JSON test cases in test.js to fail.

2. test/__utils__/test-utils.js loadTest() ran the CLI without overriding --output, so the
   CLI used the output path from options.yaml. Which during a run with
   `deleteOutput` set, would silently overwrite and mask
   the corruption from (1) while still producing test failures.

Solution:
- Write the already-serialized result string directly with `fs.writeFileSync` in test.js.
- Pass --output <tmpfile> in loadTest so the CLI writes to a temp file instead of the
  shared `output`. Output file mutation is now exclusive owned by `test.js`.
Problem:
1. sort and bundle were unconditionally derived from no-sort/no-bundle,
   ignoring explicit sort/bundle values set directly in options.yaml
2. The no-bundle delete guard incorrectly checked no-sort as its first
   condition.

Solution:
Default sort and bundle to true, and only translate the no-X keys when they
are actually present in the options file.
@thim81 thim81 merged commit 904d78c into thim81:main Mar 31, 2026
2 checks passed
@thim81
Copy link
Copy Markdown
Owner

thim81 commented Mar 31, 2026

@guilhas07 Great of you to figure out the quirky behaviour in the tests suite.
It has been around for such a long time, and I knew there was something strange with but I never figured out what was actually causing it.

Thank you for taking the time to fix it with this PR 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants