Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80665 views
1
/**
2
* Copyright (c) 2015, Facebook, Inc. All rights reserved.
3
*
4
* This source code is licensed under the BSD-style license found in the
5
* LICENSE file in the root directory of this source tree. An additional grant
6
* of patent rights can be found in the PATENTS file in the same directory.
7
*/
8
'use strict';
9
10
require('mock-modules').autoMockOff();
11
12
describe('JasmineReporter', function() {
13
// modules
14
var JasmineReporter;
15
var colors;
16
17
// other variables
18
var reporter;
19
20
beforeEach(function() {
21
JasmineReporter = require('../JasmineReporter');
22
colors = require('../../lib/colors');
23
24
reporter = new JasmineReporter();
25
});
26
27
describe('colorization', function() {
28
function getRunner(actualResult, expectedResult, passed) {
29
return {
30
suites: function() {
31
return [
32
{
33
parentSuite: null,
34
specs: function() {
35
return [
36
{
37
results: function() {
38
return {
39
getItems: function() {
40
return [
41
{
42
actual: actualResult,
43
expected: expectedResult,
44
matcherName: 'toBe',
45
passed: function() { return passed; },
46
trace: {},
47
type: 'expect',
48
}
49
];
50
},
51
};
52
},
53
},
54
];
55
},
56
suites: function() { return []; },
57
},
58
];
59
},
60
};
61
}
62
63
function errorize(str) {
64
return colors.RED + colors.BOLD + colors.UNDERLINE + str + colors.RESET;
65
}
66
67
function highlight(str) {
68
return colors.RED_BG + str + colors.RESET;
69
}
70
71
pit('colorizes single-line failures using a per-char diff', function() {
72
var runner = getRunner('foo', 'foobar', false);
73
reporter.reportRunnerResults(runner);
74
75
return reporter.getResults().then(function(result) {
76
var message = result.testResults[0].failureMessages[0];
77
expect(message).toBe(
78
errorize('Expected:') + ' \'foo\' ' +
79
errorize('toBe:') + ' \'foo' + highlight('bar') + '\''
80
);
81
});
82
});
83
84
pit('colorizes multi-line failures using a per-line diff', function() {
85
var runner = getRunner('foo\nbar\nbaz', 'foo\nxxx\nbaz', false);
86
reporter.reportRunnerResults(runner);
87
88
return reporter.getResults().then(function(result) {
89
var message = result.testResults[0].failureMessages[0];
90
expect(message).toBe(
91
errorize('Expected:') + ' \'foo\n' + highlight('bar\n') + 'baz\' ' +
92
errorize('toBe:') + ' \'foo\n' + highlight('xxx\n') + 'baz\''
93
);
94
});
95
});
96
});
97
});
98
99