Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/utils/schema-version-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

export const CURRENT_SUPPORTED_SCHEMA = {
major: 0,
minor: 1,
minor: 2,
patch: 0,
};

function combineVersions({ major, minor, patch }) {
export function combineVersions({ major, minor, patch }) {
return [major, minor, patch].join('.');
}

const CURRENT_SCHEMA_STRING = combineVersions(CURRENT_SUPPORTED_SCHEMA);
export const CURRENT_SCHEMA_STRING = combineVersions(CURRENT_SUPPORTED_SCHEMA);

function constructMinorVersionMessage(current) {
return `[Swift-DocC-Render] The render node version for this page has a higher minor version (${current}) than Swift-DocC-Render supports (${CURRENT_SCHEMA_STRING}). Compatibility is not guaranteed.`;
Expand Down
23 changes: 13 additions & 10 deletions tests/unit/utils/schema-version-check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import emitWarningForSchemaVersionMismatch, { CURRENT_SUPPORTED_SCHEMA } from 'docc-render/utils/schema-version-check';
import emitWarningForSchemaVersionMismatch, { CURRENT_SUPPORTED_SCHEMA, combineVersions, CURRENT_SCHEMA_STRING } from 'docc-render/utils/schema-version-check';

const warnSpy = jest.spyOn(console, 'warn').mockReturnValue('');

Expand All @@ -23,33 +23,36 @@ describe('schema-version-check', () => {
});

it('emits a warning if the major version is higher than the supported', () => {
emitWarningForSchemaVersionMismatch({
const newVersion = {
...CURRENT_SUPPORTED_SCHEMA,
major: CURRENT_SUPPORTED_SCHEMA.major + 1,
});
};
emitWarningForSchemaVersionMismatch(newVersion);
expect(warnSpy).toHaveBeenCalledTimes(1);
expect(warnSpy)
.toHaveBeenCalledWith('[Swift-DocC-Render] The render node version for this page (1.1.0) has a different major version component than Swift-DocC-Render supports (0.1.0). Compatibility is not guaranteed.');
.toHaveBeenCalledWith(`[Swift-DocC-Render] The render node version for this page (${combineVersions(newVersion)}) has a different major version component than Swift-DocC-Render supports (${CURRENT_SCHEMA_STRING}). Compatibility is not guaranteed.`);
});

it('emits a warning if the major version is lower than the supported', () => {
emitWarningForSchemaVersionMismatch({
const newVersion = {
...CURRENT_SUPPORTED_SCHEMA,
major: CURRENT_SUPPORTED_SCHEMA.major - 1,
});
};
emitWarningForSchemaVersionMismatch(newVersion);
expect(warnSpy).toHaveBeenCalledTimes(1);
expect(warnSpy)
.toHaveBeenCalledWith('[Swift-DocC-Render] The render node version for this page (-1.1.0) has a different major version component than Swift-DocC-Render supports (0.1.0). Compatibility is not guaranteed.');
.toHaveBeenCalledWith(`[Swift-DocC-Render] The render node version for this page (${combineVersions(newVersion)}) has a different major version component than Swift-DocC-Render supports (${CURRENT_SCHEMA_STRING}). Compatibility is not guaranteed.`);
});

it('emits a warning if the minor version is higher than the supported', () => {
emitWarningForSchemaVersionMismatch({
const newVersion = {
...CURRENT_SUPPORTED_SCHEMA,
minor: CURRENT_SUPPORTED_SCHEMA.minor + 1,
});
};
emitWarningForSchemaVersionMismatch(newVersion);
expect(warnSpy).toHaveBeenCalledTimes(1);
expect(warnSpy)
.toHaveBeenCalledWith('[Swift-DocC-Render] The render node version for this page has a higher minor version (0.2.0) than Swift-DocC-Render supports (0.1.0). Compatibility is not guaranteed.');
.toHaveBeenCalledWith(`[Swift-DocC-Render] The render node version for this page has a higher minor version (${combineVersions(newVersion)}) than Swift-DocC-Render supports (${CURRENT_SCHEMA_STRING}). Compatibility is not guaranteed.`);
});

it('does not emit a warning, if the minor version is lower than the supported', () => {
Expand Down