File tree Expand file tree Collapse file tree 4 files changed +117
-0
lines changed Expand file tree Collapse file tree 4 files changed +117
-0
lines changed Original file line number Diff line number Diff line change 8
8
"start" : " tsc --watch" ,
9
9
"build" : " tsc" ,
10
10
"test" : " jest" ,
11
+ "test:coverage" : " jest --coverage" ,
11
12
"test:watch" : " jest --watch" ,
12
13
"lint" : " eslint --max-warnings 0 --config .eslintrc ." ,
13
14
"lint:fix" : " eslint --max-warnings 0 --config .eslintrc . --fix" ,
Original file line number Diff line number Diff line change
1
+ import { Output , DiffOutputItem } from './types' ;
2
+
3
+ /**
4
+ * Implements functions to deal with the diff.
5
+ * @class
6
+ * @returns {AsyncAPIDiff }
7
+ */
8
+ export default class AsyncAPIDiff {
9
+ private output : Output ;
10
+
11
+ constructor ( output : string ) {
12
+ // output is a stringified JSON
13
+ this . output = JSON . parse ( output ) ;
14
+ }
15
+
16
+ /**
17
+ * @returns All the breaking changes
18
+ */
19
+ breaking ( ) : DiffOutputItem [ ] {
20
+ return this . output . changes . filter ( ( diff ) => diff . type === 'breaking' ) ;
21
+ }
22
+
23
+ /**
24
+ * @returns All the non-breaking changes
25
+ */
26
+ nonBreaking ( ) : DiffOutputItem [ ] {
27
+ return this . output . changes . filter ( ( diff ) => diff . type === 'non-breaking' ) ;
28
+ }
29
+
30
+ /**
31
+ * @returns All the unclassified changes
32
+ */
33
+ unclassified ( ) : DiffOutputItem [ ] {
34
+ return this . output . changes . filter ( ( diff ) => diff . type === 'unclassified' ) ;
35
+ }
36
+
37
+ /**
38
+ * @returns The JSON output
39
+ */
40
+ getOutput ( ) : Output {
41
+ return this . output ;
42
+ }
43
+ }
Original file line number Diff line number Diff line change
1
+ import AsyncAPIDiff from '../src/asyncapidiff' ;
2
+
3
+ import {
4
+ breakingChanges ,
5
+ inputDiff ,
6
+ nonbreakingChanges ,
7
+ unclassifiedChanges ,
8
+ } from './fixtures/asyncapidiff.fixtures' ;
9
+
10
+ describe ( 'AsyncAPIDiff wrapper' , ( ) => {
11
+ test ( 'checks the instance' , ( ) => {
12
+ expect ( new AsyncAPIDiff ( JSON . stringify ( inputDiff ) ) ) . toBeInstanceOf (
13
+ AsyncAPIDiff
14
+ ) ;
15
+ } ) ;
16
+
17
+ test ( 'checks the original output' , ( ) => {
18
+ const diff = new AsyncAPIDiff ( JSON . stringify ( inputDiff ) ) ;
19
+ expect ( diff . getOutput ( ) ) . toEqual ( inputDiff ) ;
20
+ } ) ;
21
+
22
+ test ( 'returns breaking changes' , ( ) => {
23
+ const diff = new AsyncAPIDiff ( JSON . stringify ( inputDiff ) ) ;
24
+ expect ( diff . breaking ( ) ) . toEqual ( breakingChanges ) ;
25
+ } ) ;
26
+
27
+ test ( 'returns non-breaking changes' , ( ) => {
28
+ const diff = new AsyncAPIDiff ( JSON . stringify ( inputDiff ) ) ;
29
+ expect ( diff . nonBreaking ( ) ) . toEqual ( nonbreakingChanges ) ;
30
+ } ) ;
31
+
32
+ test ( 'returns unclassified changes' , ( ) => {
33
+ const diff = new AsyncAPIDiff ( JSON . stringify ( inputDiff ) ) ;
34
+ expect ( diff . unclassified ( ) ) . toEqual ( unclassifiedChanges ) ;
35
+ } ) ;
36
+ } ) ;
Original file line number Diff line number Diff line change
1
+ export const inputDiff = {
2
+ changes : [
3
+ {
4
+ type : 'breaking' ,
5
+ path : '/servers' ,
6
+ } ,
7
+ {
8
+ type : 'non-breaking' ,
9
+ path : '/channels' ,
10
+ } ,
11
+ {
12
+ type : 'unclassified' ,
13
+ path : '/info' ,
14
+ } ,
15
+ ] ,
16
+ } ;
17
+
18
+ export const breakingChanges = [
19
+ {
20
+ type : 'breaking' ,
21
+ path : '/servers' ,
22
+ } ,
23
+ ] ;
24
+
25
+ export const nonbreakingChanges = [
26
+ {
27
+ type : 'non-breaking' ,
28
+ path : '/channels' ,
29
+ } ,
30
+ ] ;
31
+
32
+ export const unclassifiedChanges = [
33
+ {
34
+ type : 'unclassified' ,
35
+ path : '/info' ,
36
+ } ,
37
+ ] ;
You can’t perform that action at this time.
0 commit comments