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