-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from marp-team/improved-plugin-interface
Improve module interface of `@marp-team/marpit/plugin`
- Loading branch information
Showing
4 changed files
with
47 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import markdownIt from 'markdown-it' | ||
import pluginAsDefaultExport from '../src/plugin' | ||
import { marpitPlugin } from '../src/plugin' | ||
import { Marpit } from '../src/index' | ||
|
||
describe('Plugin interface', () => { | ||
it('is compatible as CommonJS module', () => { | ||
expect(require('../src/plugin')).toBeInstanceOf(Function) | ||
}) | ||
|
||
it('is compatible as ES Modules and able to use through default export', () => { | ||
expect(pluginAsDefaultExport).toBeInstanceOf(Function) | ||
}) | ||
|
||
it('is compatible as ES Modules and able to use through named export', () => { | ||
expect(marpitPlugin).toBeInstanceOf(Function) | ||
}) | ||
|
||
it('generates plugin function that is able to use in Marpit instance', () => { | ||
const pluginFn = jest.fn((md) => md) | ||
const plugin = marpitPlugin(pluginFn) | ||
expect(plugin).toBeInstanceOf(Function) | ||
|
||
const marpit = new Marpit().use(plugin) | ||
expect(pluginFn).toHaveLastReturnedWith(marpit.markdown) | ||
expect(marpit.markdown.marpit).toStrictEqual(marpit) | ||
}) | ||
|
||
it('throws error if a generated plugin was used in markdown-it instance', () => { | ||
const plugin = marpitPlugin(jest.fn()) | ||
|
||
expect(() => new markdownIt().use(plugin)).toThrowError( | ||
'Marpit plugin has detected incompatible markdown-it instance.' | ||
) | ||
}) | ||
}) |