Improved interface testing
This commit is contained in:
parent
7d841b2f5f
commit
1f3ecb5c58
10 changed files with 407 additions and 120 deletions
|
@ -1,76 +1,55 @@
|
|||
const u = require('../../src/utils')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const yaml = require('js-yaml')
|
||||
const ergogen = require('../../src/ergogen')
|
||||
|
||||
const minimal = {
|
||||
'points.zones.matrix': {
|
||||
columns: {col: {}},
|
||||
rows: {row: {}}
|
||||
}
|
||||
}
|
||||
|
||||
const full = {
|
||||
'points.zones.matrix': {
|
||||
columns: {col: {}},
|
||||
rows: {row: {}}
|
||||
},
|
||||
'outlines.exports': {
|
||||
export: [{
|
||||
type: 'keys',
|
||||
side: 'left',
|
||||
size: 18
|
||||
}],
|
||||
_export: [{
|
||||
type: 'keys',
|
||||
side: 'left',
|
||||
size: 18
|
||||
}]
|
||||
},
|
||||
cases: {
|
||||
export: [{
|
||||
name: 'export',
|
||||
extrude: 1
|
||||
}],
|
||||
_export: [{
|
||||
name: 'export',
|
||||
extrude: 1
|
||||
}]
|
||||
},
|
||||
pcbs: {
|
||||
export: {},
|
||||
_export: {}
|
||||
}
|
||||
}
|
||||
|
||||
// to check whether the output has "private" exports
|
||||
const underscore = obj => {
|
||||
for (const val of Object.values(obj)) {
|
||||
for (const key of Object.keys(val)) {
|
||||
if (key.startsWith('_')) return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// fixtures
|
||||
const load = name => yaml.safeLoad(fs.readFileSync(
|
||||
path.join(__dirname, `../fixtures/${name}`)
|
||||
).toString())
|
||||
const minimal = load('minimal.yaml')
|
||||
const big = load('big.yaml')
|
||||
const kle = load('atreus_kle.json')
|
||||
|
||||
describe('Interface', function() {
|
||||
|
||||
it('minimal', async function() {
|
||||
it('debug', async function() {
|
||||
// to check whether the output has "private" exports
|
||||
const underscore = obj => {
|
||||
for (const val of Object.values(obj)) {
|
||||
for (const key of Object.keys(val)) {
|
||||
if (key.startsWith('_')) return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
underscore(await ergogen.process(minimal)).should.be.false
|
||||
underscore(await ergogen.process(big, false)).should.be.false
|
||||
underscore(await ergogen.process(big, true)).should.be.true
|
||||
})
|
||||
|
||||
it('production', async function() {
|
||||
underscore(await ergogen.process(full, false)).should.be.false
|
||||
it('formats', async function() {
|
||||
const logger = msg => {
|
||||
if (msg.startsWith('Interpreting format:')) {
|
||||
throw msg.split(':')[1].trim()
|
||||
}
|
||||
}
|
||||
return Promise.all([
|
||||
ergogen.process(minimal, true, logger).should.be.rejectedWith('OBJ'),
|
||||
ergogen.process(yaml.dump(minimal), true, logger).should.be.rejectedWith('YAML'),
|
||||
ergogen.process(`
|
||||
//:
|
||||
return {points: {}}
|
||||
`, true, logger).should.be.rejectedWith('JS'),
|
||||
ergogen.process(`
|
||||
//:
|
||||
return 'not an object';
|
||||
`, true, logger).should.be.rejectedWith('not valid'),
|
||||
ergogen.process(kle, true, logger).should.be.rejectedWith('KLE'),
|
||||
ergogen.process('not an object', true, logger).should.be.rejectedWith('object'),
|
||||
ergogen.process({}, true, logger).should.be.rejectedWith('empty'),
|
||||
ergogen.process({not_points: {}}, true, () => {}).should.be.rejectedWith('any points')
|
||||
])
|
||||
})
|
||||
|
||||
it('debug', async function() {
|
||||
underscore(await ergogen.process(full, true)).should.be.true
|
||||
})
|
||||
|
||||
it('logging', async function() {
|
||||
const flag = {value: false}
|
||||
const logger = msg => { flag.value = true }
|
||||
await ergogen.process(full, false, logger)
|
||||
flag.value.should.be.true
|
||||
})
|
||||
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue