| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import path from 'path' |
| |
|
| | import { describe, expect, test, vi } from 'vitest' |
| |
|
| | import { head, get } from '@/tests/helpers/e2etest' |
| | import { loadPages } from '@/frame/lib/page-data' |
| |
|
| | const EMPTY = Symbol('EMPTY') |
| |
|
| | const pageList = await loadPages(undefined, ['en']) |
| |
|
| | function getChangedContentFiles() { |
| | return getContentFiles(process.env.CHANGED_FILES) |
| | } |
| | function getDeletedContentFiles() { |
| | return getContentFiles(process.env.DELETED_FILES) |
| | } |
| |
|
| | function getContentFiles(spaceSeparatedList: string | undefined): string[] { |
| | return (spaceSeparatedList || '').split(/\s+/g).filter((filePath) => { |
| | |
| | return ( |
| | filePath.endsWith('.md') && |
| | filePath.split(path.sep)[0] === 'content' && |
| | path.basename(filePath) !== 'README.md' |
| | ) |
| | }) |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | vi.setConfig({ testTimeout: 60 * 1000 }) |
| |
|
| | describe('changed-content', () => { |
| | const changedContentFiles = getChangedContentFiles() |
| |
|
| | |
| | |
| | const testFiles: Array<string | symbol> = changedContentFiles.length |
| | ? changedContentFiles |
| | : [EMPTY] |
| |
|
| | test.each(testFiles)('changed-content: %s', async (file: string | symbol) => { |
| | |
| | if (file === EMPTY) return |
| |
|
| | const page = pageList.find((p) => { |
| | return path.join(p.basePath, p.relativePath) === file |
| | }) |
| | if (!page) { |
| | throw new Error(`Could not find page for ${file as string} in all loaded English content`) |
| | } |
| | |
| | for (const { href } of page.permalinks) { |
| | const res = await get(href) |
| | if (!res.ok) { |
| | let msg = `This error happened when rendering from: ${file as string}\n` |
| | msg += |
| | 'To see the full error from vitest re-run the test with DEBUG_MIDDLEWARE_TESTS=true set\n' |
| | msg += `Or, to view it locally start the server (npm run dev) and visit http://localhost:4000${href}` |
| | console.log(msg) |
| | throw new Error(`Rendering ${href} failed with status ${res.statusCode}`) |
| | } |
| | } |
| | }) |
| | }) |
| |
|
| | describe('deleted-content', () => { |
| | const deletedContentFiles = getDeletedContentFiles() |
| |
|
| | |
| | |
| | const testFiles: Array<string | symbol> = deletedContentFiles.length |
| | ? deletedContentFiles |
| | : [EMPTY] |
| |
|
| | test.each(testFiles)('deleted-content: %s', async (file: string | symbol) => { |
| | |
| | if (file === EMPTY) return |
| |
|
| | const page = pageList.find((p) => { |
| | return path.join(p.basePath, p.relativePath) === file |
| | }) |
| | if (page) { |
| | throw new Error( |
| | `The supposedly deleted file ${file as string} is still in list of loaded pages`, |
| | ) |
| | } |
| | |
| | |
| | |
| | const indexmdSuffixRegex = new RegExp(`${path.sep}index\\.md$`) |
| | const mdSuffixRegex = /\.md$/ |
| | const relativePath = (file as string).split(path.sep).slice(1).join(path.sep) |
| | const href = `/en/${relativePath.replace(indexmdSuffixRegex, '').replace(mdSuffixRegex, '')}` |
| |
|
| | const res = await head(href) |
| | const error = |
| | res.statusCode === 404 |
| | ? `The deleted file ${file as string} did not set up a redirect when deleted.` |
| | : '' |
| | |
| | |
| | |
| | expect(res.statusCode === 301 || res.statusCode === 200, error).toBe(true) |
| | }) |
| | }) |
| |
|