diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26bc5da46ad1e..53ba53b623fbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,35 +20,6 @@ env: PUPPETEER_DOWNLOAD_PATH: ${{ github.workspace }}/.cache/Puppeteer jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: ./.github/actions/setup-and-cache - - - name: Install - run: pnpm i - - - name: Lint - run: pnpm run lint - - typecheck: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: ./.github/actions/setup-and-cache - - - name: Install - run: pnpm i - - - name: Build - run: pnpm run build - - - name: Typecheck - run: pnpm run typecheck - test: runs-on: ${{ matrix.os }} @@ -56,13 +27,8 @@ jobs: strategy: matrix: - os: [ubuntu-latest] - node_version: [16, 18] - include: - - os: macos-latest - node_version: 18 - - os: windows-latest - node_version: 18 + os: [windows-latest] + node_version: [18] fail-fast: false steps: @@ -79,126 +45,5 @@ jobs: run: pnpm run build - name: Test - run: pnpm run test:ci - - - name: Test Single Thread - run: pnpm run test:ci:single-thread - - test-ui: - runs-on: ubuntu-latest - - timeout-minutes: 10 - - steps: - - uses: actions/checkout@v3 - - - uses: ./.github/actions/setup-and-cache - with: - node-version: 16.16 - - - name: Install - run: pnpm i - - - name: Test UI - run: pnpm run ui:test - - test-browser: - runs-on: ubuntu-latest - strategy: - matrix: - browser: [[chrome, chromium], [firefox, firefox], [edge, webkit]] - - timeout-minutes: 30 - - env: - BROWSER: ${{ matrix.browser[0] }} - steps: - - uses: actions/checkout@v3 - - - uses: ./.github/actions/setup-and-cache - with: - node-version: 18 - - - uses: browser-actions/setup-chrome@v1 - - uses: browser-actions/setup-firefox@v1 - - uses: browser-actions/setup-edge@v1 - - - name: Install - run: pnpm i - - - name: Install Playwright Dependencies - run: pnpx playwright install-deps - - - name: Build - run: pnpm run build - - - name: Test Browser (webdriverio) - run: pnpm run test:browser:webdriverio - - - name: Test Browser (playwright) - run: pnpm run test:browser:playwright - env: - BROWSER: ${{ matrix.browser[1] }} - - test-browser-windows: - runs-on: windows-latest - strategy: - matrix: - browser: [[chrome, chromium], [edge, webkit]] - - timeout-minutes: 30 - - env: - BROWSER: ${{ matrix.browser[0] }} - steps: - - uses: actions/checkout@v3 - - - uses: ./.github/actions/setup-and-cache - with: - node-version: 18 - - - uses: browser-actions/setup-chrome@v1 - - uses: browser-actions/setup-edge@v1 - - - name: Install - run: pnpm i - - - name: Install Playwright Dependencies - run: pnpx playwright install-deps - - - name: Build - run: pnpm run build - - - name: Test Browser (webdriverio) - run: pnpm run test:browser:webdriverio - - - name: Test Browser (playwright) - run: pnpm run test:browser:playwright - env: - BROWSER: ${{ matrix.browser[1] }} - - test-browser-safari: - runs-on: macos-latest - timeout-minutes: 30 - - steps: - - uses: actions/checkout@v3 - - - uses: ./.github/actions/setup-and-cache - with: - node-version: 18 - - - name: Install - run: sudo pnpm i --frozen-lockfile - - - name: Build - run: sudo pnpm run build - - - name: Enable - run: sudo safaridriver --enable - - - name: Test Browser (webdriverio) - run: sudo BROWSER=safari pnpm run test:browser:webdriverio - - - name: Test Browser (playwright) - run: sudo BROWSER=webkit pnpm run test:browser:playwright + working-directory: test/coverage-test + run: pnpm run test diff --git a/packages/coverage-c8/src/provider.ts b/packages/coverage-c8/src/provider.ts index 8fc0e8a2d3884..7064f37e3ebbc 100644 --- a/packages/coverage-c8/src/provider.ts +++ b/packages/coverage-c8/src/provider.ts @@ -1,4 +1,4 @@ -import { existsSync, promises as fs } from 'node:fs' +import { existsSync, promises as fs, readdirSync } from 'node:fs' import _url from 'node:url' import type { Profiler } from 'node:inspector' import MagicString from 'magic-string' @@ -61,8 +61,21 @@ export class C8CoverageProvider extends BaseCoverageProvider implements Coverage } async clean(clean = true) { - if (clean && existsSync(this.options.reportsDirectory)) - await fs.rm(this.options.reportsDirectory, { recursive: true, force: true, maxRetries: 10 }) + if (clean && existsSync(this.options.reportsDirectory)) { + this.ctx.logger.log('Cleaning:', this.options.reportsDirectory) + + try { + await fs.rm(this.options.reportsDirectory, { recursive: true, force: true, maxRetries: 10 }) + } + catch (e) { + console.error('Failed to rm reports directory', e) + throw e + } + + const exists = existsSync(this.options.reportsDirectory) + const contents = readdirSync('./') + this.ctx.logger.log('Cleaned. Exists:', exists, 'Cwd contents:', contents.join(',')) + } this.coverages = [] } diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index bdbe27f6bf0df..4d3b247f12d8c 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -285,14 +285,13 @@ export class Vitest { return } - try { - await this.initCoverageProvider() - await this.coverageProvider?.clean(this.config.coverage.clean) - await this.initBrowserProviders() - } - finally { - await this.report('onInit', this) - } + await this.initCoverageProvider() + await this.coverageProvider?.clean(this.config.coverage.clean) + await this.initBrowserProviders() + + await this.report('onInit', this).catch((e) => { + console.error('onInit failed too', e.message) + }) const files = await this.filterTestsBySource( await this.globTestFiles(filters), diff --git a/packages/vitest/src/node/reporters/junit.ts b/packages/vitest/src/node/reporters/junit.ts index a9b9181756239..f89128ab8714e 100644 --- a/packages/vitest/src/node/reporters/junit.ts +++ b/packages/vitest/src/node/reporters/junit.ts @@ -1,4 +1,4 @@ -import { existsSync, promises as fs } from 'node:fs' +import { existsSync, promises as fs, readdirSync } from 'node:fs' import { hostname } from 'node:os' import { dirname, relative, resolve } from 'pathe' @@ -75,6 +75,7 @@ export class JUnitReporter implements Reporter { private baseLog!: (text: string) => Promise private logger!: IndentedLogger> private _timeStart = new Date() + private fileFd?: fs.FileHandle async onInit(ctx: Vitest): Promise { this.ctx = ctx @@ -85,12 +86,31 @@ export class JUnitReporter implements Reporter { this.reportFile = resolve(this.ctx.config.root, outputFile) const outputDirectory = dirname(this.reportFile) - if (!existsSync(outputDirectory)) + if (!existsSync(outputDirectory)) { + this.ctx.logger.log('Creating:', outputDirectory) await fs.mkdir(outputDirectory, { recursive: true }) + } + else { + this.ctx.logger.log('Exists already:', outputDirectory) + } + + try { + const fileFd = await fs.open(this.reportFile, 'w+') + this.fileFd = fileFd + + this.baseLog = async (text: string) => await fs.writeFile(fileFd, `${text}\n`) + } + catch (e) { + this.ctx.logger.error(`Failed to open JUnit report file "${this.reportFile}" - ${(e as any).message}`) + + const exists = existsSync(outputDirectory) + this.ctx.logger.log('Exists:', exists) - const fileFd = await fs.open(this.reportFile, 'w+') + const contents = readdirSync(outputDirectory) + this.ctx.logger.log('Contents:', contents.join(', ')) - this.baseLog = async (text: string) => await fs.writeFile(fileFd, `${text}\n`) + throw e + } } else { this.baseLog = async (text: string) => this.ctx.logger.log(text) @@ -244,5 +264,7 @@ export class JUnitReporter implements Reporter { if (this.reportFile) this.ctx.logger.log(`JUNIT report written to ${this.reportFile}`) + + await this.fileFd?.close() } }