|
| 1 | +/** |
| 2 | + * Copyright (c) 2014-present, 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 | +const runJest = require('../runJest'); |
| 11 | +const skipOnWindows = require('skipOnWindows'); |
| 12 | + |
| 13 | +describe('Custom Reporters Integration', () => { |
| 14 | + skipOnWindows.suite(); |
| 15 | + |
| 16 | + test('valid string format for adding reporters', () => { |
| 17 | + const reporterConfig = { |
| 18 | + reporters: ['<rootDir>/reporters/TestReporter.js'], |
| 19 | + }; |
| 20 | + |
| 21 | + const {status} = runJest('custom_reporters', [ |
| 22 | + '--config', |
| 23 | + JSON.stringify(reporterConfig), |
| 24 | + 'add-test.js', |
| 25 | + ]); |
| 26 | + |
| 27 | + expect(status).toBe(0); |
| 28 | + }); |
| 29 | + |
| 30 | + test('valid array format for adding reporters', () => { |
| 31 | + const reporterConfig = { |
| 32 | + reporters: [ |
| 33 | + ['<rootDir>/reporters/TestReporter.js', {'Dmitrii Abramov': 'Awesome'}], |
| 34 | + ], |
| 35 | + }; |
| 36 | + |
| 37 | + const {status} = runJest('custom_reporters', [ |
| 38 | + '--config', |
| 39 | + JSON.stringify(reporterConfig), |
| 40 | + 'add-test.js', |
| 41 | + ]); |
| 42 | + |
| 43 | + expect(status).toBe(0); |
| 44 | + }); |
| 45 | + |
| 46 | + test('invalid format for adding reporters', () => { |
| 47 | + const reporterConfig = { |
| 48 | + reporters: [[3243242]], |
| 49 | + }; |
| 50 | + |
| 51 | + const {status, stderr} = runJest('custom_reporters', [ |
| 52 | + '--config', |
| 53 | + JSON.stringify(reporterConfig), |
| 54 | + 'add-test.js', |
| 55 | + ]); |
| 56 | + |
| 57 | + expect(status).toBe(1); |
| 58 | + expect(stderr).toMatchSnapshot(); |
| 59 | + }); |
| 60 | + |
| 61 | + test('TestReporter with all tests passing', () => { |
| 62 | + const {stdout, status, stderr} = runJest('custom_reporters', [ |
| 63 | + 'add-test.js', |
| 64 | + ]); |
| 65 | + |
| 66 | + const parsedJSON = JSON.parse(stdout); |
| 67 | + |
| 68 | + expect(status).toBe(0); |
| 69 | + expect(stderr.trim()).toBe(''); |
| 70 | + expect(parsedJSON).toMatchSnapshot(); |
| 71 | + }); |
| 72 | + |
| 73 | + test('TestReporter with all tests failing', () => { |
| 74 | + const {stdout, status, stderr} = runJest('custom_reporters', [ |
| 75 | + 'add-fail-test.js', |
| 76 | + ]); |
| 77 | + |
| 78 | + const parsedJSON = JSON.parse(stdout); |
| 79 | + |
| 80 | + expect(status).toBe(1); |
| 81 | + expect(stderr.trim()).toBe(''); |
| 82 | + expect(parsedJSON).toMatchSnapshot(); |
| 83 | + }); |
| 84 | + |
| 85 | + test('IncompleteReporter for flexibility', () => { |
| 86 | + const {stderr, stdout, status} = runJest('custom_reporters', [ |
| 87 | + '--no-cache', |
| 88 | + '--config', |
| 89 | + JSON.stringify({ |
| 90 | + reporters: ['<rootDir>/reporters/IncompleteReporter.js'], |
| 91 | + }), |
| 92 | + 'add-test.js', |
| 93 | + ]); |
| 94 | + |
| 95 | + expect(status).toBe(0); |
| 96 | + expect(stderr.trim()).toBe(''); |
| 97 | + |
| 98 | + expect(stdout).toMatchSnapshot(); |
| 99 | + }); |
| 100 | +}); |
0 commit comments