From c50412e06587a2686a25ef8e81afd5e097f1b753 Mon Sep 17 00:00:00 2001 From: Guilherme Soares Date: Sun, 29 Mar 2026 15:43:22 +0100 Subject: [PATCH 1/2] 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`. --- test/__utils__/test-utils.js | 7 ++++--- test/json-default-bug-big-numbers/output.json | 2 +- test/json-delete-method/output.json | 2 +- test/json-filter-inverse-operationids-126/output.json | 2 +- test/json-filter-unused/output.json | 2 +- test/overlay-extends-local/output.yaml | 1 - test/overlay-extends-remote/output.yaml | 1 - test/test.js | 3 +-- .../yaml-filter-inverse-flagsvalue-value-array/output.yaml | 2 +- 9 files changed, 10 insertions(+), 12 deletions(-) diff --git a/test/__utils__/test-utils.js b/test/__utils__/test-utils.js index f6d29672..7d227446 100644 --- a/test/__utils__/test-utils.js +++ b/test/__utils__/test-utils.js @@ -1,5 +1,5 @@ const fs = require('fs'); -const sy = require('@stoplight/yaml'); +const os = require('os'); const {exec} = require('child_process'); const path = require('path'); const {parseFile, stringify} = require('../../utils/file'); @@ -13,6 +13,7 @@ async function loadTest(folder, inputType = 'yaml', outType = 'yaml') { const inputPath = `./test/${folder}/${inputFile}`; const outputFile = `output.${outType}`; const outputPath = `./test/${folder}/${outputFile}`; + const tmpOutput = path.join(os.tmpdir(), `openapi-format-${folder}-output.${outType}`); try { input = await parseFile(inputPath); @@ -26,10 +27,10 @@ async function loadTest(folder, inputType = 'yaml', outType = 'yaml') { // File not found = {} will be used } - let result = await cli([`${inputFile}`, `--configFile options.yaml`], testPath); + let result = await cli([`${inputFile}`, `--configFile options.yaml`, `--output ${tmpOutput}`], testPath); try { - outputAfter = await parseFile(outputPath); + outputAfter = await parseFile(tmpOutput); } catch (err) { // } diff --git a/test/json-default-bug-big-numbers/output.json b/test/json-default-bug-big-numbers/output.json index 6de1f81b..38e709eb 100644 --- a/test/json-default-bug-big-numbers/output.json +++ b/test/json-default-bug-big-numbers/output.json @@ -59,4 +59,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/json-delete-method/output.json b/test/json-delete-method/output.json index df6856cf..9dcb2515 100644 --- a/test/json-delete-method/output.json +++ b/test/json-delete-method/output.json @@ -35,4 +35,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/json-filter-inverse-operationids-126/output.json b/test/json-filter-inverse-operationids-126/output.json index 68cb2d0a..7d0edede 100644 --- a/test/json-filter-inverse-operationids-126/output.json +++ b/test/json-filter-inverse-operationids-126/output.json @@ -78,4 +78,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/json-filter-unused/output.json b/test/json-filter-unused/output.json index de838ba0..ec0a5a5a 100644 --- a/test/json-filter-unused/output.json +++ b/test/json-filter-unused/output.json @@ -141,4 +141,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/overlay-extends-local/output.yaml b/test/overlay-extends-local/output.yaml index 1a038f9d..60ace849 100644 --- a/test/overlay-extends-local/output.yaml +++ b/test/overlay-extends-local/output.yaml @@ -3,4 +3,3 @@ info: title: Base Local version: 1.0.0 paths: {} - diff --git a/test/overlay-extends-remote/output.yaml b/test/overlay-extends-remote/output.yaml index dc7c429a..10250f5a 100644 --- a/test/overlay-extends-remote/output.yaml +++ b/test/overlay-extends-remote/output.yaml @@ -5,4 +5,3 @@ info: servers: - url: 'https://api.example.com' description: Default server - diff --git a/test/test.js b/test/test.js index 8f871336..ca8d2d69 100644 --- a/test/test.js +++ b/test/test.js @@ -128,8 +128,7 @@ describe('openapi-format tests', () => { try { if (!readOutput) { - // Write OpenAPI string to file - await writeFile(outputFilename, result, options); + fs.writeFileSync(outputFilename, result, 'utf8'); } } catch (error) { console.error('error', error); diff --git a/test/yaml-filter-inverse-flagsvalue-value-array/output.yaml b/test/yaml-filter-inverse-flagsvalue-value-array/output.yaml index 9a2906d4..31333343 100644 --- a/test/yaml-filter-inverse-flagsvalue-value-array/output.yaml +++ b/test/yaml-filter-inverse-flagsvalue-value-array/output.yaml @@ -2,4 +2,4 @@ openapi: 3.0.1 servers: - url: 'https://server-e' x-stage: - - e \ No newline at end of file + - e From a6d066d5855aed76ec8062527b131e06ec7e77d1 Mon Sep 17 00:00:00 2001 From: Guilherme Soares Date: Sun, 29 Mar 2026 15:43:48 +0100 Subject: [PATCH 2/2] 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/test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test.js b/test/test.js index ca8d2d69..7af835c1 100644 --- a/test/test.js +++ b/test/test.js @@ -52,13 +52,13 @@ describe('openapi-format tests', () => { if (fs.existsSync(configFilename)) { // Load options file configFileOptions = await parseFile(configFilename); - configFileOptions.sort = !configFileOptions['no-sort']; - if (configFileOptions['no-sort'] && configFileOptions['no-sort'] === true) { + configFileOptions.sort = configFileOptions.sort ?? true; + configFileOptions.bundle = configFileOptions.bundle ?? true; + if (configFileOptions['no-sort']) { configFileOptions.sort = !configFileOptions['no-sort']; delete configFileOptions['no-sort']; } - configFileOptions.bundle = !configFileOptions['no-bundle']; - if (configFileOptions['no-sort'] && configFileOptions['no-bundle'] === true) { + if (configFileOptions['no-bundle']) { configFileOptions.bundle = !configFileOptions['no-bundle']; delete configFileOptions['no-bundle']; }