From 2df40f722f5d8b5fcae2933289e8426a8a0e8882 Mon Sep 17 00:00:00 2001 From: cm-ayf Date: Fri, 5 Jan 2024 18:58:07 +0900 Subject: [PATCH] add integration test to HTML --- package.json | 8 ++++++-- test/integration.js | 40 ++++++++++++++++++++++++++++++++++++ test/integration/input.md | 6 ++++++ test/integration/output.html | 2 ++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 test/integration.js create mode 100644 test/integration/input.md create mode 100644 test/integration/output.html diff --git a/package.json b/package.json index 703706c..4ac2de7 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build": "tsc", "xo:fix": "xo --fix", "xo:check": "xo --check", - "test": "node --test --conditions development --watch", + "test": "node --test --conditions development --watch", "test:ci": "node --test --conditions development" }, "keywords": [ @@ -33,10 +33,14 @@ "@tsconfig/strictest": "^2.0.2", "@types/node": "^20.10.5", "is-hidden": "^2.0.1", - "remark-parse": "^11.0.0", + "rehype-stringify": "^10.0.0", + "remark-parse": "^11.0.0", + "remark-rehype": "^11.0.0", + "to-vfile": "^8.0.0", "typescript": "^5.3.3", "unist-builder": "^4.0.0", "unist-util-remove-position": "^5.0.0", + "vfile": "^6.0.1", "xo": "^0.56.0" }, "xo": { diff --git a/test/integration.js b/test/integration.js new file mode 100644 index 0000000..7bb7898 --- /dev/null +++ b/test/integration.js @@ -0,0 +1,40 @@ +import test from 'node:test'; +import process from 'node:process'; +import assert from 'node:assert'; +import {fileURLToPath} from 'node:url'; +import remarkParse from 'remark-parse'; +import {unified} from 'unified'; +import remarkRehype from 'remark-rehype'; +import rehypeStringify from 'rehype-stringify'; +import {read, write} from 'to-vfile'; +import remarkAttributeList from '../dist/index.js'; + +const processor = unified() + .use(remarkParse) + .use(remarkAttributeList) + .use(remarkRehype) + .use(rehypeStringify); + +await test('integration', async () => { + const inputUrl = new URL('integration/input.md', import.meta.url); + const outputUrl = new URL('integration/output.html', import.meta.url); + + const input = await read(inputUrl); + const actual = await processor.process(input); + /** @type {import("vfile").VFile} */ + let output; + + try { + if ('UPDATE' in process.env) { + throw new Error('Updating…'); + } + + output = await read(outputUrl); + } catch { + output = actual; + output.path = fileURLToPath(outputUrl); + await write(output); + } + + assert.strictEqual(actual.value, output.value.toString()); +}); diff --git a/test/integration/input.md b/test/integration/input.md new file mode 100644 index 0000000..37b7713 --- /dev/null +++ b/test/integration/input.md @@ -0,0 +1,6 @@ +# Title +{:#title} + +{:outlink:target="blank" rel="noopener noreferrer"} + +See [GitHub](https://github.com/){:outlink} for more information. diff --git a/test/integration/output.html b/test/integration/output.html new file mode 100644 index 0000000..5a085e9 --- /dev/null +++ b/test/integration/output.html @@ -0,0 +1,2 @@ +

Title

+

See GitHub for more information.

\ No newline at end of file