UNPKG

2.82 kBSource Map (JSON)View Raw
1{"version":3,"sources":["transform.js"],"names":["transform","assertionStatementTemplate","comment","name","filename","type","ast","enter","path","node","trailingComments","assertions","map","makeAsserter","length","replaceWith","ORIGINAL","ASSERTIONS","testCase","value"],"mappings":";;;;;;;;;;kBA6BwBA,S;;AAzBxB;;;;AACA;;;;AACA;;;;AACA;;;;AAEA;;;;AAKA,IAAMC,6BAA6B,8HAAnC;;AAOA;;;;;;;;AArBA;;;;AA6Be,SAASD,SAAT,OAEZ;AAAA,MADDE,OACC,QADDA,OACC;AAAA,MADQC,IACR,QADQA,IACR;AAAA,MADcC,QACd,QADcA,QACd;AAAA,MADwBC,IACxB,QADwBA,IACxB;;AACD,MAAMC,MAAM,qBAAMJ,OAAN,CAAZ;;AAEA,+BAASI,GAAT,EAAc;AACZC,SADY,iBACNC,IADM,EACA;AACV,UAAIA,KAAKC,IAAL,CAAUC,gBAAd,EAAgC;AAC9B,YAAMC,aAAaH,KAAKC,IAAL,CAAUC,gBAAV,CAA2BE,GAA3B,CAA+BC,YAA/B,CAAnB;AACA,YAAIF,WAAWG,MAAf,EAAuB;AACrB,wCAAuBN,KAAKC,IAA5B,EAAkC,kBAAlC;;AAEAD,eAAKO,WAAL,CAAiBd,2BAA2B;AAC1Ce,sBAAUR,KAAKC,IAD2B;AAE1CQ,wBAAYN;AAF8B,WAA3B,CAAjB;AAID;AACF;AACF;AAbW,GAAd;;AAgBA,SAAO,6BAAa;AAClBO,cAAUZ,GADQ;AAElBH,cAFkB;AAGlBC,sBAHkB;AAIlBC;AAJkB,GAAb,CAAP;AAMD;;AAED;;;;;AAKA,SAASQ,YAAT,CAAsBX,OAAtB,EAA+B;AAC7B,MAAI,mBAAqBA,QAAQiB,KAA7B,CAAJ,EAAyC;AACvC,WAAO,oBAAsBjB,QAAQiB,KAA9B,CAAP;AACD;;AAED,SAAO,IAAP;AACD","file":"transform.js","sourcesContent":["/*!\n * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport parse from './parse';\nimport template from 'babel-template';\nimport traverse from 'babel-traverse';\nimport generateSpec from './mocha-template';\n\nimport {\n build as buildLiteralAssertion,\n test as literalAssertionTest\n} from './assertions/literal';\n\nconst assertionStatementTemplate = template(`\n return Promise.resolve(ORIGINAL)\n .then(function(result) {\n ASSERTIONS\n })\n`);\n\n/**\n * @param {Object} options\n * @param {ast} options.comment\n * @param {string} options.name\n * @param {string} options.filename\n * @param {string} options.type\n * @returns {ast}\n */\nexport default function transform({\n comment, name, filename, type\n}) {\n const ast = parse(comment);\n\n traverse(ast, {\n enter(path) {\n if (path.node.trailingComments) {\n const assertions = path.node.trailingComments.map(makeAsserter);\n if (assertions.length) {\n Reflect.deleteProperty(path.node, 'trailingComments');\n\n path.replaceWith(assertionStatementTemplate({\n ORIGINAL: path.node,\n ASSERTIONS: assertions\n }));\n }\n }\n }\n });\n\n return generateSpec({\n testCase: ast,\n name,\n filename,\n type\n });\n}\n\n/**\n * Takes a trailing comment from an example block and changes it to an assertion\n * @param {CommentBlock} comment\n * @returns {ast}\n */\nfunction makeAsserter(comment) {\n if (literalAssertionTest(comment.value)) {\n return buildLiteralAssertion(comment.value);\n }\n\n return null;\n}\n"]}
\No newline at end of file