1 |
|
2 | var jasmineReporters = require("../index");
|
3 |
|
4 | var env, suite, subSuite, subSubSuite,
|
5 | reporter, suiteId=0, specId=0, noop=function(){};
|
6 | function fakeSpec(ste, name) {
|
7 | var s = new jasmine.Spec({
|
8 | env: env,
|
9 | id: specId++,
|
10 | description: name,
|
11 | queueableFn: {fn: noop},
|
12 | });
|
13 | ste.addChild(s);
|
14 | return s;
|
15 | }
|
16 | function fakeSuite(name, parentSuite) {
|
17 | var s = new jasmine.Suite({
|
18 | env: env,
|
19 | id: suiteId++,
|
20 | description: name,
|
21 | parentSuite: parentSuite || jasmine.createSpy("pretend top suite")
|
22 | });
|
23 | if (parentSuite) {
|
24 | parentSuite.addChild(s);
|
25 | }
|
26 | else {
|
27 |
|
28 | env._suites = env._suites || [];
|
29 | env._suites.push(s);
|
30 | }
|
31 | return s;
|
32 | }
|
33 |
|
34 | function setupReporterWithOptions(options) {
|
35 | reporter = new jasmineReporters.TeamCityReporter(options);
|
36 | }
|
37 |
|
38 |
|
39 | function triggerRunnerEvents() {
|
40 | var logs = [];
|
41 | var _stdoutWrite = process.stdout.write;
|
42 | process.stdout.write = function() {
|
43 | logs.push(arguments[0]);
|
44 | };
|
45 | reporter.jasmineStarted();
|
46 | for (var i=0; i<env._suites.length; i++) {
|
47 | var s = env._suites[i];
|
48 | triggerSuiteEvents(s);
|
49 | }
|
50 | reporter.jasmineDone();
|
51 | process.stdout.write = _stdoutWrite;
|
52 | return logs;
|
53 | }
|
54 | function triggerSuiteEvents(ste) {
|
55 | reporter.suiteStarted(ste.result);
|
56 | var thing;
|
57 | for (var i=0; i<ste.children.length; i++) {
|
58 | thing = ste.children[i];
|
59 | if (thing instanceof jasmine.Suite) {
|
60 | triggerSuiteEvents(thing);
|
61 | } else {
|
62 | reporter.specStarted(thing.result);
|
63 | reporter.specDone(thing.result);
|
64 | }
|
65 | }
|
66 | reporter.suiteDone(ste.result);
|
67 | }
|
68 |
|
69 | describe("TeamCityReporter", function(){
|
70 | beforeEach(function(){
|
71 | env = new jasmine.Env();
|
72 | suite = fakeSuite("ParentSuite");
|
73 | subSuite = fakeSuite("SubSuite", suite);
|
74 | subSubSuite = fakeSuite("SubSubSuite", subSuite);
|
75 | fakeSuite("SiblingSuite");
|
76 | var failedSpec = fakeSpec(subSubSuite, "should be failed");
|
77 | failedSpec.result.status = "failed";
|
78 | failedSpec.result.failedExpectations.push({
|
79 | passed: false,
|
80 | message: "Expected true to be false.",
|
81 | expected: false,
|
82 | actual: true,
|
83 | matcherName: "toBe",
|
84 | stack: 'Stack trace! Stack traces are cool & can have "special" characters <3\n\n Neat: yes.'
|
85 | });
|
86 | fakeSpec(subSuite, "should be one level down");
|
87 | fakeSpec(subSubSuite, "(1) should be two levels down");
|
88 | });
|
89 |
|
90 | describe("General behavior", function() {
|
91 | beforeEach(function() {
|
92 | setupReporterWithOptions();
|
93 | this.logs = triggerRunnerEvents();
|
94 | });
|
95 | it("should log testSuiteStarted and testSuiteFinished events", function() {
|
96 |
|
97 | var started = this.logs.filter(l=>l.indexOf("testSuiteStarted") > -1);
|
98 | var finished = this.logs.filter(l=>l.indexOf("testSuiteStarted") > -1);
|
99 | expect(started.length).toBe(4);
|
100 | expect(finished.length).toBe(4);
|
101 | expect(started[0].indexOf("name='ParentSuite'")).toBeGreaterThan(-1);
|
102 | });
|
103 | it("should log testStarted and testFinished events", function() {
|
104 |
|
105 | var started = this.logs.filter(l=>l.indexOf("testStarted") > -1);
|
106 | var finished = this.logs.filter(l=>l.indexOf("testStarted") > -1);
|
107 | expect(started.length).toBe(3);
|
108 | expect(finished.length).toBe(3);
|
109 | expect(started[0].indexOf("name='should be failed'")).toBeGreaterThan(-1);
|
110 | });
|
111 | it("should log testFailed event including reason and stack trace", function() {
|
112 |
|
113 | var failed = this.logs.filter(l=>l.indexOf("testFailed") > -1);
|
114 | expect(failed.length).toBe(1);
|
115 | expect(failed[0].indexOf("name='should be failed'")).toBeGreaterThan(-1);
|
116 | expect(failed[0].indexOf("message='Expected true to be false.'")).toBeGreaterThan(-1);
|
117 | expect(failed[0].indexOf("details='Stack trace! Stack traces are cool")).toBeGreaterThan(-1);
|
118 | });
|
119 | });
|
120 |
|
121 | describe("modifySuiteName", function() {
|
122 | var modification = "-modified";
|
123 | beforeEach(function() {
|
124 | setupReporterWithOptions({modifySuiteName: function(name) { return name + modification; }});
|
125 | this.logs = triggerRunnerEvents();
|
126 | });
|
127 | it("should use the modification for suite names", function() {
|
128 |
|
129 | var started = this.logs.filter(l=>l.indexOf("testSuiteStarted") > -1);
|
130 | started.forEach(e=>expect(e.indexOf(modification)).toBeGreaterThan(-1));
|
131 | expect(started[0].indexOf("name='ParentSuite-modified'")).toBeGreaterThan(-1);
|
132 | });
|
133 | it("should *not* use the modification for spec names", function() {
|
134 |
|
135 | var started = this.logs.filter(l=>l.indexOf("testStarted") > -1);
|
136 | started.forEach(e=>expect(e.indexOf(modification)).toBe(-1));
|
137 | });
|
138 | });
|
139 | });
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|