From 9dd5edb18f8c23f3f43e253fb5c4c04ac98f173a Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 5 Feb 2018 22:21:49 +0100 Subject: add tests with AVA --- __tests__/__snapshots__/index.js.md | 28 +++++++++++++++++ __tests__/__snapshots__/index.js.snap | Bin 0 -> 353 bytes __tests__/index.js | 57 ++++++++++++++++++++++++++++++++++ __tests__/input-raw.md | 13 ++++++++ __tests__/input-simple.md | 6 ++++ package.json | 15 ++++++--- 6 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 __tests__/__snapshots__/index.js.md create mode 100644 __tests__/__snapshots__/index.js.snap create mode 100644 __tests__/index.js create mode 100644 __tests__/input-raw.md create mode 100644 __tests__/input-simple.md diff --git a/__tests__/__snapshots__/index.js.md b/__tests__/__snapshots__/index.js.md new file mode 100644 index 0000000..9c20d55 --- /dev/null +++ b/__tests__/__snapshots__/index.js.md @@ -0,0 +1,28 @@ +# Snapshot report for `__tests__/index.js` + +The actual snapshot is saved in `index.js.snap`. + +Generated by [AVA](https://ava.li). + +## line-input-raw + +> Snapshot 1 + + `

This is a input line in a paragraph . That's all forks.

␊ +

This is a formulay :

␊ +

Login : ␊ + Password :

␊ +
␊ + Dangerous HTML 🐯 !␊ +
␊ +

Your email : ␊ + Verification :

+ +## line-input + +> Snapshot 1 + + `

This is a input line in a paragraph . That's all forks.

␊ +

This is a formulay :

␊ +

Login : ␊ + Password :

` \ No newline at end of file diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap new file mode 100644 index 0000000..dd28871 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..b359cd9 --- /dev/null +++ b/__tests__/index.js @@ -0,0 +1,57 @@ +import {readFileSync as file} from 'fs'; +import {join} from 'path'; +import unified from 'unified'; + +import test from 'ava'; +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('line-input', t => { + const {contents} = render(file(join(__dirname, 'input-simple.md'))); + t.snapshot(contents); +}); + +test('line-input-simple', t => { + const {contents} = render('[__here__]'); + t.is(contents, '

'); +}); + +test('line-input-empty', t => { + const {contents} = render('[____]'); + t.is(contents, '

'); +}); + +test.todo('id text'); +test.todo('class'); +test.todo('classes'); +test.todo('key-value'); +test.todo('classes key-value id'); +test.todo('overwrite type'); +test.todo('overwrite placeholder'); +test.todo('overwrite class'); +test.todo('overwrite id'); +test.todo('multiple id'); + +test('line-input-raw', t => { + const {contents} = renderRaw(file(join(__dirname, 'input-raw.md'))); + t.snapshot(contents); +}); diff --git a/__tests__/input-raw.md b/__tests__/input-raw.md new file mode 100644 index 0000000..e7922da --- /dev/null +++ b/__tests__/input-raw.md @@ -0,0 +1,13 @@ +This is a input line in a paragraph [___Type here___]. That's all forks. + +This is a formulay : + +Login : [__Login__] +Password : [__Password__]{type=password} + +
+Dangerous HTML 🐯 ! +
+ +Your email : [__email__]{#email} +Verification : [__verif__]{#verif} diff --git a/__tests__/input-simple.md b/__tests__/input-simple.md new file mode 100644 index 0000000..4816cd8 --- /dev/null +++ b/__tests__/input-simple.md @@ -0,0 +1,6 @@ +This is a input line in a paragraph [___Type here___]. That's all forks. + +This is a formulay : + +Login : [__Login__] +Password : [__Password__]{type=password} diff --git a/package.json b/package.json index 1a9da0c..86ff3f0 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,11 @@ { "name": "remark-line-input", "version": "0.1.0", - "description": "A remark plugin to parse line input syntax.", + "description": "A remark plugin to parse line input syntax", "main": "app.js", "scripts": { + "pretest": "xo", + "test": "ava", "start": "node app.js" }, "dependencies": { @@ -17,16 +19,21 @@ "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", "always-multiline" ] } - } } -- cgit v1.2.3