|
| 1 | +import { dirname, join } from 'node:path'; |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | +import { describe, expect, it } from '@rstest/core'; |
| 4 | +import fs from 'fs-extra'; |
| 5 | +import { runRstestCli } from '../scripts'; |
| 6 | + |
| 7 | +const __filename = fileURLToPath(import.meta.url); |
| 8 | +const __dirname = dirname(__filename); |
| 9 | + |
| 10 | +describe('test projects coverage', () => { |
| 11 | + it('should run projects correctly with coverage', async () => { |
| 12 | + const { cli, expectExecSuccess } = await runRstestCli({ |
| 13 | + command: 'rstest', |
| 14 | + args: ['run', '--globals', '-c', 'rstest.coverage.config.ts'], |
| 15 | + options: { |
| 16 | + nodeOptions: { |
| 17 | + cwd: join(__dirname, 'fixtures'), |
| 18 | + }, |
| 19 | + }, |
| 20 | + }); |
| 21 | + |
| 22 | + await expectExecSuccess(); |
| 23 | + const logs = cli.stdout.split('\n').filter(Boolean); |
| 24 | + |
| 25 | + expect( |
| 26 | + logs.find( |
| 27 | + (log) => |
| 28 | + log.includes('All files') && |
| 29 | + log.replaceAll(' ', '').includes('100|100|100|100'), |
| 30 | + ), |
| 31 | + ).toBeTruthy(); |
| 32 | + |
| 33 | + expect( |
| 34 | + logs.find( |
| 35 | + (log) => |
| 36 | + log.includes('client/test') && |
| 37 | + log.replaceAll(' ', '').includes('100|100|100|100'), |
| 38 | + ), |
| 39 | + ).toBeTruthy(); |
| 40 | + |
| 41 | + expect( |
| 42 | + logs.find( |
| 43 | + (log) => |
| 44 | + log.includes('node') && |
| 45 | + log.replaceAll(' ', '').includes('100|100|100|100'), |
| 46 | + ), |
| 47 | + ).toBeTruthy(); |
| 48 | + |
| 49 | + expect( |
| 50 | + fs.existsSync(join(__dirname, 'fixtures/coverage/index.html')), |
| 51 | + ).toBeTruthy(); |
| 52 | + }); |
| 53 | +}); |
0 commit comments