-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds test suite and CI to run them on PR
- Loading branch information
Showing
4 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Build & Test | ||
|
||
on: | ||
# Trigger the workflow every time a push is made to 'master' | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
# Allows you to run this workflow manually from the Actions tab on GitHub. | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout your repository using git | ||
uses: actions/checkout@v4 | ||
- name: Install & Build | ||
uses: withastro/action@v2 | ||
- name: Test | ||
run: bun test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expect, test, describe } from "bun:test"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const rootDir: string = path.join(__dirname, "../"); | ||
|
||
describe("Markdown Rendering", () => { | ||
const srcDir = path.join(rootDir, "/src/pages"); | ||
const distDir = path.join(rootDir, "/dist"); | ||
|
||
const mdFiles = fs.readdirSync(srcDir).filter((file) => file.endsWith(".md")); | ||
//<h1>{frontmatter.title}</h1> | ||
test("Pages Exist", () => { | ||
mdFiles.forEach((file) => { | ||
const htmlFile = file.replace(".md", ".html"); | ||
const htmlFilePath = path.join(distDir, htmlFile); | ||
expect(fs.existsSync(htmlFilePath)).toBe(true); | ||
}); | ||
}); | ||
|
||
test("Layouts Applied", () => { | ||
mdFiles.forEach((file) => { | ||
const htmlFile = file.replace(".md", "/index.html"); | ||
const htmlFilePath = path.join(distDir, htmlFile); | ||
const htmlContent = fs.readFileSync(htmlFilePath, "utf-8"); | ||
const fileContent = fs.readFileSync(path.join(srcDir, file), "utf-8"); | ||
const frontMatterMatch = fileContent.match(/^title:\s*(.*)$/m); | ||
const frontMatterTitle = frontMatterMatch | ||
? frontMatterMatch[1] | ||
: file.replace(".md", ""); | ||
const h1Tag = `<h1>${frontMatterTitle}</h1>`; | ||
|
||
expect(htmlContent.includes(h1Tag)).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expect, test, describe } from "bun:test"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const rootDir: string = path.join(__dirname, "../"); | ||
|
||
describe("Middleware Compilation", () => { | ||
const srcDir = path.join(rootDir, "/src/pages"); | ||
const distDir = path.join(rootDir, "/dist"); | ||
|
||
const mdFiles = fs.readdirSync(srcDir).filter((file) => file.endsWith(".md")); | ||
|
||
test("HTML Redirects Exist", () => { | ||
mdFiles.forEach((file) => { | ||
const htmlFile = file.replace(".md", ".html"); | ||
const htmlFilePath = path.join(distDir, htmlFile); | ||
expect(fs.existsSync(htmlFilePath)).toBe(true); | ||
}); | ||
}); | ||
|
||
test("Redirects Work", () => { | ||
mdFiles.forEach((file) => { | ||
const htmlFile = file.replace(".md", ".html"); | ||
const htmlFilePath = path.join(distDir, htmlFile); | ||
const htmlContent = fs.readFileSync(htmlFilePath, "utf-8"); | ||
const metaTag = `<meta http-equiv="refresh" content="0; URL=http://ladybird.org/${file.replace(".md", "")}/"/>`; | ||
const linkTag = `<link rel="canonical" href="http://ladybird.org/${file.replace(".md", "")}/"/>`; | ||
|
||
expect(htmlContent.includes(metaTag)).toBe(true); | ||
expect(htmlContent.includes(linkTag)).toBe(true); | ||
}); | ||
}); | ||
}); |