Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(src): adds tests for plugin, updates jest.config.js
- Loading branch information
1 parent
650b7a8
commit 4cd581e
Showing
6 changed files
with
277 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
module.exports = { | ||
bail: true, | ||
collectCoverage: true, | ||
collectCoverageFrom: ['src/index.ts'], | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: 'tsconfig.test.json', | ||
}, | ||
}, | ||
preset: 'ts-jest', | ||
roots: ['<rootDir>'], | ||
testEnvironment: 'node', | ||
transform: { '^.+\\.(ts|tsx|js|jsx)?$': 'ts-jest' }, | ||
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(ts|tsx)$'], | ||
} |
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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`rehype-code-titles Snapshot w/ title block 1`] = `"<div class=\\"rehype-code-title\\">lib/mdx.ts</div><pre><code class=\\"language-typescript\\"></code></pre>"`; | ||
exports[`rehype-code-titles Snapshot w/out title block 1`] = `"<pre><code class=\\"language-typescript\\"></code></pre>"`; |
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,45 @@ | ||
import rehype from 'rehype' | ||
import dedent from 'dedent' | ||
import rehypeCodeTitles from './index' | ||
|
||
const processHtml = (html: string): string => { | ||
return rehype() | ||
.data('settings', { fragment: true }) | ||
.use(rehypeCodeTitles) | ||
.processSync(html) | ||
.toString() | ||
} | ||
|
||
const classNameWithTitle = 'language-typescript:lib/mdx.ts' | ||
const className = 'language-typescript' | ||
|
||
describe('rehype-code-titles', () => { | ||
test('Snapshot w/ title block', () => { | ||
const result = processHtml(dedent` | ||
<pre><code class="${classNameWithTitle}"></code></pre> | ||
`) | ||
expect(result).toMatchSnapshot() | ||
}) | ||
test('Snapshot w/out title block', () => { | ||
const result = processHtml(dedent` | ||
<pre><code class="${className}"></code></pre> | ||
`) | ||
expect(result).toMatchSnapshot() | ||
}) | ||
test('Contains title block', () => { | ||
const result = processHtml(dedent` | ||
<pre><code class="${classNameWithTitle}"></code></pre> | ||
`) | ||
expect(result.includes('div')).toEqual(true) | ||
expect(result.includes('rehype-code-title')).toEqual(true) | ||
expect(result.includes('lib/mdx.ts')).toEqual(true) | ||
}) | ||
test('Does not contain title block', () => { | ||
const result = processHtml(dedent` | ||
<pre><code class="${className}"></code></pre> | ||
`) | ||
expect(result.includes('div')).not.toEqual(true) | ||
expect(result.includes('rehype-code-title')).not.toEqual(true) | ||
expect(result.includes('lib/mdx.ts')).not.toEqual(true) | ||
}) | ||
}) |
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,7 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"noEmit": true | ||
} | ||
} |
Oops, something went wrong.