docsify/test/integration/emoji.test.js
John Hildenbiddle 35002c92b7
feat: Native emoji w/ image-based fallbacks and improved parsing (#1746)
* Render native emoji with image fallback

Fix #779

* Deprecate emoji plugin

* Add emoji tests

* Remove console.log statement

* Fix emoji image alt attribute

* Set nativeEmoji to false by default (non-breaking)

* Fix parsing emoji in HTML comments and script tags

* Add nativeEmoji and update noEmoji details

* Add Emoji plugin deprecation notice

* Fix ESLint issues

* Create build:emoji task

- Auto-generate emoji data from GitHub API
- Auto-generate emoji markdown for website
- Add emoji page to navigation

* Fix rendering of GitHub emoji without unicode

* Adjust and match size of native and image emoji

* Update emoji test snapshot

* Update docs test snapshot

* Fix ci/codesandbox error

* Update native emoji font-stack

* Fix rendering of native multi-character emoji

* Kick GitHub Workflow

* Replace rollup’s uglify plugin with terser

* Switch “npm ci” instead of “npm i” for stability

* Change emoji data from default to named export

* Revert "Replace rollup’s uglify plugin with terser"

This reverts commit 7ba85136361c72839516900d91cca806fac94fee.

* Revert "Switch “npm ci” instead of “npm i” for stability"

This reverts commit d52b476a387250740d934e8fd7df7ba274dd17a0.

* Revert "Change emoji data from default to named export"

This reverts commit 3f2dd467cf9c7a74d8c53c2ee52cc63837b00a3c.

* Specify codesandbox template and node version

* Update codesandbox config

* Revert "Revert "Replace rollup’s uglify plugin with terser""

This reverts commit e06fed49f0383c485e01f1758228849ad0085bc8.

* Revert "Revert "Revert "Replace rollup’s uglify plugin with terser"""

This reverts commit 27d49521f61976dedcbbf210e1811839853e0e47.

* Update codesandbox config

* Revert "Update codesandbox config"

This reverts commit 5120dd23d45fbd4b2c893db33acbf7014e57c023.

* Fix codesandbox uglify error

* Emoji docs tweaks

* Restore and update emoji plugin code

* Restore and update emoji plugin docs

* Prettier updates

* Match lowercase shortcodes only

Co-authored-by: Koy Zhuang <369491420@qq.com>
2022-03-05 22:25:09 -06:00

135 lines
2.7 KiB
JavaScript

const docsifyInit = require('../helpers/docsify-init');
// Suite
// -----------------------------------------------------------------------------
describe('Emoji', function () {
// Tests
// ---------------------------------------------------------------------------
const emojiMarkdown = `
:smile:
:smile::smile:
:smile: :smile:
:smile::smile::smile:
:smile: :smile: :smile:
text:smile:
:smile:text
text:smile:text
`;
test('Renders native emoji characters (nativeEmoji:true)', async () => {
await docsifyInit({
config: {
nativeEmoji: true,
},
markdown: {
homepage: emojiMarkdown,
},
// _logHTML: true,
});
const mainElm = document.querySelector('#main');
expect(mainElm.innerHTML).toMatchSnapshot();
});
test('Renders GitHub emoji images (nativeEmoji:false)', async () => {
await docsifyInit({
config: {
nativeEmoji: false,
},
markdown: {
homepage: emojiMarkdown,
},
// _logHTML: true,
});
const mainElm = document.querySelector('#main');
expect(mainElm.innerHTML).toMatchSnapshot();
});
test('Ignores all emoji shorthand codes (noEmoji:true)', async () => {
await docsifyInit({
config: {
noEmoji: true,
},
markdown: {
homepage: emojiMarkdown,
},
// _logHTML: true,
});
const mainElm = document.querySelector('#main');
expect(mainElm.innerHTML).toMatchSnapshot();
});
test('Ignores unmatched emoji shorthand codes', async () => {
await docsifyInit({
markdown: {
homepage: `
hh:mm
hh:mm:ss
Namespace::SubNameSpace
Namespace::SubNameSpace::Class
2014-12-29T16:11:20+00:00
`,
},
// _logHTML: true,
});
const mainElm = document.querySelector('#main');
expect(mainElm.innerHTML).toMatchSnapshot();
});
test('Ignores emoji shorthand codes in comments', async () => {
await docsifyInit({
markdown: {
homepage: 'Text <!-- :foo: :100: -->',
},
// _logHTML: true,
});
const mainElm = document.querySelector('#main');
expect(mainElm.innerHTML).toMatchSnapshot();
});
test('Ignores emoji shorthand codes in code, pre, script, and template tags', async () => {
await docsifyInit({
markdown: {
homepage: `
<pre>:100:</pre>
<code>:100:</code>
<script>
var test = ':100:';
</script>
<template>
<p>:100</p>
</template>
`,
},
// _logHTML: true,
});
const mainElm = document.querySelector('#main');
expect(mainElm.innerHTML).toMatchSnapshot();
});
});