|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { applyVitestBuilder } from '../../utils/vitest'; |
| 3 | +import { ng, noSilentNg } from '../../utils/process'; |
| 4 | +import { installPackage } from '../../utils/packages'; |
| 5 | +import { expectFileToExist, readFile, writeFile } from '../../utils/fs'; |
| 6 | +import { stripVTControlCharacters } from 'node:util'; |
| 7 | + |
| 8 | +export default async function (): Promise<void> { |
| 9 | + await applyVitestBuilder(); |
| 10 | + await installPackage('playwright@1'); |
| 11 | + await installPackage('@vitest/browser-playwright@4'); |
| 12 | + await installPackage('@vitest/coverage-v8@4'); |
| 13 | + await ng('generate', 'component', 'my-comp'); |
| 14 | + |
| 15 | + // Add a failing test to verify source map support |
| 16 | + await writeFile( |
| 17 | + 'src/app/failing.spec.ts', |
| 18 | + ` |
| 19 | + describe('Failing Test', () => { |
| 20 | + it('should fail', () => { |
| 21 | + expect(true).toBe(false); |
| 22 | + }); |
| 23 | + }); |
| 24 | + `, |
| 25 | + ); |
| 26 | + |
| 27 | + try { |
| 28 | + await noSilentNg('test', '--no-watch', '--browsers', 'chromiumHeadless', '--coverage'); |
| 29 | + throw new Error('Expected "ng test" to fail.'); |
| 30 | + } catch (error: any) { |
| 31 | + const stdout = stripVTControlCharacters(error.stdout || error.message); |
| 32 | + // We expect the failure from failing.spec.ts |
| 33 | + assert.match(stdout, /1 failed/, 'Expected 1 test to fail.'); |
| 34 | + // Check that the stack trace points to the correct file |
| 35 | + assert.match( |
| 36 | + stdout, |
| 37 | + /\\bsrc[\\/\\\\]app[\\/\\\\]failing\\.spec\\.ts:4:\\d+/, |
| 38 | + 'Expected stack trace to point to the source file.', |
| 39 | + ); |
| 40 | + } |
| 41 | + |
| 42 | + // Verify that coverage files are generated |
| 43 | + const coverageJsonPath = 'coverage/test-project/coverage-final.json'; |
| 44 | + await expectFileToExist(coverageJsonPath); |
| 45 | + |
| 46 | + const coverageContent = await readFile(coverageJsonPath); |
| 47 | + assert.match(coverageContent, /app\.component\.ts/, 'Expected coverage report to contain app.component.ts.'); |
| 48 | +} |
0 commit comments