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

ci: enable test #54

Merged
merged 6 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ jobs:
matrix:
settings:
- host: macos-latest
target: "x86_64-apple-darwin"
target: "aarch64-apple-darwin"
- host: windows-latest
target: "x86_64-pc-windows-msvc"
node: ["16", "18"]
Expand Down
573 changes: 525 additions & 48 deletions __test__/__snapshots__/index.spec.ts.snap

Large diffs are not rendered by default.

50 changes: 38 additions & 12 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
import { readFileSync } from "fs";
import { describe, test, expect } from "vitest";
import path from "path";
// @ts-ignore TODO: add types for pretter
import prettier from "prettier";

import { compile } from "../index.js";
import { compile, type CompileOptions } from "../index.js";


const formatHTML = (html: string) => {
return prettier.format(html, { parser: "html" })
};

const formatResult = async (result: string): Promise<string> => {
// For win ci
const replacedResult = result.replace(/\\r\\n/g, '<LF>').replace(/\\n/g, '<LF>');
return prettier.format(replacedResult, { parser: "babel-ts" })
};

const testCompile = async (options: CompileOptions) => {
let { code: result, html } = await compile(options);

const [formattedResult, formattedHtml] = await Promise.all([
formatResult(result),
formatHTML(html),
]);

return {
code: formattedResult,
html: formattedHtml,
};
};


const formatHTML = (html: string) => prettier.format(html, { parser: "html" });

describe("compile", () => {
test("should render container type correctly", async (t) => {
let { code: result, html } = await compile({
let { code: result, html } = await testCompile({
value: readFileSync(path.join(__dirname, "./container-type.md"), "utf8"),
filepath: "xxx.mdx",
development: true,
root: "xxx",
});

expect(formatHTML(html)).toMatchSnapshot();
expect(html).toMatchSnapshot();
expect(result).toMatchSnapshot();
});

test("should render container type with space correctly", async (t) => {
let { code: result, html } = await compile({
let { code: result, html } = await testCompile({
value: readFileSync(
path.join(__dirname, "./container-type-with-space.md"),
"utf8"
Expand All @@ -31,12 +57,12 @@ describe("compile", () => {
root: "xxx",
});

expect(formatHTML(html)).toMatchSnapshot();
expect(html).toMatchSnapshot();
expect(result).toMatchSnapshot();
});

test("should render container content correctly", async (t) => {
let { code: result, html } = await compile({
let { code: result, html } = await testCompile({
value: readFileSync(
path.join(__dirname, "./container-content.md"),
"utf8"
Expand All @@ -46,12 +72,12 @@ describe("compile", () => {
root: "xxx",
});

expect(formatHTML(html)).toMatchSnapshot();
expect(html).toMatchSnapshot();
expect(result).toMatchSnapshot();
});

test("should render container title in mdx correctly", async (t) => {
let { code: result, html } = await compile({
let { code: result, html } = await testCompile({
value: readFileSync(
path.join(__dirname, "./container-title.mdx"),
"utf8"
Expand All @@ -61,19 +87,19 @@ describe("compile", () => {
root: "xxx",
});

expect(formatHTML(html)).toMatchSnapshot();
expect(html).toMatchSnapshot();
expect(result).toMatchSnapshot();
});

test("should render container title in md correctly", async (t) => {
let { code: result, html } = await compile({
let { code: result, html } = await testCompile({
value: readFileSync(path.join(__dirname, "./container-title.md"), "utf8"),
filepath: "xxx.md",
development: true,
root: "xxx",
});

expect(formatHTML(html)).toMatchSnapshot();
expect(html).toMatchSnapshot();
expect(result).toMatchSnapshot();
});
});
14 changes: 14 additions & 0 deletions __test__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["esnext"],
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"],
"strict": true,
"declaration": true,
"noEmit": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"prettier": "^2.8.7",
"typescript": "^5.0.2",
"vite": "^4.4.11",
"vitest": "^0.29.7"
"vitest": "^0.29.7",
"@types/node": "16.18.101"
},
"engines": {
"node": ">= 10"
Expand All @@ -46,7 +47,7 @@
"build": "napi build --cargo-cwd crates/binding --platform --release",
"build:debug": "napi build --cargo-cwd crates/binding --platform",
"prepublishOnly": "napi prepublish -t npm",
"test": "echo Enable test when fix CI, GLIB3.22 not found",
"test": "vitest run",
"test:local": "vitest run",
"test:watch": "vitest dev",
"universal": "napi universal",
Expand Down
25 changes: 14 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading