Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a50851
commit 3c2615c
Showing
7 changed files
with
181 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "<p>This is the uses page.</p>", | ||
}) | ||
}) | ||
|
||
describe("transforms markdown", () => { | ||
test("supports gfm", async () => { | ||
const html = await transformMarkdown("~~nope~~") | ||
expect(html).toEqual("<p><del>nope</del></p>") | ||
}) | ||
|
||
test("unwraps images", async () => { | ||
const html = await transformMarkdown( | ||
"![brad garropy](https://bradgarropy.com/profile.jpg)", | ||
) | ||
|
||
expect(html).toEqual( | ||
// eslint-disable-next-line quotes | ||
'<img src="https://bradgarropy.com/profile.jpg" alt="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('<div class="codesandbox">'), | ||
) | ||
|
||
expect(html).toEqual(expect.stringContaining("<iframe")) | ||
|
||
expect(html).toEqual( | ||
expect.stringContaining( | ||
// eslint-disable-next-line quotes | ||
'src="https://codesandbox.io/embed/exciting-pascal-j5hwu"', | ||
), | ||
) | ||
}) | ||
|
||
test("embeds twitch", async () => { | ||
const html = await transformMarkdown("https://twitch.tv/bradgarropy") | ||
|
||
expect(html).toEqual( | ||
// eslint-disable-next-line quotes | ||
expect.stringContaining('<div class="twitch">'), | ||
) | ||
|
||
expect(html).toEqual( | ||
// eslint-disable-next-line quotes | ||
expect.stringContaining("<iframe"), | ||
) | ||
|
||
expect(html).toEqual( | ||
expect.stringContaining( | ||
// eslint-disable-next-line quotes | ||
'src="https://player.twitch.tv?channel=bradgarropy&parent=bradgarropy.com"', | ||
), | ||
) | ||
}) | ||
|
||
test("embeds twitter", async () => { | ||
const html = await transformMarkdown( | ||
"https://twitter.com/bradgarropy/status/1458449938157801490", | ||
) | ||
|
||
// eslint-disable-next-line quotes | ||
expect(html).toEqual(expect.stringContaining('<div class="twitter">')) | ||
|
||
expect(html).toEqual( | ||
// eslint-disable-next-line quotes | ||
expect.stringContaining('<blockquote class="twitter-tweet">'), | ||
) | ||
|
||
expect(html).toEqual( | ||
expect.stringContaining( | ||
// eslint-disable-next-line quotes | ||
'<script async src="https://platform.twitter.com/widgets.js" charset="utf-8">', | ||
), | ||
) | ||
}) | ||
|
||
test("embeds youtube", async () => { | ||
const html = await transformMarkdown("https://youtu.be/9zcU6oUOHVc") | ||
|
||
// eslint-disable-next-line quotes | ||
expect(html).toEqual(expect.stringContaining('<div class="youtube">')) | ||
|
||
// eslint-disable-next-line quotes | ||
expect(html).toEqual(expect.stringContaining('<div class="youtube">')) | ||
|
||
expect(html).toEqual(expect.stringContaining("<iframe")) | ||
|
||
// eslint-disable-next-line quotes | ||
expect(html).toEqual(expect.stringContaining('title="9zcU6oUOHVc"')) | ||
|
||
expect(html).toEqual( | ||
expect.stringContaining( | ||
// eslint-disable-next-line quotes | ||
'src="https://www.youtube-nocookie.com/embed/9zcU6oUOHVc"', | ||
), | ||
) | ||
}) | ||
|
||
test.skip("syntax highlights", async () => { | ||
expect(true).toBeTruthy() | ||
}) | ||
|
||
test("slugifies headings", async () => { | ||
const html = await transformMarkdown("# Heading one") | ||
|
||
// eslint-disable-next-line quotes | ||
expect(html).toEqual(expect.stringContaining('<h1 id="heading-one">')) | ||
}) | ||
|
||
test("links headings", async () => { | ||
const html = await transformMarkdown("# Heading one") | ||
|
||
expect(html).toEqual( | ||
expect.stringContaining( | ||
// eslint-disable-next-line quotes | ||
'<a aria-hidden="true" tabindex="-1" href="#heading-one">', | ||
), | ||
) | ||
}) | ||
|
||
test("includes image sizes", async () => { | ||
const html = await transformMarkdown("![brad garropy](/profile.jpg)") | ||
|
||
expect(html).toEqual( | ||
// eslint-disable-next-line quotes | ||
'<img src="/profile.jpg" alt="brad garropy" width="460" height="460">', | ||
) | ||
}) | ||
|
||
test("opens external links in new tabs", async () => { | ||
const html = await transformMarkdown( | ||
"This is an [external link](https://example.com).", | ||
) | ||
|
||
expect(html).toEqual( | ||
expect.stringContaining( | ||
// eslint-disable-next-line quotes | ||
'<a href="https://example.com" target="_blank" rel="noopener noreferrer">external link</a>', | ||
), | ||
) | ||
}) | ||
}) |
3c2615c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
bradgarropy-next – ./
bradgarropy-next.vercel.app
bradgarropy-next-git-next-bradgarropy.vercel.app
bradgarropy-next-bradgarropy.vercel.app