Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: precompile schemas, related to stylelint/stylelint#1912 (#19)
* refactor: precompile schemas, related to stylelint/stylelint#1912 * test: coverage; schema tests * test: streamConfig schema * chore: disable max line length style rule * style: use camel-case names for variables * style: silence false-positive no default import * style: generate file names use camel-case convention * chore: give script an imperative name * style: sort scripts alphabetically * chore: make build script part of the test script * chore: build assets required to pass linting * chore: remove ./dist prior to each build * chore: give script an imperative name * chore: remove superfluous test * chore: use nyc to generate code coverage * chore: give script an imperative name
- Loading branch information
Showing
8 changed files
with
432 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,12 @@ | |
], | ||
"presets": [ | ||
"es2015-node4" | ||
] | ||
], | ||
"env": { | ||
"development": { | ||
"plugins": [ | ||
"istanbul" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": "canonical" | ||
"extends": "canonical", | ||
"rules": { | ||
"max-len": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
expect | ||
} from 'chai'; | ||
import configSamples from './configSamples'; | ||
import validateConfig from '../dist/validateConfig'; | ||
import configSchema from '../src/schemas/config.json'; | ||
import Ajv from 'ajv'; | ||
import ajvKeywords from 'ajv-keywords'; | ||
|
||
describe('config.json schema', () => { | ||
var validate; | ||
|
||
before(() => { | ||
var ajv = new Ajv({allErrors: true}); | ||
ajvKeywords(ajv, 'typeof'); | ||
validate = ajv.compile(configSchema); | ||
}); | ||
|
||
it('should pass validation of valid config samples', () => { | ||
configSamples.valid.forEach((sample, i) => { | ||
testValid(sample, validate); | ||
testValid(sample, validateConfig); | ||
}); | ||
|
||
function testValid(sample, validate) { | ||
var valid = validate(sample); | ||
if (!valid) console.log(validate.errors); | ||
expect(valid).to.equal(true); | ||
} | ||
}); | ||
|
||
it('should fail validation of invalid config samples', () => { | ||
configSamples.invalid.forEach((sample, i) => { | ||
testInvalid(sample, validate); | ||
testInvalid(sample, validateConfig); | ||
}); | ||
|
||
function testInvalid(sample, validate) { | ||
var valid = validate(sample); | ||
expect(valid).to.equal(false); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
export default { | ||
valid: [ | ||
{ | ||
columns: { | ||
0: { | ||
alignment: 'left', | ||
// minWidth: 10, | ||
width: 10 | ||
}, | ||
1: { | ||
alignment: 'center', | ||
// minWidth: 10, | ||
width: 10 | ||
}, | ||
2: { | ||
alignment: 'right', | ||
// minWidth: 10, | ||
width: 10 | ||
} | ||
} | ||
}, | ||
{ | ||
border: { | ||
topBody: `─`, | ||
topJoin: `┬`, | ||
topLeft: `┌`, | ||
topRight: `┐`, | ||
|
||
bottomBody: `─`, | ||
bottomJoin: `┴`, | ||
bottomLeft: `└`, | ||
bottomRight: `┘`, | ||
|
||
bodyLeft: `│`, | ||
bodyRight: `│`, | ||
bodyJoin: `│`, | ||
|
||
joinBody: `─`, | ||
joinLeft: `├`, | ||
joinRight: `┤`, | ||
joinJoin: `┼` | ||
} | ||
}, | ||
{ | ||
columns: { | ||
0: { | ||
paddingLeft: 3 | ||
}, | ||
1: { | ||
width: 2, | ||
paddingRight: 3 | ||
} | ||
} | ||
}, | ||
{ | ||
border: {}, | ||
columnDefault: { | ||
paddingLeft: 0, | ||
paddingRight: 1 | ||
}, | ||
// drawJoin: () => { | ||
// return false | ||
// } | ||
}, | ||
{ | ||
columnDefault: { | ||
width: 50 | ||
}, | ||
// columnCount: 3, | ||
columns: { | ||
0: { | ||
width: 10, | ||
alignment: 'right' | ||
}, | ||
1: { | ||
alignment: 'center', | ||
}, | ||
2: { | ||
width: 10 | ||
} | ||
} | ||
}, | ||
{ border: { topBody: '-' } }, | ||
{ border: { topJoin: '-' } }, | ||
{ border: { topLeft: '-' } }, | ||
{ border: { topRight: '-' } }, | ||
{ border: { bottomBody: '-' } }, | ||
{ border: { bottomJoin: '-' } }, | ||
{ border: { bottomLeft: '-' } }, | ||
{ border: { bottomRight: '-' } }, | ||
{ border: { bodyLeft: '-' } }, | ||
{ border: { bodyRight: '-' } }, | ||
{ border: { bodyJoin: '-' } }, | ||
{ border: { joinBody: '-' } }, | ||
{ border: { joinLeft: '-' } }, | ||
{ border: { joinRight: '-' } }, | ||
{ border: { joinJoin: '-' } }, | ||
{ columns: { '1': { alignment: 'left' } } }, | ||
{ columns: { '1': { width: 5 } } }, | ||
{ columns: { '1': { wrapWord: true } } }, | ||
{ columns: { '1': { truncate: 1 } } }, | ||
{ columns: { '1': { paddingLeft: 1 } } }, | ||
{ columns: { '1': { paddingRight: 1 } } }, | ||
{ columnDefault: { alignment: 'left' } }, | ||
{ columnDefault: { width: 5 } }, | ||
{ columnDefault: { wrapWord: true } }, | ||
{ columnDefault: { truncate: 1 } }, | ||
{ columnDefault: { paddingLeft: 1 } }, | ||
{ columnDefault: { paddingRight: 1 } }, | ||
{ drawHorizontalLine: function(){} } | ||
], | ||
invalid: [ | ||
{ border: 1 }, | ||
{ border: { unknown: '-' } }, | ||
{ border: { topBody: 1 } }, | ||
{ border: { topJoin: 1 } }, | ||
{ border: { topLeft: 1 } }, | ||
{ border: { topRight: 1 } }, | ||
{ border: { bottomBody: 1 } }, | ||
{ border: { bottomJoin: 1 } }, | ||
{ border: { bottomLeft: 1 } }, | ||
{ border: { bottomRight: 1 } }, | ||
{ border: { bodyLeft: 1 } }, | ||
{ border: { bodyRight: 1 } }, | ||
{ border: { bodyJoin: 1 } }, | ||
{ border: { joinBody: 1 } }, | ||
{ border: { joinLeft: 1 } }, | ||
{ border: { joinRight: 1 } }, | ||
{ border: { joinJoin: 1 } }, | ||
{ columns: 1 }, | ||
{ columns: { a: { width: 5 } } }, | ||
{ columns: { '1': 1 } }, | ||
{ columns: { '1': { unknown: 1 } } }, | ||
{ columns: { '1': { alignment: 1 } } }, | ||
{ columns: { '1': { alignment: '1' } } }, | ||
{ columns: { '1': { width: '5' } } }, | ||
{ columns: { '1': { wrapWord: 1 } } }, | ||
{ columns: { '1': { truncate: '1' } } }, | ||
{ columns: { '1': { paddingLeft: '1' } } }, | ||
{ columns: { '1': { paddingRight: '1' } } }, | ||
{ columnDefault: 1 }, | ||
{ columnDefault: { unknown: 1 } }, | ||
{ columnDefault: { alignment: 1 } }, | ||
{ columnDefault: { alignment: '1' } }, | ||
{ columnDefault: { width: '5' } }, | ||
{ columnDefault: { wrapWord: 1 } }, | ||
{ columnDefault: { truncate: '1' } }, | ||
{ columnDefault: { paddingLeft: '1' } }, | ||
{ columnDefault: { paddingRight: '1' } }, | ||
{ drawHorizontalLine: 1 }, | ||
{ unknown: 1 } | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
expect | ||
} from 'chai'; | ||
import configSamples from './streamConfigSamples'; | ||
import validateConfig from '../dist/validateStreamConfig'; | ||
import configSchema from '../src/schemas/streamConfig.json'; | ||
import Ajv from 'ajv'; | ||
import ajvKeywords from 'ajv-keywords'; | ||
|
||
describe('streamConfig.json schema', () => { | ||
var validate; | ||
|
||
before(() => { | ||
var ajv = new Ajv({allErrors: true}); | ||
ajvKeywords(ajv, 'typeof'); | ||
validate = ajv.compile(configSchema); | ||
}); | ||
|
||
it('should pass validation of valid streamConfig samples', () => { | ||
configSamples.valid.forEach((sample, i) => { | ||
testValid(sample, validate); | ||
testValid(sample, validateConfig); | ||
}); | ||
|
||
function testValid(sample, validate) { | ||
var valid = validate(sample); | ||
if (!valid) console.log(validate.errors); | ||
expect(valid).to.equal(true); | ||
} | ||
}); | ||
|
||
it('should fail validation of invalid streamConfig samples', () => { | ||
configSamples.invalid.forEach((sample, i) => { | ||
testInvalid(sample, validate); | ||
testInvalid(sample, validateConfig); | ||
}); | ||
|
||
function testInvalid(sample, validate) { | ||
var valid = validate(sample); | ||
expect(valid).to.equal(false); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.