1
0
Fork 0

chore: Updated tests for core changes

This commit is contained in:
joostdecock 2022-09-25 10:46:50 +02:00
parent 4e2dc7cf33
commit 2491fcdf8d
2 changed files with 22 additions and 19 deletions

View file

@ -23,30 +23,31 @@ const mmAllowed = ['rendertest']
* @param string Pattern: The Pattern constructor * @param string Pattern: The Pattern constructor
*/ */
export const testPatternConfig = (Pattern) => { export const testPatternConfig = (Pattern) => {
const pattern = new Pattern() //const pattern = new Pattern()
const config = pattern.getConfig() const designConfig = Pattern.designConfig
const patternConfig = Pattern.patternConfig
it('Pattern data:', () => true) it('Pattern data:', () => true)
it(` - 'name' should be set and be a non-empty string`, () => { it(` - 'name' should be set and be a non-empty string`, () => {
expect(typeof config.data.name).to.equal('string') expect(typeof designConfig.data.name).to.equal('string')
expect(config.data.name.length > 1).to.be.true expect(designConfig.data.name.length > 1).to.be.true
}) })
// //
it(` - 'version' should be set and be a non-empty string`, () => { it(` - 'version' should be set and be a non-empty string`, () => {
expect(typeof config.data.version).to.equal('string') expect(typeof designConfig.data.version).to.equal('string')
expect(config.data.version.length > 1).to.be.true expect(designConfig.data.version.length > 1).to.be.true
}) })
it(` - 'version' should be a proper semantic version`, () => { it(` - 'version' should be a proper semantic version`, () => {
const chunks = config.data.version.split('.') const chunks = designConfig.data.version.split('.')
if (chunks.length > 3) { if (chunks.length > 3) {
expect(config.data.version.split('.').length).to.equal(4) expect(designConfig.data.version.split('.').length).to.equal(4)
expect(chunks[2]).to.contain.oneOf(['-alpha', '-beta', '-rc']) expect(chunks[2]).to.contain.oneOf(['-alpha', '-beta', '-rc'])
} }
else expect(config.version.split('.').length).to.equal(3) else expect(designConfig.version.split('.').length).to.equal(3)
}) })
it('Monorepo data:', () => true) it('Monorepo data:', () => true)
// Store these for re-use // Store these for re-use
const name = getShortName(config.data.name) const name = getShortName(designConfig.data.name)
const family = getFamily(name) const family = getFamily(name)
it(` - 'name' should be resolvable to a short name`, () => { it(` - 'name' should be resolvable to a short name`, () => {
expect(typeof name).to.equal('string') expect(typeof name).to.equal('string')
@ -94,13 +95,13 @@ export const testPatternConfig = (Pattern) => {
if (family !== 'utilities') { if (family !== 'utilities') {
// Ensure required measurements are known measurements // Ensure required measurements are known measurements
it('Required measurements:', () => true) it('Required measurements:', () => true)
for (const measurement of config.measurements || []) { for (const measurement of patternConfig.measurements || []) {
it(` - '${measurement}' should be a known measurement`, () => { it(` - '${measurement}' should be a known measurement`, () => {
expect(measurements.indexOf(measurement)).to.not.equal(-1) expect(measurements.indexOf(measurement)).to.not.equal(-1)
}) })
} }
it('Optional measurements:', () => true) it('Optional measurements:', () => true)
for (let measurement of config.optionalMeasurements || []) { for (let measurement of patternConfig.optionalMeasurements || []) {
it(` - '${measurement}' should be a known measurement`, () => { it(` - '${measurement}' should be a known measurement`, () => {
expect(measurements.indexOf(measurement)).to.not.equal(-1) expect(measurements.indexOf(measurement)).to.not.equal(-1)
}) })
@ -109,8 +110,8 @@ export const testPatternConfig = (Pattern) => {
// Test validity of the pattern's options // Test validity of the pattern's options
it('Pattern options:', () => true) it('Pattern options:', () => true)
for (const name in config.options) { for (const name in patternConfig.options) {
const option = config.options[name] const option = patternConfig.options[name]
const type = typeof option const type = typeof option
if (type === 'object' && typeof option.pct !== 'undefined') { if (type === 'object' && typeof option.pct !== 'undefined') {
it(` - If it has a 'menu' property, it should be a string or method`, () => { it(` - If it has a 'menu' property, it should be a string or method`, () => {
@ -155,7 +156,7 @@ export const testPatternConfig = (Pattern) => {
it(` - Should have a maximum >= the default value`, () => { it(` - Should have a maximum >= the default value`, () => {
expect(option.max >= option.mm).to.be.true expect(option.max >= option.mm).to.be.true
}) })
if (mmAllowed.indexOf(getShortName(config.data.name)) === -1) { if (mmAllowed.indexOf(getShortName(designConfig.data.name)) === -1) {
it(` - Patterns should not use mm options`, () => { it(` - Patterns should not use mm options`, () => {
expect("Does not use mm").to.be.true expect("Does not use mm").to.be.true
}) })

View file

@ -14,8 +14,8 @@ const expect = chai.expect
*/ */
export const testPatternDrafting = (Pattern, log = false) => { export const testPatternDrafting = (Pattern, log = false) => {
const pattern = new Pattern() const pattern = new Pattern()
const config = pattern.getConfig() const config = Pattern.patternConfig
const design = getShortName(config.data.name) const design = getShortName(Pattern.designConfig.data.name)
const family = getFamily(design) const family = getFamily(design)
// Helper method to try/catch pattern drafting // Helper method to try/catch pattern drafting
@ -23,9 +23,11 @@ export const testPatternDrafting = (Pattern, log = false) => {
try { try {
pattern.draft().render() pattern.draft().render()
if (log) { if (log) {
console.log(pattern.stores[0].logs) console.log(pattern.store.logs)
console.log(pattern.setStores[0].logs)
} }
if (pattern.stores[0].logs.error.length < 1) return true if (pattern.store.logs.error.length < 1) return true
if (pattern.setStores[0].logs.error.length < 1) return true
return false return false
} catch (err) { } catch (err) {
if (log) console.log(err) if (log) console.log(err)