diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index aab59a7bc029..9f1727e744c5 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -171,7 +171,7 @@ jobs: test_target_name: e2e.esbuild_node22 env: E2E_SHARD_TOTAL: 1 - TESTBRIDGE_TEST_ONLY: tests/basic/{build,rebuild}.ts + TESTBRIDGE_TEST_ONLY: tests/vitest/larger-project-coverage.ts e2e-package-managers: needs: build diff --git a/packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts b/packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts index 96d3337e0149..b89df899bacb 100644 --- a/packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts +++ b/packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts @@ -10,6 +10,7 @@ import assert from 'node:assert'; import { readFile } from 'node:fs/promises'; import { createRequire } from 'node:module'; import path from 'node:path'; +import { platform } from 'node:os'; import type { BrowserConfigOptions, InlineConfig, @@ -171,6 +172,10 @@ export function createVitestPlugins(pluginOptions: PluginOptions): VitestPlugins name: 'angular:test-in-memory-provider', enforce: 'pre', resolveId: (id, importer) => { + if (id[0] === '/' && platform() === 'win32' && path.isAbsolute(id.slice(1))) { + return id.slice(1); + } + if (importer && (id[0] === '.' || id[0] === '/')) { let fullPath; if (testFileToEntryPoint.has(importer)) { diff --git a/tests/legacy-cli/e2e/tests/vitest/larger-project-coverage.ts b/tests/legacy-cli/e2e/tests/vitest/larger-project-coverage.ts index 17e642014d8d..4d3598baf47c 100644 --- a/tests/legacy-cli/e2e/tests/vitest/larger-project-coverage.ts +++ b/tests/legacy-cli/e2e/tests/vitest/larger-project-coverage.ts @@ -1,10 +1,10 @@ -import { ng } from '../../utils/process'; +import { ng, noSilentNg } from '../../utils/process'; import { applyVitestBuilder } from '../../utils/vitest'; import assert from 'node:assert'; import { installPackage } from '../../utils/packages'; import { exec } from '../../utils/process'; import { updateJsonFile } from '../../utils/project'; -import { readFile } from '../../utils/fs'; +import { readFile, replaceInFile } from '../../utils/fs'; export default async function () { await applyVitestBuilder(); @@ -59,20 +59,22 @@ export default async function () { const expectedMessage = new RegExp(`${totalTests} passed`); const coverageJsonPath = 'coverage/test-project/coverage-final.json'; + // await replaceInFile( + // 'node_modules/@vitest/coverage-v8/dist/provider.js', + // `removeStartsWith(url, FILE_PROTOCOL)`, + // `fileURLToPath(url)`, + // ); + // Run tests in default (JSDOM) mode with coverage - const { stdout: jsdomStdout } = await ng('test', '--no-watch', '--coverage'); + const { stdout: jsdomStdout } = await noSilentNg('test', '--no-watch', '--coverage'); assert.match(jsdomStdout, expectedMessage, `Expected ${totalTests} tests to pass in JSDOM mode.`); - // TODO: Investigate why coverage-final.json is empty on Windows in JSDOM mode. - // For now, skip the coverage report check on Windows. - if (process.platform !== 'win32') { - // Assert that every generated file is in the coverage report by reading the JSON output. - const jsdomSummary = JSON.parse(await readFile(coverageJsonPath)); - const jsdomSummaryKeys = Object.keys(jsdomSummary); - for (const file of generatedFiles) { - const found = jsdomSummaryKeys.some((key) => key.endsWith(file)); - assert.ok(found, `Expected ${file} to be in the JSDOM coverage report.`); - } + // Assert that every generated file is in the coverage report by reading the JSON output. + const jsdomSummary = JSON.parse(await readFile(coverageJsonPath)); + const jsdomSummaryKeys = Object.keys(jsdomSummary); + for (const file of generatedFiles) { + const found = jsdomSummaryKeys.some((key) => key.endsWith(file)); + assert.ok(found, `Expected ${file} to be in the JSDOM coverage report.`); } // Setup for browser mode @@ -81,7 +83,7 @@ export default async function () { await exec('npx', 'playwright', 'install', 'chromium', '--only-shell'); // Run tests in browser mode with coverage - const { stdout: browserStdout } = await ng( + const { stdout: browserStdout } = await noSilentNg( 'test', '--no-watch', '--coverage',