Closed nickreese closed 3 years ago
@nickreese The only thing that my plugin depends on currently is data.markdown[route].length
. But would love to help, I'll see what i can do.
Update: I'm not really sure what need to be tested but at current state this is what i've come up with, i will 3 files in the test and directory routes/blog
to simulate the route
path as in the plugin and a sample markdown file which i took from elderjs sample blog. Tell me what you think.
.
└── markdown/
└── test/
├── fixtures/
│ └── getting-started-output.js
├── routes/
│ └── blog/
│ └── getting-started.md
└── index.spec.js
const plugin = require('../index');
const gettingStartedOutput = require('./fixtures/getting-started-output');
beforeAll(() => {
// for test we need to define necessary plugin property manually
plugin.settings = {};
plugin.settings.srcDir = __dirname;
plugin.settings.shortcodes = { closePattern: '}}', openPattern: '{{' };
plugin.config.routes = ['blog']
plugin.settings.plugins = {}
// plugin.settings.plugins = {'@elderjs/plugin-images': {}}
});
describe(`index.init()`, () => {
it('have defined property', () => {
expect(plugin.name).toBeDefined();
expect(plugin.description).toBeDefined();
expect(plugin.init).toBeDefined();
expect(plugin.hooks.length).toBeGreaterThan(0);
expect(plugin.config).toBeDefined();
expect(plugin.settings).toBeDefined();
expect(plugin.settings.srcDir).toBeDefined();
expect(plugin.settings.shortcodes).toBeDefined();
});
it('plugin.init() output formatting', async () => {
const pluginOutput = await plugin.init(plugin);
const markdownOuput = pluginOutput.markdown[plugin.config.routes[0]][0];
expect(pluginOutput.markdown[plugin.config.routes[0]].length).toBe(1);
expect(markdownOuput.slug).toEqual(gettingStartedOutput.slug);
expect(markdownOuput.frontmatter).toEqual(gettingStartedOutput.frontmatter);
expect(markdownOuput.html).toEqual(gettingStartedOutput.html);
expect(markdownOuput.data).toEqual({})
});
it('@elderjs/plugin-images output', async () => {
plugin.settings.plugins = { '@elderjs/plugin-images': {} }
plugin.config.useElderJsPluginImages = true;
const pluginOutput = await plugin.init(plugin);
const markdownOuput = pluginOutput.markdown[plugin.config.routes[0]][0];
expect(markdownOuput.html).toContain('<div class="md-img">');
});
});
@noxasch This looks great. 💯
@nickreese cool, I submitted a pull-request.
Thanks again. 👍
Hey man, great work on the pagination plugin. As current markdown plugin doesn't have tests I'm afraid the integration may be brittle. If you're up for it, I wouldn't turn down tests to make sure the format stays consistent.
No pressure, just a note more than anything.
Great work. 👍