Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: link to next docs and vice versa #1438

Merged
merged 22 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
20 changes: 19 additions & 1 deletion docs/.vitepress/versions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { execSync } from 'child_process';
import { version } from '../../package.json';

export const currentVersion = `v${version}`;
const NEXT_TEXT = 'Next';

function readBranchName() {
try {
return execSync('git branch --show-current').toString('utf8') || NEXT_TEXT;
} catch {
return NEXT_TEXT;
}
}

const branchName = readBranchName();
const isNext = !branchName.match(/^v\d+$/);

export const currentVersion = isNext ? NEXT_TEXT : `v${version}`;

const nextVersion = { version: NEXT_TEXT, link: 'https://next.fakerjs.dev/' };
const latestVersion = { version: `v${version}`, link: 'https://fakerjs.dev/' };

export const oldVersions = [
isNext ? latestVersion : nextVersion,
{ version: 'v6.3.1', link: 'https://v6.fakerjs.dev/' },
];
42 changes: 42 additions & 0 deletions test/docs/versions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, expect, it } from 'vitest';
import { currentVersion, oldVersions } from '../../docs/.vitepress/versions';
import { version } from '../../package.json';

function extractMajorVersionNumber(version: string): number {
return Number(version.split('.')[0].substring(1));
}

describe('docs versions', () => {
it('should have a complete set of oldVersions', () => {
const versionText = `v${version}`;

expect(oldVersions.length).toBeGreaterThanOrEqual(1);
const currentMajorVersion = extractMajorVersionNumber(versionText);

if (currentVersion === 'Next') {
expect(oldVersions[0]).toEqual({
version: versionText,
link: 'https://fakerjs.dev/',
});

for (let i = 0; i < oldVersions.length; i++) {
const oldMajorVersion = extractMajorVersionNumber(
oldVersions[i].version
);
expect(oldMajorVersion).toBe(currentMajorVersion - i);
}
} else {
expect(oldVersions[0]).toEqual({
version: 'Next',
link: 'https://next.fakerjs.dev/',
});

for (let i = 1; i < oldVersions.length; i++) {
const oldMajorVersion = extractMajorVersionNumber(
oldVersions[i].version
);
expect(oldMajorVersion).toBe(currentMajorVersion - i);
}
}
});
});