Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80668 views
1
/**
2
* Copyright 2013 Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
* @emails [email protected] [email protected]
17
*/
18
19
describe("MessageList", function() {
20
var MessageList = require('../lib/MessageList');
21
var cli = require('../lib/cli');
22
23
it('should add different types of messages', function() {
24
var list = new MessageList();
25
list.addMessage('foo.js', 'js', 'message');
26
list.addWarning('foo.js', 'js', 'warning');
27
list.addError('foo.js', 'js', 'error');
28
list.addClowntownError('foo.js', 'js', 'clowntown');
29
expect(list.length).toBe(4);
30
});
31
32
it('should render error with bold', function() {
33
var list = new MessageList();
34
list.addWarning('foo.js', 'js', 'warning text');
35
expect(list.render()).toContain('warning text');
36
expect(list.render()).toContain(cli.bold('Warning'));
37
});
38
39
it('should render error with awesome', function() {
40
var list = new MessageList();
41
list.addError('foo.js', 'js', 'error text');
42
expect(list.render()).toContain('error text');
43
expect(list.render()).toContain(cli.awesome('Error'));
44
});
45
46
it('should render error with awesome', function() {
47
var list = new MessageList();
48
list.addClowntownError('foo.js', 'js', 'clowntown');
49
expect(list.render()).toContain('clowntown');
50
expect(list.render()).toContain(cli.awesome('Error'));
51
});
52
53
it('should group messages by file', function() {
54
var list = new MessageList();
55
list.addError('foo.js', 'js', 'error');
56
list.addClowntownError('foo.js', 'js', 'clowntown');
57
expect(list.render()).toContain(cli.bold('Messages'));
58
});
59
60
it('expected to merge lists', function() {
61
var list1 = new MessageList();
62
list1.addWarning('a', 'b', '1');
63
list1.addError('a', 'b', '2');
64
65
var list2 = new MessageList();
66
list2.addClowntownError('a', 'b', '3');
67
68
list2.merge(list1);
69
expect(list2.length).toBe(3);
70
});
71
72
it('should reuse objects created through the factory', function() {
73
MessageList.clearCache();
74
var list = MessageList.create();
75
list.addWarning('a', 'b', '1');
76
77
list.recycle();
78
expect(list.length).toBe(0);
79
expect(MessageList.create()).toBe(list);
80
});
81
82
it('should serialize a message list', function() {
83
var list = new MessageList();
84
list.addMessage('foo.js', 'js', 'message');
85
list.addWarning('foo.js', 'js', 'warning');
86
list.addError('foo.js', 'js', 'error text');
87
list.addClowntownError('foo.js', 'js', 'clowntown');
88
89
list = MessageList.fromObject(
90
JSON.parse(JSON.stringify(list.toObject())));
91
expect(list.length).toBe(4);
92
expect(list.render()).toContain('error text');
93
expect(list.render()).toContain(cli.awesome('Error'));
94
});
95
});
96
97