1 | var path = require('path');
|
2 | var chai = require('chai');
|
3 | var expect = chai.expect;
|
4 | var Locator = require('../lib/locator');
|
5 | var testFramework = require('../index');
|
6 |
|
7 | function getTestsFrom(specs) {
|
8 | if (!Array.isArray(specs)) { specs = [specs]; }
|
9 | testFramework.initialize({
|
10 | 'mocha_tests': specs,
|
11 | 'mocha_opts': path.join(specs[0], 'mocha.opts')
|
12 | });
|
13 | return testFramework.iterator({tempDir: path.resolve('.')});
|
14 | }
|
15 |
|
16 | describe('test iterator', function () {
|
17 | var tests;
|
18 |
|
19 | before(function() {
|
20 | tests = getTestsFrom('./test_support/basic');
|
21 | });
|
22 |
|
23 | it('finds tests', function () {
|
24 | expect(tests).to.have.length(2);
|
25 | });
|
26 |
|
27 | it('instantiates tests as Locators', function() {
|
28 | expect(tests[0]).to.be.an.instanceOf(Locator);
|
29 | });
|
30 |
|
31 | it('collects details of a test', function() {
|
32 | var test = tests[0];
|
33 | expect(test.name).to.equal('Suite passes');
|
34 | expect(test.title).to.equal('passes');
|
35 | expect(tests[0].filename).to.contain('test_support/basic/spec.js');
|
36 | expect(test.pending).to.be.false;
|
37 | });
|
38 |
|
39 | it('collects pending tests', function() {
|
40 | var test = tests[1];
|
41 | expect(test.title).to.equal('contains pending');
|
42 | expect(test.pending).to.be.true;
|
43 | });
|
44 | });
|
45 |
|
46 | describe('test iterator plus mocha.opts', function() {
|
47 |
|
48 | it('supports coffeescript', function() {
|
49 | var tests = getTestsFrom('./test_support/coffee');
|
50 | expect(tests).to.have.length(2);
|
51 | });
|
52 |
|
53 | it('respects grep option and ignores non-matching', function() {
|
54 | var tests = getTestsFrom('./test_support/grep');
|
55 | expect(tests).to.have.length(3);
|
56 | });
|
57 |
|
58 | it('supports recursive collection', function() {
|
59 | var tests = getTestsFrom('./test_support/recursive');
|
60 | expect(tests).to.have.length(4);
|
61 | });
|
62 | });
|