|  | 
| 1 | 1 | const testUtils = require('../test/__utils__/test-utils'); | 
| 2 | 2 | const fs = require('fs'); | 
| 3 | 3 | const {describe, it, expect} = require('@jest/globals'); | 
| 4 |  | -const {getLocalFile, getRemoteFile, parseFile} = require('../utils/file'); | 
|  | 4 | +const {getLocalFile} = require('../utils/file'); | 
| 5 | 5 | 
 | 
| 6 | 6 | describe('openapi-format CLI command', () => { | 
| 7 | 7 |   it('should output the help', async () => { | 
| @@ -191,6 +191,66 @@ describe('openapi-format CLI command', () => { | 
| 191 | 191 |     expect(sanitize(result.stderr)).toStrictEqual(sanitize(output)); | 
| 192 | 192 |   }); | 
| 193 | 193 | 
 | 
|  | 194 | +  it('should bundle reference', async () => { | 
|  | 195 | +    const path = `test/yaml-ref-quotes`; | 
|  | 196 | +    const inputFile = `${path}/input.yaml`; | 
|  | 197 | +    const outputFile = `${path}/bundled.yaml`; | 
|  | 198 | +    const output = await getLocalFile(outputFile); | 
|  | 199 | + | 
|  | 200 | +    let result = await testUtils.cli([inputFile, `--no-sort`], '.'); | 
|  | 201 | +    // console.log('result', result) | 
|  | 202 | +    expect(result.code).toBe(0); | 
|  | 203 | +    expect(result.stdout).toContain('formatted successfully'); | 
|  | 204 | +    expect(result.stdout).toMatchSnapshot(); | 
|  | 205 | +    expect(sanitize(result.stderr)).toStrictEqual(sanitize(output)); | 
|  | 206 | +  }); | 
|  | 207 | + | 
|  | 208 | +  it('should not bundle reference', async () => { | 
|  | 209 | +    const path = `test/yaml-ref-quotes`; | 
|  | 210 | +    const inputFile = `${path}/input.yaml`; | 
|  | 211 | +    const outputFile = `${path}/output.yaml`; | 
|  | 212 | +    const output = await getLocalFile(outputFile); | 
|  | 213 | + | 
|  | 214 | +    let result = await testUtils.cli([inputFile, `--no-bundle`, `--no-sort`], '.'); | 
|  | 215 | +    // console.log('result', result) | 
|  | 216 | +    expect(result.code).toBe(0); | 
|  | 217 | +    expect(result.stdout).toContain('formatted successfully'); | 
|  | 218 | +    expect(result.stdout).toMatchSnapshot(); | 
|  | 219 | +    expect(sanitize(result.stderr)).toStrictEqual(sanitize(output)); | 
|  | 220 | +  }); | 
|  | 221 | + | 
|  | 222 | +  it('should split the openapi file', async () => { | 
|  | 223 | +    const path = `test/_split`; | 
|  | 224 | +    const inputFile = `../__utils__/train.yaml`; | 
|  | 225 | +    const outputFile = `output.yaml`; | 
|  | 226 | + | 
|  | 227 | +    const snap = await getLocalFile(`${path}/snap.yaml`); | 
|  | 228 | +    const snap_station = await getLocalFile(`${path}/snap_station.yaml`); | 
|  | 229 | +    const snap_station_id = await getLocalFile(`${path}/snap_station_id.yaml`); | 
|  | 230 | + | 
|  | 231 | +    let result = await testUtils.cli([inputFile, `--output ${outputFile}`, `--split`, `--no-sort`], path); | 
|  | 232 | + | 
|  | 233 | +    const outputPath = `${path}/${outputFile}`; | 
|  | 234 | +    const outputStationPath = `${path}/paths/stations_{station_id}.yaml`; | 
|  | 235 | +    const outputStationIdPath = `${path}/components/parameters/StationId.yaml`; | 
|  | 236 | +    // const outputStationSchemaPath = `${path}/components/schemas/Station.yaml` | 
|  | 237 | +    const output = await getLocalFile(outputPath); | 
|  | 238 | +    const output_station = await getLocalFile(outputStationPath); | 
|  | 239 | +    const output_station_id = await getLocalFile(outputStationIdPath); | 
|  | 240 | + | 
|  | 241 | +    // console.log('result', result) | 
|  | 242 | +    expect(result.code).toBe(0); | 
|  | 243 | +    expect(result.stdout).toContain('formatted successfully'); | 
|  | 244 | +    expect(result.stdout).toMatchSnapshot(); | 
|  | 245 | +    expect(sanitize(output)).toStrictEqual(sanitize(snap)); | 
|  | 246 | +    expect(sanitize(output_station)).toStrictEqual(sanitize(snap_station)); | 
|  | 247 | +    expect(sanitize(output_station_id)).toStrictEqual(sanitize(snap_station_id)); | 
|  | 248 | + | 
|  | 249 | +    fs.rmSync(`${path}/paths`, {recursive: true, force: true}); | 
|  | 250 | +    fs.rmSync(`${path}/components`, {recursive: true, force: true}); | 
|  | 251 | +    fs.unlinkSync(outputPath); | 
|  | 252 | +  }); | 
|  | 253 | + | 
| 194 | 254 |   it.skip('should generate a playground share URL', async () => { | 
| 195 | 255 |     const path = `test/yaml-filter-custom`; | 
| 196 | 256 |     const inputFile = `${path}/input.yaml`; | 
|  | 
0 commit comments