From 3c2615ce2600e23edef0cd2bb3201c3f169cc8c5 Mon Sep 17 00:00:00 2001 From: Brad Garropy Date: Thu, 27 Jan 2022 11:47:13 -0600 Subject: [PATCH] markdown tests. --- .../codesandbox/codesandbox.test.ts | 2 +- src/transformers/codesandbox/codesandbox.ts | 2 +- src/transformers/twitch/twitch.test.ts | 8 +- src/transformers/twitch/twitch.ts | 2 +- src/transformers/youtube/youtube.test.ts | 8 +- src/transformers/youtube/youtube.ts | 4 +- src/utils/markdown.test.ts | 168 ++++++++++++++++++ 7 files changed, 181 insertions(+), 13 deletions(-) diff --git a/src/transformers/codesandbox/codesandbox.test.ts b/src/transformers/codesandbox/codesandbox.test.ts index 330536d1..e364a2b9 100644 --- a/src/transformers/codesandbox/codesandbox.test.ts +++ b/src/transformers/codesandbox/codesandbox.test.ts @@ -23,7 +23,7 @@ test("transforms codesandbox links", () => {
@@ -37,7 +37,7 @@ test("transforms twitch videos", () => { src="https://player.twitch.tv?video=1272889918&parent=bradgarropy.com" frameborder="0" scrolling="no" - allowfullscreen="" + allowfullscreen > @@ -55,7 +55,7 @@ test("transforms twitch clips", () => { src="https://clips.twitch.tv/embed?clip=ZealousSpeedyStingrayUnSane&parent=bradgarropy.com" frameborder="0" scrolling="no" - allowfullscreen="" + allowfullscreen > @@ -71,7 +71,7 @@ test("transforms twitch clips", () => { src="https://clips.twitch.tv/embed?clip=ZealousSpeedyStingrayUnSane&parent=bradgarropy.com" frameborder="0" scrolling="no" - allowfullscreen="" + allowfullscreen > diff --git a/src/transformers/twitch/twitch.ts b/src/transformers/twitch/twitch.ts index d495e49c..e357dc73 100644 --- a/src/transformers/twitch/twitch.ts +++ b/src/transformers/twitch/twitch.ts @@ -28,7 +28,7 @@ const getHTML = (string: string): string => { src="${src}&parent=bradgarropy.com" frameborder="0" scrolling="no" - allowfullscreen="" + allowfullscreen > diff --git a/src/transformers/youtube/youtube.test.ts b/src/transformers/youtube/youtube.test.ts index df0496e3..e6a1495c 100644 --- a/src/transformers/youtube/youtube.test.ts +++ b/src/transformers/youtube/youtube.test.ts @@ -20,9 +20,9 @@ test("transforms youtube links", () => { @@ -37,9 +37,9 @@ test("transforms youtube links with start", () => { diff --git a/src/transformers/youtube/youtube.ts b/src/transformers/youtube/youtube.ts index b01aa666..ca4ca5ae 100644 --- a/src/transformers/youtube/youtube.ts +++ b/src/transformers/youtube/youtube.ts @@ -18,9 +18,9 @@ const getHTML = (string: string): string => { diff --git a/src/utils/markdown.test.ts b/src/utils/markdown.test.ts index e69de29b..9d40d6bf 100644 --- a/src/utils/markdown.test.ts +++ b/src/utils/markdown.test.ts @@ -0,0 +1,168 @@ +import matter from "gray-matter" +import {getMarkdownBySlug, transformMarkdown} from "utils/markdown" + +jest.mock("gray-matter") + +jest.mock("gatsby-remark-vscode", () => { + return { + remarkPlugin: tree => tree, + } +}) + +test("gets markdown by slug", async () => { + const mockMatter = matter.read as jest.Mock + mockMatter.mockReturnValue({data: {}, content: "This is the uses page."}) + + const markdown = await getMarkdownBySlug("uses") + + expect(markdown).toEqual({ + frontmatter: {}, + html: "

This is the uses page.

", + }) +}) + +describe("transforms markdown", () => { + test("supports gfm", async () => { + const html = await transformMarkdown("~~nope~~") + expect(html).toEqual("

nope

") + }) + + test("unwraps images", async () => { + const html = await transformMarkdown( + "![brad garropy](https://bradgarropy.com/profile.jpg)", + ) + + expect(html).toEqual( + // eslint-disable-next-line quotes + 'brad garropy', + ) + }) + + test("embeds codesandbox", async () => { + const html = await transformMarkdown( + "https://codesandbox.io/s/exciting-pascal-j5hwu", + ) + + expect(html).toEqual( + // eslint-disable-next-line quotes + expect.stringContaining('
'), + ) + + expect(html).toEqual(expect.stringContaining(" { + const html = await transformMarkdown("https://twitch.tv/bradgarropy") + + expect(html).toEqual( + // eslint-disable-next-line quotes + expect.stringContaining('
'), + ) + + expect(html).toEqual( + // eslint-disable-next-line quotes + expect.stringContaining(" { + const html = await transformMarkdown( + "https://twitter.com/bradgarropy/status/1458449938157801490", + ) + + // eslint-disable-next-line quotes + expect(html).toEqual(expect.stringContaining('