From 72bda7d7e370d639d61caa68a20e6b80e467074a Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 5 Feb 2018 06:15:50 +0100 Subject: Add test with AVA --- __tests__/__snapshots__/index.js.md | 12 +++++++++++ __tests__/__snapshots__/index.js.snap | Bin 0 -> 177 bytes __tests__/index.js | 38 ++++++++++++++++++++++++++++++++++ package.json | 12 +++++++++-- 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 __tests__/__snapshots__/index.js.md create mode 100644 __tests__/__snapshots__/index.js.snap create mode 100644 __tests__/index.js diff --git a/__tests__/__snapshots__/index.js.md b/__tests__/__snapshots__/index.js.md new file mode 100644 index 0000000..f8a1110 --- /dev/null +++ b/__tests__/__snapshots__/index.js.md @@ -0,0 +1,12 @@ +# Snapshot report for `__tests__/index.js` + +The actual snapshot is saved in `index.js.snap`. + +Generated by [AVA](https://ava.li). + +## question + +> Snapshot 1 + + `

␊ + What does the 🦊 say ?

` diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap new file mode 100644 index 0000000..8728a37 Binary files /dev/null and b/__tests__/__snapshots__/index.js.snap differ diff --git a/__tests__/index.js b/__tests__/index.js new file mode 100644 index 0000000..5d4c995 --- /dev/null +++ b/__tests__/index.js @@ -0,0 +1,38 @@ +import test from 'ava'; +import unified from 'unified'; +import raw from 'rehype-raw'; +import reParse from 'remark-parse'; +import stringify from 'rehype-stringify'; +import remark2rehype from 'remark-rehype'; + +import plugin from '../app'; + +const render = text => unified() + .use(reParse) + .use(plugin) + .use(remark2rehype) + .use(stringify) + .processSync(text); + +const renderRaw = text => unified() + .use(reParse) + .use(plugin) + .use(remark2rehype, {allowDangerousHTML: true}) + .use(raw) + .use(stringify) + .processSync(text); + +test('simple citation', t => { + const {contents} = render('>This is a citation'); + t.is(contents, '
\n

This is a citation

\n
'); +}); + +test('simple citation raw', t => { + const {contents} = renderRaw('>This is a citation'); + t.is(contents, '
\n

This is a citation

\n
'); +}); + +test('question', t => { + const {contents} = renderRaw('>!question\nWhat does the 🦊 say ?'); + t.snapshot(contents); +}); diff --git a/package.json b/package.json index ae516fe..fcc484a 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "description": "A remark plugin for Markdown that parse special blox", "main": "app.js", "scripts": { + "pretest": "eslint .", + "test": "ava", "start": "node app.js" }, "dependencies": { @@ -16,10 +18,16 @@ "remark" ], "devDependencies": { + "ava": "^0.25.0", + "rehype-raw": "^2.0.0", + "rehype-stringify": "^3.0.0", + "remark-parse": "^5.0.0", + "remark-rehype": "^3.0.0", + "unified": "^6.1.6", "xo": "^0.18.2" }, - "xo" : { - "space" : true, + "xo": { + "space": true, "rules": { "comma-dangle": [ "error", -- cgit v1.2.3