react / wstein / node_modules / jest-cli / node_modules / node-haste / __tests__ / MessageList-test.js
80668 views/**1* Copyright 2013 Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*15* @emails [email protected] [email protected]16*/1718describe("MessageList", function() {19var MessageList = require('../lib/MessageList');20var cli = require('../lib/cli');2122it('should add different types of messages', function() {23var list = new MessageList();24list.addMessage('foo.js', 'js', 'message');25list.addWarning('foo.js', 'js', 'warning');26list.addError('foo.js', 'js', 'error');27list.addClowntownError('foo.js', 'js', 'clowntown');28expect(list.length).toBe(4);29});3031it('should render error with bold', function() {32var list = new MessageList();33list.addWarning('foo.js', 'js', 'warning text');34expect(list.render()).toContain('warning text');35expect(list.render()).toContain(cli.bold('Warning'));36});3738it('should render error with awesome', function() {39var list = new MessageList();40list.addError('foo.js', 'js', 'error text');41expect(list.render()).toContain('error text');42expect(list.render()).toContain(cli.awesome('Error'));43});4445it('should render error with awesome', function() {46var list = new MessageList();47list.addClowntownError('foo.js', 'js', 'clowntown');48expect(list.render()).toContain('clowntown');49expect(list.render()).toContain(cli.awesome('Error'));50});5152it('should group messages by file', function() {53var list = new MessageList();54list.addError('foo.js', 'js', 'error');55list.addClowntownError('foo.js', 'js', 'clowntown');56expect(list.render()).toContain(cli.bold('Messages'));57});5859it('expected to merge lists', function() {60var list1 = new MessageList();61list1.addWarning('a', 'b', '1');62list1.addError('a', 'b', '2');6364var list2 = new MessageList();65list2.addClowntownError('a', 'b', '3');6667list2.merge(list1);68expect(list2.length).toBe(3);69});7071it('should reuse objects created through the factory', function() {72MessageList.clearCache();73var list = MessageList.create();74list.addWarning('a', 'b', '1');7576list.recycle();77expect(list.length).toBe(0);78expect(MessageList.create()).toBe(list);79});8081it('should serialize a message list', function() {82var list = new MessageList();83list.addMessage('foo.js', 'js', 'message');84list.addWarning('foo.js', 'js', 'warning');85list.addError('foo.js', 'js', 'error text');86list.addClowntownError('foo.js', 'js', 'clowntown');8788list = MessageList.fromObject(89JSON.parse(JSON.stringify(list.toObject())));90expect(list.length).toBe(4);91expect(list.render()).toContain('error text');92expect(list.render()).toContain(cli.awesome('Error'));93});94});959697