--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+const YAML = require('yamljs');\r
+\r
+module.exports = function (convertTo) {\r
+\r
+ const toConvert = ['testDataTemplate'];\r
+\r
+ function convert(p) {\r
+ for (var key in p) {\r
+ if (p.hasOwnProperty(key) && (typeof p[key] === 'object' || typeof p[key] === 'array') ) {\r
+ if (toConvert.indexOf(key) < 0) {\r
+ convert(p[key])\r
+ } else {\r
+ \r
+ if(convertTo == 'yaml'){\r
+ p[key] = YAML.stringify(p[key]);\r
+ }\r
+ if(convertTo == 'json'){\r
+ console.log(key)\r
+ console.log(p[key]);\r
+ p[key] = convertTabs(p[key]);\r
+ p[key] = YAML.parse(p[key]);\r
+ console.log(p[key]);\r
+ }\r
+ }\r
+ }else{\r
+ if (toConvert.indexOf(key) >= 0) {\r
+ \r
+ if(convertTo == 'yaml'){\r
+ p[key] = YAML.stringify(p[key]);\r
+ }\r
+ if(convertTo == 'json'){\r
+ p[key] = convertTabs(p[key]);\r
+ p[key] = YAML.parse(p[key]);\r
+ console.log(p[key])\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ function convertTabs(str){\r
+ if(typeof str === 'string'){\r
+ return str.replace(/\t/g, ' ');\r
+ }\r
+ }\r
+\r
+ return async context => {\r
+ if(context.result)\r
+ convert(context.result);\r
+ if(context.data)\r
+ convert(context.data);\r
+ return context;\r
+ };\r
+};\r