Skip to content

Commit e2a9ae9

Browse files
committed
Library schema validation plus other tests.
1 parent 7fcc6f7 commit e2a9ae9

File tree

6 files changed

+183
-0
lines changed

6 files changed

+183
-0
lines changed

package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
"chai": "^4.1.2",
1919
"chai-arrays": "^2.0.0",
2020
"chai-as-promised": "^7.1.1",
21+
"chai-json-schema": "^1.5.0",
2122
"clipboard-polyfill": "^2.4.6",
2223
"codemirror": "^5.33.0",
24+
"deep-freeze": "0.0.1",
2325
"flipclock": "^0.7.8",
2426
"grunt": "^1.0.1",
2527
"grunt-cli": "^1.2.0",
@@ -50,6 +52,7 @@
5052
"source-map-support": "^0.5.3",
5153
"stylus": "^0.54.5",
5254
"tippy.js": "^2.3.0",
55+
"tv4-formats": "^3.0.3",
5356
"uglifyjs-webpack-plugin": "^1.1.6",
5457
"web-ext": "^2.4.0",
5558
"webpack": "^4.1.0",

test/unit/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'source-map-support/register';
22

33
import './utils.js';
4+
import './libraries.js';
45
import './editor';

test/unit/libraries.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import chai from 'chai';
2+
import chaiJsonSchema from 'chai-json-schema';
3+
import deepFreeze from 'deep-freeze';
4+
import formats from 'tv4-formats';
5+
6+
import getLanguages from
7+
'../../views/website/libraries/support/get-languages.js';
8+
import languageSchema from
9+
'../../views/website/libraries/support/language-schema.js';
10+
11+
chai.use(chaiJsonSchema);
12+
chai.should();
13+
chai.tv4.addFormat(formats);
14+
15+
describe('Libraries', function() {
16+
const languages = deepFreeze(getLanguages());
17+
18+
it('Each language has a unique name', function() {
19+
const names = new Set();
20+
21+
for(const lang of languages) {
22+
names.has(lang.name).should.be.false;
23+
names.add(lang.name);
24+
}
25+
});
26+
27+
it('uniqueClass is unique for each language', function() {
28+
const classes = new Set();
29+
30+
for(const lang of languages) {
31+
classes.has(lang.uniqueClass).should.be.false;
32+
classes.add(lang.uniqueClass);
33+
}
34+
});
35+
36+
it('Have a correct schema', function() {
37+
for(const lang of languages) {
38+
lang.should.be.jsonSchema(languageSchema);
39+
}
40+
});
41+
});
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
module.exports = {
2+
type: 'object',
3+
required: ['name', 'uniqueClass', 'image', 'bgColor', 'libs'],
4+
properties: {
5+
name: {
6+
type: 'string',
7+
minLength: 1,
8+
},
9+
uniqueClass: {
10+
type: 'string',
11+
minLength: 1,
12+
// Not entirely correct, but good enough
13+
pattern: /[a-zA-Z_][\w\-]*/
14+
},
15+
image: {
16+
type: 'string',
17+
minLength: 1,
18+
pattern: /\/img\/.*/
19+
},
20+
bgColor: {
21+
type: 'string',
22+
minLength: 1
23+
},
24+
libs: {
25+
type: 'array',
26+
uniqueItems: true,
27+
items: {
28+
type: 'object',
29+
required: ['minimumVersion', 'support', 'authorUrl', 'authorName',
30+
'gitHubRepoPath', 'repoUrl', 'installCommandHtml'],
31+
properties: {
32+
minimumVersion: {
33+
type: ['null', 'string'],
34+
minLength: 1
35+
},
36+
authorUrl: {
37+
type: ['null', 'string'],
38+
minLength: 1,
39+
// Format validator fails on null values, sigh.
40+
//format: 'url'
41+
},
42+
authorName: {
43+
type: 'string',
44+
minLength: 1
45+
},
46+
gitHubRepoPath: {
47+
type: ['null', 'string'],
48+
minLength: 1,
49+
// Not entirely correct, but good enough
50+
pattern: /.*\/.*/
51+
},
52+
repoUrl: {
53+
type: 'string',
54+
minLength: 1,
55+
format: 'url'
56+
},
57+
installCommandHtml: {
58+
type: 'string',
59+
minLength: 1
60+
},
61+
support: {
62+
type: 'object',
63+
required: ['sign', 'verify', 'iss', 'sub', 'aud', 'exp', 'nbf',
64+
'iat', 'jti', 'hs256', 'hs384', 'hs512', 'rs256',
65+
'rs384', 'rs512', 'es256', 'es384', 'es512'],
66+
properties: {
67+
sign: { type: 'boolean' },
68+
verify: { type: 'boolean' },
69+
iss: { type: 'boolean' },
70+
sub: { type: 'boolean' },
71+
aud: { type: 'boolean' },
72+
exp: { type: 'boolean' },
73+
nbf: { type: 'boolean' },
74+
iat: { type: 'boolean' },
75+
jti: { type: 'boolean' },
76+
hs256: { type: 'boolean' },
77+
hs384: { type: 'boolean' },
78+
hs512: { type: 'boolean' },
79+
rs256: { type: 'boolean' },
80+
rs384: { type: 'boolean' },
81+
rs512: { type: 'boolean' },
82+
es256: { type: 'boolean' },
83+
es384: { type: 'boolean' },
84+
es512: { type: 'boolean' },
85+
}
86+
}
87+
}
88+
}
89+
}
90+
}
91+
};

webpack.website-unit-tests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ module.exports = merge(common, {
1212
path: __dirname + '/dist/test'
1313
},
1414
target: 'node',
15+
node: {
16+
__dirname: true
17+
},
1518
module: {
1619
rules: [{
1720
test: /\.js$/,

0 commit comments

Comments
 (0)