Skip to content

Commit

Permalink
add integration test to HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-ayf committed Jan 5, 2024
1 parent 83ecc40 commit 618425a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# remark-attribute-list

[![](https://github.com/cm-ayf/remark-attribute-list/actions/workflows/ci.yml/badge.svg)](https://github.com/cm-ayf/remark-attribute-list/actions)

Remark plugin to parse Attribute List Definitions and Inline Attribute Lists from Kramdown.

## Install

This package is ESM only. In Node.js, install with npm:

```sh
npm install remark-attribute-list
```

## Use

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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": {
Expand Down
40 changes: 40 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
@@ -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());
});
6 changes: 6 additions & 0 deletions test/integration/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Title
{:#title}

{:outlink:target="blank" rel="noopener noreferrer"}

See [GitHub](https://github.com/){:outlink} for more information.
2 changes: 2 additions & 0 deletions test/integration/output.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1 id="title">Title</h1>
<p>See <a href="https://github.com/" target="blank" rel="noopener noreferrer">GitHub</a> for more information.</p>

0 comments on commit 618425a

Please sign in to comment.