Skip to content

Commit 67f88a7

Browse files
committed
Update tests
1 parent ee2f62f commit 67f88a7

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

bin/__snapshots__/cli.test.js.snap

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ Options:
132132
"
133133
`;
134134
135+
exports[`openapi-format CLI command should respect boolean options from .openapiformatrc 1`] = `
136+
"================================================================================
137+
OpenAPI-Format CLI settings:
138+
- .openapiformatrc: /Users/joseph/oss/openapi-format/.openapiformatrc
139+
- Input file: test/yaml-no-sort-keep-comments/input.yaml
140+
================================================================================
141+
✅ OpenAPI formatted successfully
142+
================================================================================
143+
"
144+
`;
145+
135146
exports[`openapi-format CLI command should show unused components 1`] = `
136147
"================================================================================
137148
OpenAPI-Format CLI settings:
@@ -234,7 +245,7 @@ OpenAPI-Format CLI settings:
234245
"
235246
`;
236247
237-
exports[`openapi-format CLI command should use the configFile with all settings 1`] = `
248+
exports[`openapi-format CLI command should use the configFile with all settings including boolean options 1`] = `
238249
"================================================================================
239250
OpenAPI-Format CLI settings:
240251
- Config file: test/_cli-configfile/configFile.json

bin/cli.test.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('openapi-format CLI command', () => {
9797
expect(sanitize(result.stderr)).toStrictEqual(sanitize(output));
9898
});
9999

100-
it('should use the configFile with all settings', async () => {
100+
it('should use the configFile with all settings including boolean options', async () => {
101101
// const path = `test/__utils__`;
102102
const inputFile = `test/__utils__/mockOpenApi.json`;
103103
const outputFile = `test/_cli-configfile/output.json`;
@@ -146,6 +146,63 @@ describe('openapi-format CLI command', () => {
146146
fs.readFileSync.mockRestore();
147147
});
148148

149+
it('should respect boolean options from .openapiformatrc', async () => {
150+
// Create a temporary .openapiformatrc file with boolean options
151+
const defaultConfigPath = '.openapiformatrc';
152+
const configContent = {
153+
keepComments: true,
154+
sortComponentsProps: true,
155+
split: false
156+
};
157+
158+
// Write the config file
159+
fs.writeFileSync(defaultConfigPath, JSON.stringify(configContent, null, 2));
160+
161+
try {
162+
const inputFile = `test/yaml-no-sort-keep-comments/input.yaml`;
163+
let result = await testUtils.cli([inputFile, '--no-sort'], '.');
164+
expect(result.code).toBe(0);
165+
expect(result.stdout).toContain('formatted successfully');
166+
expect(result.stdout).toMatchSnapshot();
167+
// The output should preserve comments due to keepComments: true in config
168+
expect(result.stderr).toContain('#');
169+
} finally {
170+
// Clean up - remove the temporary config file
171+
if (fs.existsSync(defaultConfigPath)) {
172+
fs.unlinkSync(defaultConfigPath);
173+
}
174+
}
175+
});
176+
177+
it('should use config file boolean options when set', async () => {
178+
// Create a config file with boolean options set to non-default values
179+
const defaultConfigPath = '.openapiformatrc';
180+
const configContent = {
181+
keepComments: true,
182+
sortComponentsProps: true,
183+
split: false,
184+
sort: false
185+
};
186+
187+
// Write the config file
188+
fs.writeFileSync(defaultConfigPath, JSON.stringify(configContent, null, 2));
189+
190+
try {
191+
const inputFile = `test/yaml-no-sort-keep-comments/input.yaml`;
192+
// Config file values should be applied
193+
let result = await testUtils.cli([inputFile], '.');
194+
expect(result.code).toBe(0);
195+
expect(result.stdout).toContain('formatted successfully');
196+
// The output should preserve comments due to config file setting
197+
expect(result.stderr).toContain('#');
198+
} finally {
199+
// Clean up - remove the temporary config file
200+
if (fs.existsSync(defaultConfigPath)) {
201+
fs.unlinkSync(defaultConfigPath);
202+
}
203+
}
204+
});
205+
149206
it('should use the casingFile', async () => {
150207
const path = `test/yaml-casing`;
151208
const inputFile = `${path}/input.yaml`;

test/_cli-configfile/configFile.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@
2222
},
2323
"no-sort": false,
2424
"lineWidth": 80,
25-
"rename": "Updated API"
25+
"rename": "Updated API",
26+
"keepComments": true,
27+
"sortComponentsProps": true,
28+
"split": false
2629
}

0 commit comments

Comments
 (0)