UNPKG

testx-yaml-parser

Version:

Simple YAML file parser for use with the testx library. Converts a YAML file to testx test script (JSON)

79 lines (71 loc) 2.13 kB
// Generated by CoffeeScript 1.12.7 (function() { var base, findKeywordLines, fs, parse, pkg, yaml; yaml = require('js-yaml'); fs = require('fs'); pkg = require('../package.json'); if ((base = String.prototype).startsWith == null) { base.startsWith = function(s) { return this.slice(0, s.length) === s; }; } findKeywordLines = function(lines) { var i, j, len, line, results; results = []; for (i = j = 0, len = lines.length; j < len; i = ++j) { line = lines[i]; if (line.startsWith('- ')) { results.push({ line: i + 1 }); } } return results; }; module.exports = { name: pkg.name, version: pkg.version, extensions: ['testx', 'yaml', 'yml'], parseFile: function(file) { var script; script = parse(fs.readFileSync(file, 'utf8')); script.source = { file: file }; return script; }, parse: parse = function(content) { var _ignore, all, args, comment, doc, keyword, kwd, lines, row, step, steps; lines = findKeywordLines(content.split('\n')); doc = yaml.safeLoad(content); steps = (function() { var j, len, ref, ref1, results; results = []; for (row = j = 0, len = doc.length; j < len; row = ++j) { step = doc[row]; if (typeof step === 'object') { keyword = Object.keys(step)[0]; args = step[keyword]; } else { keyword = step; args = []; } ref = keyword.match(/^(.*?)(\[(.*)\])?$/), all = ref[0], kwd = ref[1], _ignore = ref[2], comment = ref[3]; results.push({ name: (kwd != null ? kwd.trim() : void 0) || keyword, meta: { 'Full name': keyword, Comment: (comment != null ? comment.trim() : void 0) || '', Row: ((ref1 = lines[row]) != null ? ref1.line : void 0) || row }, "arguments": args }); } return results; })(); return { steps: steps }; } }; }).call(this);