File tree Expand file tree Collapse file tree 7 files changed +237
-5
lines changed Expand file tree Collapse file tree 7 files changed +237
-5
lines changed Original file line number Diff line number Diff line change 1
1
name : Test
2
+
2
3
on :
3
4
push :
4
5
branches : [ main ]
17
18
- run : npm run build
18
19
- name : Check schema.json is up-to-date
19
20
run : git diff --exit-code
21
+ - name : Run tests
22
+ run : npm test
Original file line number Diff line number Diff line change 1
1
.DS_Store
2
2
node_modules /
3
+ /test /
Original file line number Diff line number Diff line change
1
+ {
2
+ "schemaVersion" : " 1.0.0" ,
3
+ "readme" : " README.md" ,
4
+ "modules" : [
5
+ {
6
+ "kind" : " javascript-module" ,
7
+ "path" : " my-project/my-element.js" ,
8
+ "declarations" : [
9
+ {
10
+ "kind" : " class" ,
11
+ "description" : " This is the description of the class" ,
12
+ "name" : " MyElement" ,
13
+ "members" : [
14
+ {
15
+ "kind" : " field" ,
16
+ "name" : " disabled"
17
+ },
18
+ {
19
+ "kind" : " method" ,
20
+ "name" : " fire"
21
+ }
22
+ ],
23
+ "events" : [
24
+ {
25
+ "name" : " disabled-changed" ,
26
+ "type" : {
27
+ "text" : " Event"
28
+ }
29
+ }
30
+ ],
31
+ "attributes" : [
32
+ {
33
+ "name" : " disabled"
34
+ }
35
+ ],
36
+ "superclass" : {
37
+ "name" : " HTMLElement"
38
+ },
39
+ "tagName" : " my-element" ,
40
+ "customElement" : true
41
+ }
42
+ ],
43
+ "exports" : [
44
+ {
45
+ "kind" : " js" ,
46
+ "name" : " MyElement" ,
47
+ "declaration" : {
48
+ "name" : " MyElement" ,
49
+ "module" : " my-project/my-element.js"
50
+ }
51
+ },
52
+ {
53
+ "kind" : " custom-element-definition" ,
54
+ "name" : " my-element" ,
55
+ "declaration" : {
56
+ "name" : " MyElement" ,
57
+ "module" : " my-project/my-element.js"
58
+ }
59
+ }
60
+ ]
61
+ }
62
+ ]
63
+ }
Original file line number Diff line number Diff line change 2
2
"name" : " custom-elements-manifest" ,
3
3
"version" : " 1.0.0" ,
4
4
"description" : " A file format for describing custom elements" ,
5
+ "type" : " module" ,
5
6
"main" : " schema.json" ,
6
7
"scripts" : {
7
- "format" : " prettier schema.d.ts --write" ,
8
- "build" : " typescript-json-schema --required --ignoreErrors schema.d.ts -o schema.json Package" ,
8
+ "format" : " prettier schema.d.ts src/**/*.ts --write" ,
9
+ "build" : " npm run build:ts && npm run build:schema" ,
10
+ "build:ts" : " tsc" ,
11
+ "build:schema" : " typescript-json-schema --required --ignoreErrors schema.d.ts -o schema.json Package" ,
12
+ "test" : " node ./test/schema_test.js" ,
9
13
"prepublishOnly" : " npm run build"
10
14
},
11
15
"files" : [
24
28
},
25
29
"homepage" : " https://github.com/webcomponents/custom-elements-manifest#readme" ,
26
30
"devDependencies" : {
31
+ "jsonschema" : " ^1.4.0" ,
27
32
"prettier" : " ^2.2.1" ,
28
33
"typescript" : " ~4.5.5" ,
29
- "typescript-json-schema" : " ^0.53.0"
34
+ "typescript-json-schema" : " ^0.53.0" ,
35
+ "uvu" : " ^0.5.3"
30
36
}
31
37
}
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2022 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ * Code distributed by Google as part of the polymer project is also
8
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ */
10
+
11
+ import { test } from 'uvu' ;
12
+ import * as assert from 'uvu/assert' ;
13
+ import { Validator } from 'jsonschema' ;
14
+ import * as fs from 'fs/promises' ;
15
+
16
+ const schema = JSON . parse ( await fs . readFile ( './schema.json' , 'utf-8' ) ) ;
17
+
18
+ test ( 'Schema tests' , async ( ) => {
19
+ // TODO: read multiple test files
20
+ const example = JSON . parse (
21
+ await fs . readFile ( './examples/simple-element.json' , 'utf-8' )
22
+ ) ;
23
+ const validator = new Validator ( ) ;
24
+ const result = validator . validate ( example , schema ) ;
25
+ assert . is ( result . errors . length , 0 ) ;
26
+ } ) ;
27
+
28
+ test . run ( ) ;
Original file line number Diff line number Diff line change 6
6
"declaration" : true ,
7
7
"declarationMap" : true ,
8
8
"sourceMap" : true ,
9
+ "rootDir" : " ./src/" ,
9
10
"outDir" : " ./" ,
10
11
"strict" : true ,
11
12
"noUnusedLocals" : true ,
14
15
"noFallthroughCasesInSwitch" : true ,
15
16
"moduleResolution" : " node" ,
16
17
},
17
- "include" : [" *.ts" ],
18
+ "include" : [" schema.d.ts " , " src/**/ *.ts" ],
18
19
"exclude" : []
19
20
}
You can’t perform that action at this time.
0 commit comments