@@ -5,20 +5,24 @@ import fs from "fs";
55import yaml from "js-yaml" ;
66import lodash from "lodash" ;
77
8+ import { JSONSchemasInterface } from "../../src/JSONSchemasInterface" ;
89import { combineType , esseType } from "../../src/utils/yaml" ;
910import { YAML_COMBINE_FILE } from "../enums" ;
11+ import { MOCK_GLOBAL_SCHEMA } from "../fixtures/mock_esse_schema" ;
1012
1113const combineSchema = yaml . DEFAULT_SCHEMA . extend ( [ combineType , esseType ] ) ;
1214
1315describe ( "YAML tag: !combine" , ( ) => {
1416 let yamlFixture ;
17+ let parsed ;
1518
1619 before ( ( ) => {
20+ JSONSchemasInterface . registerGlobalSchema ( MOCK_GLOBAL_SCHEMA ) ;
1721 yamlFixture = fs . readFileSync ( YAML_COMBINE_FILE , "utf8" ) ;
22+ parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
1823 } ) ;
1924
2025 it ( "should correctly parse a custom !combine tag with forEach and config keys" , ( ) => {
21- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
2226 const expectedResult = [
2327 { name : "mytest" , a : 1 , b : 3 , c : 5 } ,
2428 { name : "mytest" , a : 1 , b : 4 , c : 5 } ,
@@ -30,72 +34,57 @@ describe("YAML tag: !combine", () => {
3034 } ) ;
3135
3236 it ( "should correctly parse a custom !combine tag with only a name key" , ( ) => {
33- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
3437 const expectedResult = [ { name : "mytest" } ] ;
35-
3638 expect ( parsed . case2 ) . to . have . deep . members ( expectedResult ) ;
3739 } ) ;
3840
3941 it ( "should correctly parse a custom !combine tag with forEach key and no values" , ( ) => {
40- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
4142 const expectedResult = [ { name : "mytest" } ] ;
42-
4343 expect ( parsed . case3 ) . to . have . deep . members ( expectedResult ) ;
4444 } ) ;
4545
4646 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 } ) ;
4847 const expectedResult = [ { name : "mytest" , c : 5 } ] ;
49-
5048 expect ( parsed . case4 ) . to . have . deep . members ( expectedResult ) ;
5149 } ) ;
5250
5351 it ( "should correctly generate name based on template" , ( ) => {
54- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
5552 const expectedResult = [
5653 { name : "A1 with B2 and C5" , a : 1 , b : "two" , c : 5 } ,
5754 { name : "A1 with B4 and C5" , a : 1 , b : "four" , c : 5 } ,
5855 ] ;
59-
6056 expect ( parsed . case5 ) . to . have . deep . members ( expectedResult ) ;
6157 } ) ;
6258
6359 it ( "should correctly parse a custom !combine tag with additional property" , ( ) => {
64- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
6560 const expectedResult = [
6661 { name : "mytest" , a : 1 , b : 3 } ,
6762 { name : "mytest" , a : 1 , b : 4 } ,
6863 { name : "additional property" , x : 7 } ,
6964 ] ;
70-
7165 expect ( parsed . case6 ) . to . have . deep . members ( expectedResult ) ;
7266 } ) ;
7367
7468 it ( "should correctly parse a custom !combine tag with additional property from !combine tag" , ( ) => {
75- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
7669 const expectedResult = [
7770 { name : "mytest" , a : 1 , b : 3 } ,
7871 { name : "mytest" , a : 1 , b : 4 } ,
7972 { name : "additional property" , x : 7 , y : 9 } ,
8073 { name : "additional property" , x : 8 , y : 9 } ,
8174 ] ;
82-
8375 expect ( parsed . case7 ) . to . have . deep . members ( expectedResult ) ;
8476 } ) ;
8577
8678 it ( "should create an additional config when falsy parameter is provided" , ( ) => {
87- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
8879 const expectedResult = [
8980 { name : "A1 with B2" , a : 1 , b : "two" } ,
9081 { name : "A1 with B4" , a : 1 , b : "four" } ,
9182 { name : "A1" , a : 1 } ,
9283 ] ;
93-
9484 expect ( parsed . case8 ) . to . have . deep . members ( expectedResult ) ;
9585 } ) ;
9686
9787 it ( "should create all combinations of n optional parameters" , ( ) => {
98- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
9988 const expectedResult = [
10089 { name : "optional params" , a : 1 } ,
10190 { name : "optional params" , a : 1 , b : 2 } ,
@@ -104,19 +93,15 @@ describe("YAML tag: !combine", () => {
10493 { name : "optional params" , a : 1 , b : 2 , c : 4 } ,
10594 { name : "optional params" , a : 1 , b : 3 , c : 4 } ,
10695 ] ;
107-
10896 expect ( parsed . case9 ) . to . have . deep . members ( expectedResult ) ;
10997 } ) ;
11098
11199 it ( "should allow to exclude certain parameter-specified combinations" , ( ) => {
112- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
113100 const expectedResult = [ { name : "ignore test" , a : { c : 3 } , d : 4 } ] ;
114-
115101 expect ( parsed . case10 ) . to . have . deep . members ( expectedResult ) ;
116102 } ) ;
117103
118104 it ( "should use the push action to add value to an array parameter" , ( ) => {
119- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
120105 const expectedResult = [
121106 { name : "push test" , units : [ { a : 1 } , { b : 4 } ] } ,
122107 { name : "push test" , units : [ { a : 2 } , { b : 4 } ] } ,
@@ -134,7 +119,6 @@ describe("YAML tag: !combine", () => {
134119 } ) ;
135120
136121 it ( "should use cloned objects when pushing to array" , ( ) => {
137- const parsed = yaml . load ( yamlFixture , { schema : combineSchema } ) ;
138122 const [ config1 , config2 ] = parsed . case12 ;
139123
140124 // deleting property in one should not affect the other
0 commit comments