mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-08 23:14:43 -04:00
(test) use test environment nuxt to make it unnecessary to mock defineCachedFunction
This commit is contained in:
parent
3ee1119ce8
commit
c5d17aa011
@ -1,10 +1,12 @@
|
||||
import fs from 'fs';
|
||||
// @vitest-environment nuxt
|
||||
|
||||
import fs from 'node:fs/promises';
|
||||
|
||||
import type { AsyncExpectationResult } from '@vitest/expect';
|
||||
import { HtmlValidate } from 'html-validate/node';
|
||||
import type { Result } from 'html-validate/node';
|
||||
import marked from 'marked';
|
||||
import { describe, expect, test, vi } from 'vitest';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import type { Config } from '../../locale/config.ts';
|
||||
import allLocales from '../../locale/locales.ts';
|
||||
@ -63,12 +65,6 @@ declare module 'vitest' {
|
||||
|
||||
expect.extend({ toBeValidHTML });
|
||||
|
||||
vi.mock('nitropack/runtime', () => ({
|
||||
defineCachedFunction: <T, ArgsT extends unknown[] = unknown[]>(fn: (...args: ArgsT) => T | Promise<T>) => {
|
||||
return async (...args: ArgsT) => fn(...args);
|
||||
},
|
||||
}));
|
||||
|
||||
const baseTranslations = loadSumlFromBase('locale/_base/translations') as Translations;
|
||||
|
||||
describe.each(allLocales)('blog in $code', async ({ code }) => {
|
||||
@ -79,7 +75,7 @@ describe.each(allLocales)('blog in $code', async ({ code }) => {
|
||||
|
||||
const blogDirectory = `locale/${code}/blog`;
|
||||
const outputDirectory = `test/output/locale/${code}/blog`;
|
||||
const slugs = (await fs.promises.readdir(blogDirectory))
|
||||
const slugs = (await fs.readdir(blogDirectory))
|
||||
.filter((file) => file.endsWith('.md'))
|
||||
.map((file) => file.replace(/\.md$/, ''));
|
||||
|
||||
@ -91,19 +87,19 @@ describe.each(allLocales)('blog in $code', async ({ code }) => {
|
||||
|
||||
describe.each(slugs)('post %s', (slug) => {
|
||||
test('has valid metadata', async () => {
|
||||
const content = await fs.promises.readFile(`${blogDirectory}/${slug}.md`, 'utf-8');
|
||||
const content = await fs.readFile(`${blogDirectory}/${slug}.md`, 'utf-8');
|
||||
const metadata = extractMetadata(config, content);
|
||||
expect(metadata?.title).toBeTruthy();
|
||||
expect(metadata?.authors.length).toBeGreaterThan(0);
|
||||
expect(metadata?.date).toMatch(/\d\d\d\d-\d\d-\d\d/);
|
||||
});
|
||||
test('is valid HTML', async () => {
|
||||
const content = await fs.promises.readFile(`${blogDirectory}/${slug}.md`, 'utf-8');
|
||||
const content = await fs.readFile(`${blogDirectory}/${slug}.md`, 'utf-8');
|
||||
const parsed = marked(content);
|
||||
const blogEntry = await parseMarkdown(parsed, translator);
|
||||
|
||||
await fs.promises.mkdir(outputDirectory, { recursive: true });
|
||||
await fs.promises.writeFile(`${outputDirectory}/${slug}.html`, blogEntry.content ?? '');
|
||||
await fs.mkdir(outputDirectory, { recursive: true });
|
||||
await fs.writeFile(`${outputDirectory}/${slug}.html`, blogEntry.content ?? '');
|
||||
|
||||
await expect(blogEntry.content).toBeValidHTML();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user