|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import * as path from 'path'; |
| 9 | +import runJest from '../runJest'; |
| 10 | + |
| 11 | +const DIR = path.resolve(__dirname, '../coverage-provider-v8'); |
| 12 | + |
| 13 | +test('prints coverage with missing sourcemaps', () => { |
| 14 | + const sourcemapDir = path.join(DIR, 'no-sourcemap'); |
| 15 | + |
| 16 | + const {stdout, exitCode} = runJest( |
| 17 | + sourcemapDir, |
| 18 | + ['--coverage', '--coverage-provider', 'odz'], |
| 19 | + {stripAnsi: true}, |
| 20 | + ); |
| 21 | + |
| 22 | + expect(exitCode).toBe(0); |
| 23 | + expect(stdout).toMatchSnapshot(); |
| 24 | +}); |
| 25 | + |
| 26 | +test('prints coverage with empty sourcemaps', () => { |
| 27 | + const sourcemapDir = path.join(DIR, 'empty-sourcemap'); |
| 28 | + |
| 29 | + const {stdout, exitCode} = runJest( |
| 30 | + sourcemapDir, |
| 31 | + ['--coverage', '--coverage-provider', 'odz'], |
| 32 | + {stripAnsi: true}, |
| 33 | + ); |
| 34 | + |
| 35 | + expect(exitCode).toBe(0); |
| 36 | + expect(stdout).toMatchSnapshot(); |
| 37 | +}); |
| 38 | + |
| 39 | +test('reports coverage with `resetModules`', () => { |
| 40 | + const sourcemapDir = path.join(DIR, 'with-resetModules'); |
| 41 | + |
| 42 | + const {stdout, exitCode} = runJest( |
| 43 | + sourcemapDir, |
| 44 | + ['--coverage', '--coverage-provider', 'odz'], |
| 45 | + {stripAnsi: true}, |
| 46 | + ); |
| 47 | + |
| 48 | + expect(exitCode).toBe(0); |
| 49 | + expect(stdout).toMatchSnapshot(); |
| 50 | +}); |
| 51 | + |
| 52 | +test('prints correct coverage report, if a CJS module is put under test without transformation', () => { |
| 53 | + const sourcemapDir = path.join(DIR, 'cjs-native-without-sourcemap'); |
| 54 | + |
| 55 | + const {stdout, exitCode} = runJest( |
| 56 | + sourcemapDir, |
| 57 | + ['--coverage', '--coverage-provider', 'odz', '--no-cache'], |
| 58 | + {stripAnsi: true}, |
| 59 | + ); |
| 60 | + |
| 61 | + expect(exitCode).toBe(0); |
| 62 | + expect(stdout).toMatchSnapshot(); |
| 63 | +}); |
| 64 | + |
| 65 | +test('prints correct coverage report, if a TS module is transpiled by Babel to CJS and put under test', () => { |
| 66 | + const sourcemapDir = path.join(DIR, 'cjs-with-babel-transformer'); |
| 67 | + |
| 68 | + const {stdout, exitCode} = runJest( |
| 69 | + sourcemapDir, |
| 70 | + ['--coverage', '--coverage-provider', 'odz', '--no-cache'], |
| 71 | + {stripAnsi: true}, |
| 72 | + ); |
| 73 | + |
| 74 | + expect(exitCode).toBe(0); |
| 75 | + expect(stdout).toMatchSnapshot(); |
| 76 | +}); |
| 77 | + |
| 78 | +test('prints correct coverage report, if an ESM module is put under test without transformation', () => { |
| 79 | + const sourcemapDir = path.join(DIR, 'esm-native-without-sourcemap'); |
| 80 | + |
| 81 | + const {stdout, exitCode} = runJest( |
| 82 | + sourcemapDir, |
| 83 | + ['--coverage', '--coverage-provider', 'odz', '--no-cache'], |
| 84 | + { |
| 85 | + nodeOptions: '--experimental-vm-modules --no-warnings', |
| 86 | + stripAnsi: true, |
| 87 | + }, |
| 88 | + ); |
| 89 | + |
| 90 | + expect(exitCode).toBe(0); |
| 91 | + expect(stdout).toMatchSnapshot(); |
| 92 | +}); |
| 93 | + |
| 94 | +test('prints correct coverage report, if a TS module is transpiled by custom transformer to ESM put under test', () => { |
| 95 | + const sourcemapDir = path.join(DIR, 'esm-with-custom-transformer'); |
| 96 | + |
| 97 | + const {stdout, exitCode} = runJest( |
| 98 | + sourcemapDir, |
| 99 | + ['--coverage', '--coverage-provider', 'odz', '--no-cache'], |
| 100 | + { |
| 101 | + nodeOptions: '--experimental-vm-modules --no-warnings', |
| 102 | + stripAnsi: true, |
| 103 | + }, |
| 104 | + ); |
| 105 | + |
| 106 | + expect(exitCode).toBe(0); |
| 107 | + expect(stdout).toMatchSnapshot(); |
| 108 | +}); |
| 109 | + |
| 110 | +test('vm script coverage generator', () => { |
| 111 | + const dir = path.resolve(__dirname, '../vmscript-coverage'); |
| 112 | + const {stdout, exitCode} = runJest( |
| 113 | + dir, |
| 114 | + ['--coverage', '--coverage-provider', 'odz'], |
| 115 | + {stripAnsi: true}, |
| 116 | + ); |
| 117 | + |
| 118 | + expect(exitCode).toBe(0); |
| 119 | + expect(stdout).toMatchSnapshot(); |
| 120 | +}); |
0 commit comments