Skip to content

Commit

Permalink
test: OpenAPI updater tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ixuz committed Apr 18, 2024
1 parent dafaae0 commit 4ec68c0
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,74 @@ describe('cli', function () {
});
});

it('bumps version in OpenAPI `openapi.yaml` file with CRLF Line Endings', async function () {
const expected = fs.readFileSync(
'./test/mocks/openapi-1.3.0-crlf.yaml',
'utf-8',
);
const filename = 'openapi.yaml';
mock({
bump: 'minor',
realTestFiles: [
{
filename,
path: './test/mocks/openapi-1.2.3-crlf.yaml',
},
],
});
await exec({
packageFiles: [{ filename, type: 'openapi' }],
bumpFiles: [{ filename, type: 'openapi' }],
});

// filePath is the first arg passed to writeFileSync
const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
writeFileSyncSpy,
filename,
});

if (!packageJsonWriteFileSynchCall) {
throw new Error(`writeFileSynch not invoked with path ${filename}`);
}

const calledWithContentStr = packageJsonWriteFileSynchCall[1];
expect(calledWithContentStr).toEqual(expected);
});

it('bumps version in OpenAPI `openapi.yaml` file with LF Line Endings', async function () {
const expected = fs.readFileSync(
'./test/mocks/openapi-1.3.0-lf.yaml',
'utf-8',
);
const filename = 'openapi.yaml';
mock({
bump: 'minor',
realTestFiles: [
{
filename,
path: './test/mocks/openapi-1.2.3-lf.yaml',
},
],
});
await exec({
packageFiles: [{ filename, type: 'openapi' }],
bumpFiles: [{ filename, type: 'openapi' }],
});

// filePath is the first arg passed to writeFileSync
const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
writeFileSyncSpy,
filename,
});

if (!packageJsonWriteFileSynchCall) {
throw new Error(`writeFileSynch not invoked with path ${filename}`);
}

const calledWithContentStr = packageJsonWriteFileSynchCall[1];
expect(calledWithContentStr).toEqual(expected);
});

it('bumps version in Maven `pom.xml` file with CRLF Line Endings', async function () {
const expected = fs.readFileSync(
'./test/mocks/pom-6.4.0-crlf.xml',
Expand Down

0 comments on commit 4ec68c0

Please sign in to comment.