1 |
|
2 |
|
3 |
|
4 |
|
5 | import {stringLiteral} from 'babel-types';
|
6 | import template from 'babel-template';
|
7 |
|
8 | const makeDescribeBlock = template(`
|
9 | describe(DESCRIBED_THING, function() {
|
10 | IT_BLOCK
|
11 | });
|
12 | `);
|
13 |
|
14 | const makeItBlock = template(`
|
15 | it(DOES_A_THING, function() {
|
16 | STATEMENTS
|
17 | });
|
18 | `);
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | export 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 | }
|