1
0
Fork 0

chore: Added shared tests and templates for plugins

This commit is contained in:
Joost De Cock 2021-11-27 16:54:50 +01:00
parent 028a6e4cce
commit 2d2db41621
12 changed files with 171 additions and 26 deletions

42
tests/plugins/shared.mjs Normal file
View file

@ -0,0 +1,42 @@
import freesewing from '@freesewing/core'
import chai from 'chai'
/*
* This runs unit tests for the plugin configuration
* It expects the following:
*
* @param object plugin: The plugin object
* @param object freesewing: Imported @freesewing/core
* @param object expect: Imported chai.expect
*/
export const sharedPluginTests = plugin => {
describe('Shared Plugin Tests', () => {
it('Should have a name property', () => {
chai.expect(typeof plugin.name).to.equal('string')
chai.expect(plugin.name.length).to.be.greaterThan(2)
})
it('Should have a version property', () => {
chai.expect(typeof plugin.version).to.equal('string')
chai.expect(plugin.version.length).to.be.greaterThan(2)
})
it('Version should be a proper semantic version', () => {
chai.expect(plugin.version.split('.').length).to.equal(3)
})
if ([
// These don't set their version
'@freesewing/plugin-versionfree-svg',
'@freesewing/plugin-bundle',
].indexOf(plugin.name) === -1) {
const pattern = new freesewing.Pattern().use(plugin)
pattern.draft().render()
const version = plugin.name.split('@').pop().split('/').join(':')
it('Should set the plugin name:version attribute', () => {
chai.expect(pattern.svg.attributes.get(version)).to.equal(plugin.version)
})
}
})
}