|
9 | 9 | */ |
10 | 10 | 'use strict'; |
11 | 11 |
|
| 12 | +const {stripJestVersion} = require('../utils'); |
12 | 13 | const runJest = require('../runJest'); |
13 | 14 | const fs = require('fs'); |
14 | 15 | const path = require('path'); |
15 | 16 |
|
16 | | -describe('Coverage Report', () => { |
17 | | - it('outputs coverage report', () => { |
18 | | - const result = runJest('coverage_report', ['--coverage']); |
19 | | - const stdout = result.stdout.toString(); |
| 17 | +it('outputs coverage report', () => { |
| 18 | + const {stdout, status} = runJest('coverage_report', ['--coverage']); |
| 19 | + const coverageDir = path.resolve(__dirname, '../coverage_report/coverage'); |
20 | 20 |
|
21 | | - const coverageDir = path.resolve(__dirname, '../coverage_report/coverage'); |
22 | | - expect(stdout).toMatch(/All files.*100.*100.*100.*100/); |
23 | | - expect(stdout).not.toMatch(/^.+__tests__.+\|.+\|.+\|.+\|/gm); |
24 | | - expect(stdout).not.toMatch(/^.+__mocks__.+\|.+\|.+\|.+\|/gm); |
| 21 | + // should be no `setup.file` in the coverage report. It's ignored |
| 22 | + expect(stripJestVersion(stdout)).toMatchSnapshot(); |
25 | 23 |
|
26 | | - // Make sure `coveragePathIgnorePatterns` works |
27 | | - expect(stdout).not.toMatch('setup.js'); |
| 24 | + expect(() => fs.accessSync(coverageDir, fs.F_OK)).not.toThrow(); |
| 25 | + expect(status).toBe(0); |
| 26 | +}); |
| 27 | + |
| 28 | +it('collects coverage only from specified files', () => { |
| 29 | + const {stdout} = runJest('coverage_report', [ |
| 30 | + '--coverage', |
| 31 | + '--collectCoverageFrom', // overwrites the one in package.json |
| 32 | + 'setup.js', |
| 33 | + ]); |
28 | 34 |
|
29 | | - // this will throw if the coverage directory is not there |
30 | | - fs.accessSync(coverageDir, fs.F_OK); |
31 | | - expect(result.status).toBe(0); |
32 | | - }); |
| 35 | + // Coverage report should only have `setup.js` coverage info |
| 36 | + expect(stripJestVersion(stdout)).toMatchSnapshot(); |
33 | 37 | }); |
0 commit comments