From 4ef9cc8d53450791e2724f55c23f74fda6a3d4c4 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 29 Apr 2024 14:57:52 +0200 Subject: [PATCH] Test the actual build output - This changes the test runner from Playwright to `node:test` and `snapshot-fixtures`. - This publishes source maps - This publishes declaration maps --- .c8rc.json | 2 +- .gitignore | 3 - .prettierignore | 5 +- .../error/expected.html | 0 .../error/expected.md | 0 {test/fixtures => fixtures}/error/input.md | 0 .../options.ts => fixtures/error/options.js | 5 +- .../errorEmpty/expected.html | 0 .../errorEmpty/expected.md | 0 .../fixtures => fixtures}/errorEmpty/input.md | 0 fixtures/errorEmpty/options.js | 5 + .../forest/expected.html | 0 .../forest/expected.md | 0 {test/fixtures => fixtures}/forest/input.md | 0 fixtures/forest/options.js | 6 + .../multiple/expected.html | 0 .../multiple/expected.md | 0 {test/fixtures => fixtures}/multiple/input.md | 0 .../nested/expected.html | 0 .../nested/expected.md | 0 {test/fixtures => fixtures}/nested/input.md | 0 .../no-mermaid/expected.html | 0 .../no-mermaid/expected.md | 0 .../no-mermaid/input.md | 0 .../simple/expected.html | 0 .../simple/expected.md | 0 {test/fixtures => fixtures}/simple/input.md | 0 package-lock.json | 180 ++++++++++-------- package.json | 15 +- playwright.config.ts | 8 - src/remark-mermaidjs.test.ts | 44 +++++ index.ts => src/remark-mermaidjs.ts | 0 test/fixtures/errorEmpty/options.ts | 6 - test/fixtures/forest/options.ts | 7 - test/test.ts | 56 ------ tsconfig.json | 11 +- 36 files changed, 173 insertions(+), 180 deletions(-) rename test/test.ts-snapshots/error-node.html => fixtures/error/expected.html (100%) rename test/test.ts-snapshots/error-node.md => fixtures/error/expected.md (100%) rename {test/fixtures => fixtures}/error/input.md (100%) rename test/fixtures/error/options.ts => fixtures/error/options.js (60%) rename test/test.ts-snapshots/errorEmpty-node.html => fixtures/errorEmpty/expected.html (100%) rename test/test.ts-snapshots/errorEmpty-node.md => fixtures/errorEmpty/expected.md (100%) rename {test/fixtures => fixtures}/errorEmpty/input.md (100%) create mode 100644 fixtures/errorEmpty/options.js rename test/test.ts-snapshots/forest-node.html => fixtures/forest/expected.html (100%) rename test/test.ts-snapshots/forest-node.md => fixtures/forest/expected.md (100%) rename {test/fixtures => fixtures}/forest/input.md (100%) create mode 100644 fixtures/forest/options.js rename test/test.ts-snapshots/multiple-node.html => fixtures/multiple/expected.html (100%) rename test/test.ts-snapshots/multiple-node.md => fixtures/multiple/expected.md (100%) rename {test/fixtures => fixtures}/multiple/input.md (100%) rename test/test.ts-snapshots/nested-node.html => fixtures/nested/expected.html (100%) rename test/test.ts-snapshots/nested-node.md => fixtures/nested/expected.md (100%) rename {test/fixtures => fixtures}/nested/input.md (100%) rename test/test.ts-snapshots/no-mermaid-node.html => fixtures/no-mermaid/expected.html (100%) rename test/fixtures/no-mermaid/input.md => fixtures/no-mermaid/expected.md (100%) rename test/test.ts-snapshots/no-mermaid-node.md => fixtures/no-mermaid/input.md (100%) rename test/test.ts-snapshots/simple-node.html => fixtures/simple/expected.html (100%) rename test/test.ts-snapshots/simple-node.md => fixtures/simple/expected.md (100%) rename {test/fixtures => fixtures}/simple/input.md (100%) delete mode 100644 playwright.config.ts create mode 100644 src/remark-mermaidjs.test.ts rename index.ts => src/remark-mermaidjs.ts (100%) delete mode 100644 test/fixtures/errorEmpty/options.ts delete mode 100644 test/fixtures/forest/options.ts delete mode 100644 test/test.ts diff --git a/.c8rc.json b/.c8rc.json index 0fc1f54..fecdfa3 100644 --- a/.c8rc.json +++ b/.c8rc.json @@ -1,5 +1,5 @@ { "100": true, - "include": ["index.ts"], + "include": ["src/remark-mermaid.ts"], "reporter": ["html", "lcov", "text"] } diff --git a/.gitignore b/.gitignore index f773d47..3145d11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ coverage/ dist/ node_modules/ -test-results/ -*.d.ts -*.js *.log *.tgz diff --git a/.prettierignore b/.prettierignore index 2de248a..67fc140 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1 @@ -**/*-snapshots/* -coverage/ -dist/ -test-results/ +fixtures/ diff --git a/test/test.ts-snapshots/error-node.html b/fixtures/error/expected.html similarity index 100% rename from test/test.ts-snapshots/error-node.html rename to fixtures/error/expected.html diff --git a/test/test.ts-snapshots/error-node.md b/fixtures/error/expected.md similarity index 100% rename from test/test.ts-snapshots/error-node.md rename to fixtures/error/expected.md diff --git a/test/fixtures/error/input.md b/fixtures/error/input.md similarity index 100% rename from test/fixtures/error/input.md rename to fixtures/error/input.md diff --git a/test/fixtures/error/options.ts b/fixtures/error/options.js similarity index 60% rename from test/fixtures/error/options.ts rename to fixtures/error/options.js index de374d3..4860068 100644 --- a/test/fixtures/error/options.ts +++ b/fixtures/error/options.js @@ -1,6 +1,5 @@ -import { type RemarkMermaidOptions } from 'remark-mermaidjs' - -export const options: RemarkMermaidOptions = { +/** @type {import('remark-mermaidjs').RemarkMermaidOptions} */ +export default { errorFallback(node, error, vfile) { return { type: 'code', diff --git a/test/test.ts-snapshots/errorEmpty-node.html b/fixtures/errorEmpty/expected.html similarity index 100% rename from test/test.ts-snapshots/errorEmpty-node.html rename to fixtures/errorEmpty/expected.html diff --git a/test/test.ts-snapshots/errorEmpty-node.md b/fixtures/errorEmpty/expected.md similarity index 100% rename from test/test.ts-snapshots/errorEmpty-node.md rename to fixtures/errorEmpty/expected.md diff --git a/test/fixtures/errorEmpty/input.md b/fixtures/errorEmpty/input.md similarity index 100% rename from test/fixtures/errorEmpty/input.md rename to fixtures/errorEmpty/input.md diff --git a/fixtures/errorEmpty/options.js b/fixtures/errorEmpty/options.js new file mode 100644 index 0000000..8ac5f5b --- /dev/null +++ b/fixtures/errorEmpty/options.js @@ -0,0 +1,5 @@ +/** @type {import('remark-mermaidjs').RemarkMermaidOptions} */ +export default { + // eslint-disable-next-line @typescript-eslint/no-empty-function + errorFallback() {} +} diff --git a/test/test.ts-snapshots/forest-node.html b/fixtures/forest/expected.html similarity index 100% rename from test/test.ts-snapshots/forest-node.html rename to fixtures/forest/expected.html diff --git a/test/test.ts-snapshots/forest-node.md b/fixtures/forest/expected.md similarity index 100% rename from test/test.ts-snapshots/forest-node.md rename to fixtures/forest/expected.md diff --git a/test/fixtures/forest/input.md b/fixtures/forest/input.md similarity index 100% rename from test/fixtures/forest/input.md rename to fixtures/forest/input.md diff --git a/fixtures/forest/options.js b/fixtures/forest/options.js new file mode 100644 index 0000000..e44e972 --- /dev/null +++ b/fixtures/forest/options.js @@ -0,0 +1,6 @@ +/** @type {import('remark-mermaidjs').RemarkMermaidOptions} */ +export default { + mermaidConfig: { + theme: 'forest' + } +} diff --git a/test/test.ts-snapshots/multiple-node.html b/fixtures/multiple/expected.html similarity index 100% rename from test/test.ts-snapshots/multiple-node.html rename to fixtures/multiple/expected.html diff --git a/test/test.ts-snapshots/multiple-node.md b/fixtures/multiple/expected.md similarity index 100% rename from test/test.ts-snapshots/multiple-node.md rename to fixtures/multiple/expected.md diff --git a/test/fixtures/multiple/input.md b/fixtures/multiple/input.md similarity index 100% rename from test/fixtures/multiple/input.md rename to fixtures/multiple/input.md diff --git a/test/test.ts-snapshots/nested-node.html b/fixtures/nested/expected.html similarity index 100% rename from test/test.ts-snapshots/nested-node.html rename to fixtures/nested/expected.html diff --git a/test/test.ts-snapshots/nested-node.md b/fixtures/nested/expected.md similarity index 100% rename from test/test.ts-snapshots/nested-node.md rename to fixtures/nested/expected.md diff --git a/test/fixtures/nested/input.md b/fixtures/nested/input.md similarity index 100% rename from test/fixtures/nested/input.md rename to fixtures/nested/input.md diff --git a/test/test.ts-snapshots/no-mermaid-node.html b/fixtures/no-mermaid/expected.html similarity index 100% rename from test/test.ts-snapshots/no-mermaid-node.html rename to fixtures/no-mermaid/expected.html diff --git a/test/fixtures/no-mermaid/input.md b/fixtures/no-mermaid/expected.md similarity index 100% rename from test/fixtures/no-mermaid/input.md rename to fixtures/no-mermaid/expected.md diff --git a/test/test.ts-snapshots/no-mermaid-node.md b/fixtures/no-mermaid/input.md similarity index 100% rename from test/test.ts-snapshots/no-mermaid-node.md rename to fixtures/no-mermaid/input.md diff --git a/test/test.ts-snapshots/simple-node.html b/fixtures/simple/expected.html similarity index 100% rename from test/test.ts-snapshots/simple-node.html rename to fixtures/simple/expected.html diff --git a/test/test.ts-snapshots/simple-node.md b/fixtures/simple/expected.md similarity index 100% rename from test/test.ts-snapshots/simple-node.md rename to fixtures/simple/expected.md diff --git a/test/fixtures/simple/input.md b/fixtures/simple/input.md similarity index 100% rename from test/fixtures/simple/input.md rename to fixtures/simple/input.md diff --git a/package-lock.json b/package-lock.json index 749ede9..febb268 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,9 +17,8 @@ "vfile": "^6.0.0" }, "devDependencies": { - "@playwright/test": "^1.0.0", "@types/hast": "^3.0.0", - "c8": "^8.0.0", + "c8": "^9.0.0", "eslint": "^8.0.0", "eslint-config-remcohaszing": "^10.0.0", "prettier": "^3.0.0", @@ -28,6 +27,7 @@ "remark-cli": "^11.0.0", "remark-preset-remcohaszing": "^2.0.0", "remark-rehype": "^11.0.0", + "snapshot-fixtures": "^1.0.0", "typescript": "^5.0.0" }, "funding": { @@ -530,22 +530,6 @@ "balanced-match": "^1.0.0" } }, - "node_modules/@npmcli/map-workspaces/node_modules/foreground-child": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", - "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.0", - "signal-exit": "^4.0.1" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/@npmcli/map-workspaces/node_modules/glob": { "version": "10.3.4", "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.4.tgz", @@ -583,18 +567,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/@npmcli/map-workspaces/node_modules/signal-exit": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", - "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", - "dev": true, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/@npmcli/name-from-folder": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@npmcli/name-from-folder/-/name-from-folder-2.0.0.tgz", @@ -635,21 +607,6 @@ "url": "https://opencollective.com/unts" } }, - "node_modules/@playwright/test": { - "version": "1.38.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.38.0.tgz", - "integrity": "sha512-xis/RXXsLxwThKnlIXouxmIvvT3zvQj1JE39GsNieMUrMpb3/GySHDh2j8itCG22qKVD4MYLBp7xB73cUW/UUw==", - "dev": true, - "dependencies": { - "playwright": "1.38.0" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=16" - } - }, "node_modules/@prettier/sync": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@prettier/sync/-/sync-0.3.0.tgz", @@ -1366,19 +1323,18 @@ } }, "node_modules/c8": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/c8/-/c8-8.0.1.tgz", - "integrity": "sha512-EINpopxZNH1mETuI0DzRA4MZpAUH+IFiRhnmFD3vFr3vdrgxqi3VfE3KL0AIL+zDq8rC9bZqwM/VDmmoe04y7w==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/c8/-/c8-9.1.0.tgz", + "integrity": "sha512-mBWcT5iqNir1zIkzSPyI3NCR9EZCVI3WUD+AVO17MVWTSFNyUueXE82qTeampNtTr+ilN/5Ua3j24LgbCKjDVg==", "dev": true, "dependencies": { "@bcoe/v8-coverage": "^0.2.3", "@istanbuljs/schema": "^0.1.3", "find-up": "^5.0.0", - "foreground-child": "^2.0.0", + "foreground-child": "^3.1.1", "istanbul-lib-coverage": "^3.2.0", "istanbul-lib-report": "^3.0.1", "istanbul-reports": "^3.1.6", - "rimraf": "^3.0.2", "test-exclude": "^6.0.0", "v8-to-istanbul": "^9.0.0", "yargs": "^17.7.2", @@ -1388,7 +1344,7 @@ "c8": "bin/c8.js" }, "engines": { - "node": ">=12" + "node": ">=14.14.0" } }, "node_modules/call-bind": { @@ -3208,16 +3164,31 @@ } }, "node_modules/foreground-child": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", - "integrity": "sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", + "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", "dev": true, "dependencies": { "cross-spawn": "^7.0.0", - "signal-exit": "^3.0.2" + "signal-exit": "^4.0.1" }, "engines": { - "node": ">=8.0.0" + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/foreground-child/node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/format": { @@ -7951,24 +7922,6 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, - "node_modules/playwright": { - "version": "1.38.0", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.38.0.tgz", - "integrity": "sha512-fJGw+HO0YY+fU/F1N57DMO+TmXHTrmr905J05zwAQE9xkuwP/QLDk63rVhmyxh03dYnEhnRbsdbH9B0UVVRB3A==", - "dev": true, - "dependencies": { - "playwright-core": "1.38.0" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=16" - }, - "optionalDependencies": { - "fsevents": "2.3.2" - } - }, "node_modules/playwright-core": { "version": "1.38.0", "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.38.0.tgz", @@ -8000,9 +7953,9 @@ } }, "node_modules/prettier": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", - "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", "dev": true, "bin": { "prettier": "bin/prettier.cjs" @@ -12024,7 +11977,8 @@ "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true + "dev": true, + "peer": true }, "node_modules/slash": { "version": "3.0.0", @@ -12036,6 +11990,70 @@ "node": ">=8" } }, + "node_modules/snapshot-fixtures": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/snapshot-fixtures/-/snapshot-fixtures-1.1.0.tgz", + "integrity": "sha512-hyw7W1y5atsdZrD4n/6pOLk3ivH0qlcgRx3l5Epi5ApknKozc5ljVVW1vMQOO8ay7L5zfzwfYYaF6CBVKeuHnQ==", + "dev": true, + "dependencies": { + "chalk": "^5.0.0", + "ci-info": "^4.0.0", + "diff": "^5.0.0", + "to-vfile": "^8.0.0", + "vfile": "^6.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/remcohaszing" + }, + "peerDependencies": { + "prettier": ">=3" + }, + "peerDependenciesMeta": { + "prettier": { + "optional": true + } + } + }, + "node_modules/snapshot-fixtures/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "dev": true, + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/snapshot-fixtures/node_modules/ci-info": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.0.0.tgz", + "integrity": "sha512-TdHqgGf9odd8SXNuxtUBVx8Nv+qZOejE6qyqiy5NtbYYQOeFa6zmHkxlPzmaLxWWHsU6nJmB7AETdVPi+2NBUg==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/sibiraj-s" + } + ], + "engines": { + "node": ">=8" + } + }, + "node_modules/snapshot-fixtures/node_modules/to-vfile": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/to-vfile/-/to-vfile-8.0.0.tgz", + "integrity": "sha512-IcmH1xB5576MJc9qcfEC/m/nQCFt3fzMHz45sSlgJyTWjRbKW1HAkJpuf3DgE57YzIlZcwcBZA5ENQbBo4aLkg==", + "dev": true, + "dependencies": { + "vfile": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/space-separated-tokens": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", @@ -12615,9 +12633,9 @@ "dev": true }, "node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", "dev": true, "bin": { "tsc": "bin/tsc", diff --git a/package.json b/package.json index 24dc679..46441c8 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,18 @@ "name": "remark-mermaidjs", "version": "6.0.0", "description": "A remark plugin to render mermaid diagrams", - "exports": "./index.js", + "exports": "./dist/remark-mermaidjs.js", + "main": "./dist/remark-mermaidjs.js", "type": "module", "files": [ - "index.d.ts", - "index.js" + "dist", + "src", + "!*.test.*" ], "scripts": { - "prepack": "tsc --noEmit false", - "test": "c8 playwright test" + "prepack": "tsc --build", + "pretest": "tsc --build", + "test": "c8 node --enable-source-maps ./dist/remark-mermaidjs.test.js" }, "author": "Remco Haszing ", "license": "MIT", @@ -36,7 +39,6 @@ "vfile": "^6.0.0" }, "devDependencies": { - "@playwright/test": "^1.0.0", "@types/hast": "^3.0.0", "c8": "^8.0.0", "eslint": "^8.0.0", @@ -47,6 +49,7 @@ "remark-cli": "^11.0.0", "remark-preset-remcohaszing": "^2.0.0", "remark-rehype": "^11.0.0", + "snapshot-fixtures": "^1.0.0", "typescript": "^5.0.0" } } diff --git a/playwright.config.ts b/playwright.config.ts deleted file mode 100644 index cb76bef..0000000 --- a/playwright.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { type PlaywrightTestConfig } from '@playwright/test' - -const config: PlaywrightTestConfig = { - testMatch: /test\/test\.ts$/, - metadata: {} -} - -export default config diff --git a/src/remark-mermaidjs.test.ts b/src/remark-mermaidjs.test.ts new file mode 100644 index 0000000..49e5564 --- /dev/null +++ b/src/remark-mermaidjs.test.ts @@ -0,0 +1,44 @@ +import assert from 'node:assert/strict' +import { test } from 'node:test' + +import rehypeStringify from 'rehype-stringify' +import { remark } from 'remark' +import remarkMermaid, { type RemarkMermaidOptions } from 'remark-mermaidjs' +import remarkRehype from 'remark-rehype' +import { testFixturesDirectory } from 'snapshot-fixtures' +import { VFile } from 'vfile' + +testFixturesDirectory({ + directory: new URL('../fixtures', import.meta.url), + tests: { + 'expected.md'(input, options) { + return remark().use(remarkMermaid, options).process(input) + }, + + 'expected.html'(input, options) { + return remark() + .use(remarkMermaid, options) + .use(remarkRehype) + .use(rehypeStringify) + .process(input) + } + } +}) + +test('it should throw a vfile error if a diagram is invalid without error fallback', async () => { + const processor = remark().use(remarkMermaid) + const file = new VFile('```mermaid\ninvalid\n```\n') + await assert.rejects(processor.process(file)) + assert.equal(file.messages.length, 1) + assert.equal( + file.messages[0].message, + 'No diagram type detected matching given configuration for text: invalid' + ) + assert.equal(file.messages[0].source, 'remark-mermaidjs') + assert.equal(file.messages[0].ruleId, 'remark-mermaidjs') + assert.equal(file.messages[0].fatal, true) + assert.deepEqual(file.messages[0].place, { + start: { offset: 0, line: 1, column: 1 }, + end: { offset: 22, line: 3, column: 4 } + }) +}) diff --git a/index.ts b/src/remark-mermaidjs.ts similarity index 100% rename from index.ts rename to src/remark-mermaidjs.ts diff --git a/test/fixtures/errorEmpty/options.ts b/test/fixtures/errorEmpty/options.ts deleted file mode 100644 index 17cca85..0000000 --- a/test/fixtures/errorEmpty/options.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { type RemarkMermaidOptions } from 'remark-mermaidjs' - -export const options: RemarkMermaidOptions = { - // eslint-disable-next-line @typescript-eslint/no-empty-function - errorFallback() {} -} diff --git a/test/fixtures/forest/options.ts b/test/fixtures/forest/options.ts deleted file mode 100644 index 6587ba9..0000000 --- a/test/fixtures/forest/options.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { type RemarkMermaidOptions } from 'remark-mermaidjs' - -export const options: RemarkMermaidOptions = { - mermaidConfig: { - theme: 'forest' - } -} diff --git a/test/test.ts b/test/test.ts deleted file mode 100644 index a716f9a..0000000 --- a/test/test.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { readdir, readFile } from 'node:fs/promises' - -import { expect, test } from '@playwright/test' -import rehypeStringify from 'rehype-stringify' -import { remark } from 'remark' -import remarkRehype from 'remark-rehype' -import { VFile } from 'vfile' - -import remarkMermaid, { type RemarkMermaidOptions } from '../index.js' - -const fixtures = new URL('fixtures/', import.meta.url) -const fixtureNames = await readdir(fixtures) - -test.describe.parallel('node', () => { - for (const name of fixtureNames) { - // eslint-disable-next-line no-empty-pattern - test(name, async ({}, testInfo) => { - testInfo.snapshotSuffix = 'node' - const fixture = new URL(`${name}/`, fixtures) - const value = await readFile(new URL('input.md', fixture)) - let options: RemarkMermaidOptions | undefined - try { - ;({ options } = await import(String(new URL('options.ts', fixture)))) - } catch { - // This test case uses default options. - } - const processor = remark().use(remarkMermaid, options) - const asMarkdown = await processor.process({ path: `${name}/input.md`, value }) - const asHTML = await processor() - .use(remarkRehype) - .use(rehypeStringify) - .process({ path: `${name}/input.md`, value }) - expect(asMarkdown.value).toMatchSnapshot({ name: `${name}.md` }) - expect(asHTML.value).toMatchSnapshot({ name: `${name}.html` }) - }) - } - - test('it should throw a vfile error if a diagram is invalid without error fallback', async () => { - const processor = remark().use(remarkMermaid) - const file = new VFile('```mermaid\ninvalid\n```\n') - await expect(() => processor.process(file)).rejects.toThrowError( - 'No diagram type detected matching given configuration for text: invalid' - ) - expect(file.messages).toHaveLength(1) - expect(file.messages[0].message).toBe( - 'No diagram type detected matching given configuration for text: invalid' - ) - expect(file.messages[0].source).toBe('remark-mermaidjs') - expect(file.messages[0].ruleId).toBe('remark-mermaidjs') - expect(file.messages[0].fatal).toBe(true) - expect(file.messages[0].place).toStrictEqual({ - start: { offset: 0, line: 1, column: 1 }, - end: { offset: 22, line: 3, column: 4 } - }) - }) -}) diff --git a/tsconfig.json b/tsconfig.json index e8c9a19..88a1703 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,12 @@ { "compilerOptions": { "declaration": true, - "lib": ["dom", "es2020"], - "module": "node16", - "noEmit": true, + "declarationMap": true, + "module": "nodenext", + "outDir": "dist", + "rootDir": "src", "skipLibCheck": true, - "strict": true, - "target": "es2020" + "sourceMap": true, + "strict": true } }