1
0
Fork 0
freesewing/tests/plugins/shared.mjs
nikhil 6ac0e16d27 fix(testci): Accept alpha and beta package versions
testci is currently failing now that package versions have been [bumped to `3.0.0-alpha.0`](ae40299 (diff-2d72bdead8afa0798d18995311992d684348a694c2d5e214e8e4d2b6153e4821)). Alpha and beta version numbers have existed before, but only as recently as `v2.1.0-alpha.0` and `v2.7.0-beta.3` respectively, both of which preceded [the assertions in question](7ddb023c8d).

This PR updates those assertions to accept `alpha` or `beta` package versions, in addition to the already-supported `rc` and stable (non-suffixed) package versions.
2022-08-24 00:33:58 -04:00

45 lines
1.5 KiB
JavaScript

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
*/
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', () => {
const chunks = plugin.version.split('.')
if (chunks.length > 3) {
chai.expect(plugin.version.split('.').length).to.equal(4)
chai.expect(chunks[2]).to.contain.oneOf(['-alpha', '-beta', '-rc'])
}
else 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)
})
}
})
}