1 |
|
2 | "use strict";
|
3 |
|
4 | var fs = require("fs");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function getTests(suite) {
|
11 | var tests = [];
|
12 |
|
13 | suite.tests.forEach(function (t) {
|
14 | tests.push({
|
15 | file: t.file,
|
16 | title: t.title,
|
17 | fullTitle: t.fullTitle(),
|
18 | pending: t.pending
|
19 | });
|
20 | });
|
21 |
|
22 | suite.suites.forEach(function (s) {
|
23 | tests = tests.concat(getTests(s));
|
24 | });
|
25 |
|
26 | return tests;
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | module.exports = function (runner, options) {
|
33 | var outputPath = process.env.MOCHA_CAPTURE_PATH;
|
34 | if (!outputPath) {
|
35 | throw new Error("Environment variable MOCHA_CAPTURE_PATH must be defined");
|
36 | }
|
37 |
|
38 |
|
39 | runner.run = function (done) {
|
40 | done();
|
41 | };
|
42 |
|
43 |
|
44 | var tests = getTests(runner.suite);
|
45 |
|
46 |
|
47 | if (options.grep) {
|
48 | tests = tests.filter(function (t) {
|
49 | return t.fullTitle.match(options.grep);
|
50 | });
|
51 | }
|
52 |
|
53 | fs.writeFileSync(process.env.MOCHA_CAPTURE_PATH, JSON.stringify(tests));
|
54 | };
|