aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2018-02-05 22:39:25 +0100
committerache <ache@ache.one>2018-02-05 22:39:25 +0100
commit3007a24ec37aff2338ea5645ff33abff42ba6b7f (patch)
treefa9fe5dc13ecacabbe37c586ed3c52318297e0ce
parentAdd a gitignore file (diff)
add tests with AVA
-rw-r--r--__tests__/__snapshots__/index.js.md18
-rw-r--r--__tests__/__snapshots__/index.js.snapbin0 -> 155 bytes
-rw-r--r--__tests__/index.js59
-rw-r--r--__tests__/text-raw.md8
-rw-r--r--__tests__/text.md6
-rw-r--r--package.json11
6 files changed, 101 insertions, 1 deletions
diff --git a/__tests__/__snapshots__/index.js.md b/__tests__/__snapshots__/index.js.md
new file mode 100644
index 0000000..7c17a23
--- /dev/null
+++ b/__tests__/__snapshots__/index.js.md
@@ -0,0 +1,18 @@
+# Snapshot report for `__tests__/index.js`
+
+The actual snapshot is saved in `index.js.snap`.
+
+Generated by [AVA](https://ava.li).
+
+## text raw
+
+> Snapshot 1
+
+ `<p>This is a text : </p>␊
+ <textarea></textarea>`
+
+## text simple
+
+> Snapshot 1
+
+ '<p>This is a text : </p>'
diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap
new file mode 100644
index 0000000..f072c32
--- /dev/null
+++ b/__tests__/__snapshots__/index.js.snap
Binary files differ
diff --git a/__tests__/index.js b/__tests__/index.js
new file mode 100644
index 0000000..27150a5
--- /dev/null
+++ b/__tests__/index.js
@@ -0,0 +1,59 @@
+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('text simple', t => {
+ const {contents} = render(file(join(__dirname, 'text.md')));
+ t.snapshot(contents);
+});
+
+test('text raw', t => {
+ const {contents} = renderRaw(file(join(__dirname, 'text.md')));
+ t.snapshot(contents);
+});
+
+test.todo('empty');
+test.todo('empty raw');
+
+test.todo('simple');
+test.todo('simple raw');
+
+test.todo('long');
+test.todo('long raw');
+
+test.todo('id text');
+test.todo('class');
+test.todo('classes');
+test.todo('key-value');
+test.todo('classes key-value id');
+test.todo('overwrite class');
+test.todo('overwrite id');
+test.todo('multiple id');
+
+test.todo('real1');
+test.todo('real2');
+test.todo('real3');
+
diff --git a/__tests__/text-raw.md b/__tests__/text-raw.md
new file mode 100644
index 0000000..21b5833
--- /dev/null
+++ b/__tests__/text-raw.md
@@ -0,0 +1,8 @@
+This is some text.
+
+[_____
+This is a textarea
+_____]
+
+
+<span>And this is dangerous HTML 🐯</span>
diff --git a/__tests__/text.md b/__tests__/text.md
new file mode 100644
index 0000000..317346a
--- /dev/null
+++ b/__tests__/text.md
@@ -0,0 +1,6 @@
+
+This is a text :
+
+[_____
+
+_____]
diff --git a/package.json b/package.json
index 11ea9d9..14c9ff1 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,10 @@
"dependencies": {
"unist-util-visit": "^1.1.3"
},
+ "scripts": {
+ "pretest": "xo",
+ "test": "ava"
+ },
"author": "ache",
"license": "MIT",
"keywords": [
@@ -15,7 +19,12 @@
"remark"
],
"devDependencies": {
- "jest": "^22.1.4",
+ "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": {