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

test: Refactor documentation tests for better navigation #28590

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
126 changes: 71 additions & 55 deletions test/documentation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,84 +19,100 @@ describe('documentation', () => {
});

describe('website-documentation', () => {
describe('configuration-options', () => {
const doc = fs.readFileSync(
'docs/usage/configuration-options.md',
'utf8',
);

const headers = doc
.match(/\n## (.*?)\n/g)
?.map((match) => match.substring(4, match.length - 1));

const expectedOptions = options
.filter((option) => !option.globalOnly)
.filter((option) => !option.parents)
.filter((option) => !option.autogenerated)
.map((option) => option.name)
.sort();
describe('docs/usage/configuration-options.md', () => {
function getConfigHeaders(file: string): string[] {
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
viceice marked this conversation as resolved.
Show resolved Hide resolved
const matches = content.match(/\n## (.*?)\n/g) ?? [];
return matches.map((match) => match.substring(4, match.length - 1));
}

function getRequiredConfigOptions(): string[] {
return options
.filter((option) => !option.globalOnly)
.filter((option) => !option.parents)
.filter((option) => !option.autogenerated)
.map((option) => option.name)
.sort();
}

it('has doc headers sorted alphabetically', () => {
expect(headers).toEqual([...headers!].sort());
expect(getConfigHeaders('configuration-options.md')).toEqual(
getConfigHeaders('configuration-options.md').sort(),
);
});

it('has headers for every required option', () => {
expect(headers).toEqual(expectedOptions);
expect(getConfigHeaders('configuration-options.md')).toEqual(
getRequiredConfigOptions(),
);
});

const subHeaders = doc
.match(/\n### (.*?)\n/g)
?.map((match) => match.substring(5, match.length - 1));
subHeaders!.sort();
const expectedSubOptions = options
.filter((option) => option.stage !== 'global')
.filter((option) => !option.globalOnly)
.filter((option) => option.parents)
.map((option) => option.name)
.sort();
expectedSubOptions.sort();
function getConfigSubHeaders(file: string): string[] {
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
viceice marked this conversation as resolved.
Show resolved Hide resolved
const matches = content.match(/\n### (.*?)\n/g) ?? [];
return matches
.map((match) => match.substring(5, match.length - 1))
.sort();
}

function getRequiredConfigSubOptions(): string[] {
return options
.filter((option) => option.stage !== 'global')
.filter((option) => !option.globalOnly)
.filter((option) => option.parents)
.map((option) => option.name)
.sort();
}

it('has headers for every required sub-option', () => {
expect(subHeaders).toEqual(expectedSubOptions);
expect(getConfigSubHeaders('configuration-options.md')).toEqual(
getRequiredConfigSubOptions(),
);
});
});

describe('self-hosted-configuration', () => {
const doc = fs.readFileSync(
'docs/usage/self-hosted-configuration.md',
'utf8',
);
describe('docs/usage/self-hosted-configuration.md', () => {
function getSelfHostedHeaders(file: string): string[] {
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
const matches = content.match(/\n## (.*?)\n/g) ?? [];
return matches.map((match) => match.substring(4, match.length - 1));
}

const headers = doc
.match(/\n## (.*?)\n/g)
?.map((match) => match.substring(4, match.length - 1));

const expectedOptions = options
.filter((option) => !!option.globalOnly)
.map((option) => option.name)
.sort();
function getRequiredSelfHostedOptions(): string[] {
return options
.filter((option) => option.globalOnly)
.map((option) => option.name)
.sort();
}

it('has headers sorted alphabetically', () => {
expect(headers).toEqual([...headers!].sort());
expect(getSelfHostedHeaders('self-hosted-configuration.md')).toEqual(
getSelfHostedHeaders('self-hosted-configuration.md').sort(),
);
});

it('has headers for every required option', () => {
expect(headers).toEqual(expectedOptions);
expect(getSelfHostedHeaders('self-hosted-configuration.md')).toEqual(
getRequiredSelfHostedOptions(),
);
});
});

describe('self-hosted-experimental', () => {
const doc = fs.readFileSync(
'docs/usage/self-hosted-experimental.md',
'utf8',
);

const headers = doc
.match(/\n## (.*?)\n/g)
?.map((match) => match.substring(4, match.length - 1));
describe('docs/usage/self-hosted-experimental.md', () => {
function getSelfHostedExperimentalConfigHeaders(file: string): string[] {
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
const matches = content.match(/\n## (.*?)\n/g) ?? [];
return matches.map((match) => match.substring(4, match.length - 1));
}

it('has headers sorted alphabetically', () => {
expect(headers).toEqual([...headers!].sort());
expect(
getSelfHostedExperimentalConfigHeaders('self-hosted-experimental.md'),
).toEqual(
getSelfHostedExperimentalConfigHeaders(
'self-hosted-experimental.md',
).sort(),
);
});
});
});
Expand Down