From 3ea1c745a3568f6a13e5f781b8a2805f2b8eb008 Mon Sep 17 00:00:00 2001
From: ozakione <29860391+OzakIOne@users.noreply.github.com>
Date: Thu, 12 Oct 2023 18:37:26 +0200
Subject: [PATCH] wip: add text & leaf tests
---
.../__snapshots__/index.test.ts.snap | 35 +++++++++++++++++--
.../unusedDirectives/__tests__/index.test.ts | 30 +++++++++++++---
2 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/__snapshots__/index.test.ts.snap b/packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/__snapshots__/index.test.ts.snap
index 314e75ccf0a9..2a2839047df0 100644
--- a/packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/__snapshots__/index.test.ts.snap
+++ b/packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/__snapshots__/index.test.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`directives remark plugin default behavior for custom keyword 1`] = `
+exports[`directives remark plugin default behavior for container directives 1`] = `
" Take care of snowstorms...
unused directive content
:::NotAContainerDirective with a phrase after
@@ -9,10 +9,41 @@ exports[`directives remark plugin default behavior for custom keyword 1`] = `:::
" `; -exports[`directives remark plugin default behavior for custom keyword 2`] = ` +exports[`directives remark plugin default behavior for container directives 2`] = ` [ [ "[WARNING] We found a potential error in your documentation unusedDirective "packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/__fixtures__/containerDirectives.md":7:1", ], ] `; + +exports[`directives remark plugin default behavior for leaf directives 1`] = ` +" +Leaf directive in a phrase ::NotALeafDirective
+::NotALeafDirective with a phrase after
" +`; + +exports[`directives remark plugin default behavior for leaf directives 2`] = ` +[ + [ + "[WARNING] We found a potential error in your documentation unusedLeafDirective "packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/__fixtures__/leafDirectives.md":1:1", + ], +] +`; + +exports[`directives remark plugin default behavior for text directives 1`] = ` +"Simple: textDirective1
+Simple: textDirective1
+
+Simple
+Simple:textDirective1
+
"
+`;
+
+exports[`directives remark plugin default behavior for text directives 2`] = `
+[
+ [
+ "[WARNING] We found a potential error in your documentation textDirective2 "packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/__fixtures__/textDirectives.md":7:7",
+ ],
+]
+`;
diff --git a/packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/index.test.ts b/packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/index.test.ts
index 612dfccb6e3e..815a84fefd94 100644
--- a/packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/index.test.ts
+++ b/packages/docusaurus-mdx-loader/src/remark/unusedDirectives/__tests__/index.test.ts
@@ -31,15 +31,37 @@ const processFixture = async (name: string) => {
};
describe('directives remark plugin', () => {
- it('default behavior for custom keyword', async () => {
- const consoleMock = jest
- .spyOn(console, 'warn')
- .mockImplementation(() => {});
+ let consoleMock;
+ beforeEach(() => {
+ consoleMock = jest.spyOn(console, 'warn').mockImplementation(() => {});
+ });
+
+ afterEach(() => {
+ consoleMock.mockRestore();
+ });
+
+ it('default behavior for container directives', async () => {
const result = await processFixture('containerDirectives');
expect(result).toMatchSnapshot();
expect(consoleMock.mock.calls).toMatchSnapshot();
});
+
+ it('default behavior for leaf directives', async () => {
+ const result = await processFixture('leafDirectives');
+
+ expect(result).toMatchSnapshot();
+
+ expect(consoleMock.mock.calls).toMatchSnapshot();
+ });
+
+ it('default behavior for text directives', async () => {
+ const result = await processFixture('textDirectives');
+
+ expect(result).toMatchSnapshot();
+
+ expect(consoleMock.mock.calls).toMatchSnapshot();
+ });
});