Skip to content

Commit

Permalink
Documentation testing is now utilizing async processes
Browse files Browse the repository at this point in the history
  • Loading branch information
wSimsT committed Nov 20, 2024
1 parent c9033ac commit 4215ab4
Showing 1 changed file with 50 additions and 37 deletions.
87 changes: 50 additions & 37 deletions test/documentation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe('documentation', () => {
});

describe('website-documentation', () => {
function getConfigOptionSubHeaders(
async function getConfigOptionSubHeaders(
file: string,
configOption: string,
): string[] {
): Promise<string[]> {
const subHeadings = [];
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
const content = await fs.readFile(`docs/usage/${file}`, 'utf8');
const reg = regEx(`##\\s${configOption}[\\s\\S]+?\n##\\s`);
const match = reg.exec(content);
const subHeadersMatch = match?.[0]?.matchAll(/\n###\s(?<child>\w+)\n/g);
Expand All @@ -39,8 +39,8 @@ describe('documentation', () => {
}

describe('docs/usage/configuration-options.md', () => {
function getConfigHeaders(file: string): string[] {
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
async function getConfigHeaders(file: string): Promise<string[]> {
const content = await fs.readFile(`docs/usage/${file}`, 'utf8');
const matches = content.match(/\n## (.*?)\n/g) ?? [];
return matches.map((match) => match.substring(4, match.length - 1));
}
Expand All @@ -54,20 +54,20 @@ describe('documentation', () => {
.sort();
}

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

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

function getConfigSubHeaders(file: string): string[] {
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
async function getConfigSubHeaders(file: string): Promise<string[]> {
const content = await fs.readFile(`docs/usage/${file}`, 'utf8');
const matches = content.match(/\n### (.*?)\n/g) ?? [];
return matches
.map((match) => match.substring(5, match.length - 1))
Expand Down Expand Up @@ -100,30 +100,35 @@ describe('documentation', () => {
return parentNames;
}

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

it.each([...getParentNames()])(
'%s has sub-headers sorted alphabetically',
(parentName: string) => {
it('has sub-headers sorted alphabetically', async () => {
const parentNames = getParentNames();
for (const parentName of parentNames) {
expect(
getConfigOptionSubHeaders('configuration-options.md', parentName),
).toEqual(
getConfigOptionSubHeaders(
await getConfigOptionSubHeaders(
'configuration-options.md',
parentName,
),
).toEqual(
(
await getConfigOptionSubHeaders(
'configuration-options.md',
parentName,
)
).sort(),
);
},
);
}
});
});

describe('docs/usage/self-hosted-configuration.md', () => {
function getSelfHostedHeaders(file: string): string[] {
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
async function getSelfHostedHeaders(file: string): Promise<string[]> {
const content = await fs.readFile(`docs/usage/${file}`, 'utf8');
const matches = content.match(/\n## (.*?)\n/g) ?? [];
return matches.map((match) => match.substring(4, match.length - 1));
}
Expand All @@ -135,32 +140,40 @@ describe('documentation', () => {
.sort();
}

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

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

describe('docs/usage/self-hosted-experimental.md', () => {
function getSelfHostedExperimentalConfigHeaders(file: string): string[] {
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
async function getSelfHostedExperimentalConfigHeaders(
file: string,
): Promise<string[]> {
const content = await fs.readFile(`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', () => {
it('has headers sorted alphabetically', async () => {
expect(
getSelfHostedExperimentalConfigHeaders('self-hosted-experimental.md'),
).toEqual(
getSelfHostedExperimentalConfigHeaders(
await getSelfHostedExperimentalConfigHeaders(
'self-hosted-experimental.md',
),
).toEqual(
(
await getSelfHostedExperimentalConfigHeaders(
'self-hosted-experimental.md',
)
).sort(),
);
});
Expand Down

0 comments on commit 4215ab4

Please sign in to comment.