@@ -5,20 +5,24 @@ import fs from "fs";
5
5
import yaml from "js-yaml" ;
6
6
import lodash from "lodash" ;
7
7
8
+ import { JSONSchemasInterface } from "../../src/JSONSchemasInterface" ;
8
9
import { combineType , esseType } from "../../src/utils/yaml" ;
9
10
import { YAML_COMBINE_FILE } from "../enums" ;
11
+ import { MOCK_GLOBAL_SCHEMA } from "../fixtures/mock_esse_schema" ;
10
12
11
13
const combineSchema = yaml . DEFAULT_SCHEMA . extend ( [ combineType , esseType ] ) ;
12
14
13
15
describe ( "YAML tag: !combine" , ( ) => {
14
16
let yamlFixture ;
17
+ let parsed ;
15
18
16
19
before ( ( ) => {
20
+ JSONSchemasInterface . registerGlobalSchema ( MOCK_GLOBAL_SCHEMA ) ;
17
21
yamlFixture = fs . readFileSync ( YAML_COMBINE_FILE , "utf8" ) ;
22
+ parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
18
23
} ) ;
19
24
20
25
it ( "should correctly parse a custom !combine tag with forEach and config keys" , ( ) => {
21
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
22
26
const expectedResult = [
23
27
{ name : "mytest" , a : 1 , b : 3 , c : 5 } ,
24
28
{ name : "mytest" , a : 1 , b : 4 , c : 5 } ,
@@ -30,72 +34,57 @@ describe("YAML tag: !combine", () => {
30
34
} ) ;
31
35
32
36
it ( "should correctly parse a custom !combine tag with only a name key" , ( ) => {
33
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
34
37
const expectedResult = [ { name : "mytest" } ] ;
35
-
36
38
expect ( parsed . case2 ) . to . have . deep . members ( expectedResult ) ;
37
39
} ) ;
38
40
39
41
it ( "should correctly parse a custom !combine tag with forEach key and no values" , ( ) => {
40
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
41
42
const expectedResult = [ { name : "mytest" } ] ;
42
-
43
43
expect ( parsed . case3 ) . to . have . deep . members ( expectedResult ) ;
44
44
} ) ;
45
45
46
46
it ( "should correctly parse a custom !combine tag with an empty forEach key and a config key" , ( ) => {
47
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
48
47
const expectedResult = [ { name : "mytest" , c : 5 } ] ;
49
-
50
48
expect ( parsed . case4 ) . to . have . deep . members ( expectedResult ) ;
51
49
} ) ;
52
50
53
51
it ( "should correctly generate name based on template" , ( ) => {
54
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
55
52
const expectedResult = [
56
53
{ name : "A1 with B2 and C5" , a : 1 , b : "two" , c : 5 } ,
57
54
{ name : "A1 with B4 and C5" , a : 1 , b : "four" , c : 5 } ,
58
55
] ;
59
-
60
56
expect ( parsed . case5 ) . to . have . deep . members ( expectedResult ) ;
61
57
} ) ;
62
58
63
59
it ( "should correctly parse a custom !combine tag with additional property" , ( ) => {
64
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
65
60
const expectedResult = [
66
61
{ name : "mytest" , a : 1 , b : 3 } ,
67
62
{ name : "mytest" , a : 1 , b : 4 } ,
68
63
{ name : "additional property" , x : 7 } ,
69
64
] ;
70
-
71
65
expect ( parsed . case6 ) . to . have . deep . members ( expectedResult ) ;
72
66
} ) ;
73
67
74
68
it ( "should correctly parse a custom !combine tag with additional property from !combine tag" , ( ) => {
75
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
76
69
const expectedResult = [
77
70
{ name : "mytest" , a : 1 , b : 3 } ,
78
71
{ name : "mytest" , a : 1 , b : 4 } ,
79
72
{ name : "additional property" , x : 7 , y : 9 } ,
80
73
{ name : "additional property" , x : 8 , y : 9 } ,
81
74
] ;
82
-
83
75
expect ( parsed . case7 ) . to . have . deep . members ( expectedResult ) ;
84
76
} ) ;
85
77
86
78
it ( "should create an additional config when falsy parameter is provided" , ( ) => {
87
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
88
79
const expectedResult = [
89
80
{ name : "A1 with B2" , a : 1 , b : "two" } ,
90
81
{ name : "A1 with B4" , a : 1 , b : "four" } ,
91
82
{ name : "A1" , a : 1 } ,
92
83
] ;
93
-
94
84
expect ( parsed . case8 ) . to . have . deep . members ( expectedResult ) ;
95
85
} ) ;
96
86
97
87
it ( "should create all combinations of n optional parameters" , ( ) => {
98
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
99
88
const expectedResult = [
100
89
{ name : "optional params" , a : 1 } ,
101
90
{ name : "optional params" , a : 1 , b : 2 } ,
@@ -104,19 +93,15 @@ describe("YAML tag: !combine", () => {
104
93
{ name : "optional params" , a : 1 , b : 2 , c : 4 } ,
105
94
{ name : "optional params" , a : 1 , b : 3 , c : 4 } ,
106
95
] ;
107
-
108
96
expect ( parsed . case9 ) . to . have . deep . members ( expectedResult ) ;
109
97
} ) ;
110
98
111
99
it ( "should allow to exclude certain parameter-specified combinations" , ( ) => {
112
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
113
100
const expectedResult = [ { name : "ignore test" , a : { c : 3 } , d : 4 } ] ;
114
-
115
101
expect ( parsed . case10 ) . to . have . deep . members ( expectedResult ) ;
116
102
} ) ;
117
103
118
104
it ( "should use the push action to add value to an array parameter" , ( ) => {
119
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
120
105
const expectedResult = [
121
106
{ name : "push test" , units : [ { a : 1 } , { b : 4 } ] } ,
122
107
{ name : "push test" , units : [ { a : 2 } , { b : 4 } ] } ,
@@ -134,7 +119,6 @@ describe("YAML tag: !combine", () => {
134
119
} ) ;
135
120
136
121
it ( "should use cloned objects when pushing to array" , ( ) => {
137
- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
138
122
const [ config1 , config2 ] = parsed . case12 ;
139
123
140
124
// deleting property in one should not affect the other
0 commit comments