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: use async io #32639

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
79 changes: 46 additions & 33 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) => {
async (parentName: string) => {
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