forked from cliid/rehype-twemojify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
43 lines (38 loc) · 1.32 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @typedef {import('twemoji').ParseObject & { framework?: string; params: { [key: string]: string | number; } }} Options
* @typedef {(file: string; options: void | Options) => void} Runner
*/
import { jest } from '@jest/globals';
import rehypeParse from 'rehype-parse';
import rehypePresetMinify from 'rehype-preset-minify';
import { readSync } from 'to-vfile';
import { unified } from 'unified';
import { removePosition } from 'unist-util-remove-position';
import rehypeTwemojify from './index.js';
const basic = unified().use(rehypeParse).use(rehypePresetMinify);
/**
* Squash parameters
*
* @type {Runner}
*/
const run = (file, options) => {
// file: for example, `basic` --> basic.in.html and basic.out.html
const processor = unified()
.use(rehypeParse)
.use(rehypeTwemojify, options)
.use(rehypePresetMinify);
const input = processor.runSync(basic.parse(readSync(`./test/${file}.in.html`)));
removePosition(input, true);
const output = basic.runSync(basic.parse(readSync(`./test/${file}.out.html`)));
removePosition(output, true);
jest.useFakeTimers();
test(file, () => {
expect(input).toEqual(output);
});
};
// tests
run('basic');
run('massive');
run('svg', { ext: '.svg', size: 'svg' });
run('next', { framework: 'next' });
run('next-custom', { framework: 'next', params: { w: 3840, q: 100 } });