UNPKG

844 BJavaScriptView Raw
1/*!
2 * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
3 */
4
5import {stringLiteral} from 'babel-types';
6import template from 'babel-template';
7
8const makeDescribeBlock = template(`
9 describe(DESCRIBED_THING, function() {
10 IT_BLOCK
11 });
12`);
13
14const makeItBlock = template(`
15 it(DOES_A_THING, function() {
16 STATEMENTS
17 });
18`);
19
20/**
21 * Wraps a test case in a Mocha it-block
22 * @param {Object} a
23 * @param {string} a.name
24 * @param {Object} a.testCase
25 * @returns {[type]}
26 */
27export default function generateSpec(a) {
28 let itLine = a.name;
29 if (a.type.toLowerCase().includes('function')) {
30 itLine += '()';
31 }
32
33 const d = makeDescribeBlock({
34 DESCRIBED_THING: stringLiteral(a.filename),
35 IT_BLOCK: makeItBlock({
36 DOES_A_THING: stringLiteral(itLine),
37 STATEMENTS: a.testCase
38 })
39 });
40
41 return d;
42}