Improved interface testing
This commit is contained in:
parent
7d841b2f5f
commit
1f3ecb5c58
10 changed files with 407 additions and 120 deletions
271
test/fixtures/atreus_kle.json
vendored
Normal file
271
test/fixtures/atreus_kle.json
vendored
Normal file
|
@ -0,0 +1,271 @@
|
|||
[
|
||||
[
|
||||
{
|
||||
"r": 10,
|
||||
"rx": 1,
|
||||
"y": -0.09999999999999998,
|
||||
"x": 2
|
||||
},
|
||||
"E"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.65,
|
||||
"x": 1
|
||||
},
|
||||
"W",
|
||||
{
|
||||
"x": 1
|
||||
},
|
||||
"R"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.75
|
||||
},
|
||||
"Q"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.9,
|
||||
"x": 4
|
||||
},
|
||||
"T"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.7000000000000001,
|
||||
"x": 2
|
||||
},
|
||||
"D"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.6499999999999999,
|
||||
"x": 1
|
||||
},
|
||||
"S",
|
||||
{
|
||||
"x": 1
|
||||
},
|
||||
"F"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.75
|
||||
},
|
||||
"A"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.8999999999999999,
|
||||
"x": 4
|
||||
},
|
||||
"G"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.7000000000000002,
|
||||
"x": 2
|
||||
},
|
||||
"C"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.6499999999999999,
|
||||
"x": 1
|
||||
},
|
||||
"X",
|
||||
{
|
||||
"x": 1
|
||||
},
|
||||
"V"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.75
|
||||
},
|
||||
"Z"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.8999999999999999,
|
||||
"x": 4
|
||||
},
|
||||
"B"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.75,
|
||||
"x": 5,
|
||||
"h": 1.5
|
||||
},
|
||||
"Ctrl"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.9500000000000002,
|
||||
"x": 2
|
||||
},
|
||||
"super"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.6499999999999999,
|
||||
"x": 1
|
||||
},
|
||||
"Tab",
|
||||
{
|
||||
"x": 1
|
||||
},
|
||||
"Shift"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.75
|
||||
},
|
||||
"Esc"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.8999999999999999,
|
||||
"x": 4
|
||||
},
|
||||
"Bksp"
|
||||
],
|
||||
[
|
||||
{
|
||||
"r": -10,
|
||||
"rx": 7,
|
||||
"ry": 0.965,
|
||||
"y": -0.20000000000000018,
|
||||
"x": 2
|
||||
},
|
||||
"I"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.6499999999999999,
|
||||
"x": 1
|
||||
},
|
||||
"U",
|
||||
{
|
||||
"x": 1
|
||||
},
|
||||
"O"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.75,
|
||||
"x": 4
|
||||
},
|
||||
"P"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.8999999999999999
|
||||
},
|
||||
"Y"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.7000000000000002,
|
||||
"x": 2
|
||||
},
|
||||
"K"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.6499999999999999,
|
||||
"x": 1
|
||||
},
|
||||
"J",
|
||||
{
|
||||
"x": 1
|
||||
},
|
||||
"L"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.75,
|
||||
"x": 4
|
||||
},
|
||||
":\n;"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.8999999999999999
|
||||
},
|
||||
"H"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.7000000000000002,
|
||||
"x": 2
|
||||
},
|
||||
"<\n,"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.6499999999999999,
|
||||
"x": 1
|
||||
},
|
||||
"M",
|
||||
{
|
||||
"x": 1
|
||||
},
|
||||
">\n."
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.7500000000000004,
|
||||
"x": 4
|
||||
},
|
||||
"?\n/"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.9000000000000004
|
||||
},
|
||||
"N"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.7499999999999996,
|
||||
"x": -1,
|
||||
"h": 1.5
|
||||
},
|
||||
"Alt"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.9499999999999997,
|
||||
"x": 2
|
||||
},
|
||||
"_\n-"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.6500000000000004,
|
||||
"x": 1
|
||||
},
|
||||
"fn",
|
||||
{
|
||||
"x": 1
|
||||
},
|
||||
"\"\n'"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.75,
|
||||
"x": 4
|
||||
},
|
||||
"Enter"
|
||||
],
|
||||
[
|
||||
{
|
||||
"y": -0.9000000000000004
|
||||
},
|
||||
"Space"
|
||||
]
|
||||
]
|
24
test/fixtures/big.yaml
vendored
Normal file
24
test/fixtures/big.yaml
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
units:
|
||||
a: 28 + u
|
||||
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: {}
|
3
test/fixtures/minimal.yaml
vendored
Normal file
3
test/fixtures/minimal.yaml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
points.zones.matrix:
|
||||
columns.col: {}
|
||||
rows.row: {}
|
4
test/helpers/register.js
Normal file
4
test/helpers/register.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
global.chai = require('chai')
|
||||
global.chai.use(require('chai-as-promised'))
|
||||
global.expect = global.chai.expect
|
||||
global.should = global.chai.should()
|
|
@ -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