Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load deps reporter #2249

Merged
merged 9 commits into from Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/utils.ts
Expand Up @@ -6,7 +6,7 @@ import type { BenchmarkBuiltinReporters, BuiltinReporters } from './index'
async function loadCustomReporterModule<C extends Reporter>(path: string, runner: ViteNodeRunner): Promise<new () => C> {
let customReporterModule: { default: new () => C }
try {
customReporterModule = await runner.executeFile(path)
customReporterModule = await runner.executeId(path)
}
catch (customReporterModuleError) {
throw new Error(`Failed to load custom Reporter from ${path}`, { cause: customReporterModuleError as Error })
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/reporters/deps-reporter.vitest.config.ts
@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: ['tests/reporters.spec.ts'],
reporters: ['pkg-reporter'],
},
})
1 change: 1 addition & 0 deletions test/reporters/package.json
Expand Up @@ -6,6 +6,7 @@
},
"devDependencies": {
"execa": "^6.1.0",
"pkg-reporter": "./reportPkg/",
"vitest": "workspace:*"
}
}
9 changes: 9 additions & 0 deletions test/reporters/reportPkg/index.js
@@ -0,0 +1,9 @@
export default class PackageReporter {
onInit(ctx) {
this.ctx = ctx
}

onFinished() {
this.ctx.logger.log('hello from package reporter')
}
}
4 changes: 4 additions & 0 deletions test/reporters/reportPkg/package.json
@@ -0,0 +1,4 @@
{
"name": "pkg-reporter",
"main": "./index.js"
}
13 changes: 13 additions & 0 deletions test/reporters/reportTest2/custom-reporter-path.vitest.config.ts
@@ -0,0 +1,13 @@
import { resolve } from 'pathe'
import { defineConfig } from 'vitest/config'

const customReporter = resolve(__dirname, '../src/custom-reporter.ts')

export default defineConfig({
root: __dirname,
test: {
root: __dirname,
include: ['../tests/reporters.spec.ts'],
reporters: [customReporter],
},
})
10 changes: 10 additions & 0 deletions test/reporters/tests/custom-reporter.spec.ts
Expand Up @@ -45,6 +45,16 @@ describe.concurrent('custom reporters', () => {
expect(stdout).includes('hello from custom reporter')
}, 40000)

test('load no base on root custom reporter instances defined in configuration works', async () => {
const stdout = await runWithRetry('--config', './reportTest2/custom-reporter-path.vitest.config.ts')
expect(stdout).includes('hello from custom reporter')
}, 50000)

test('package.json dependencies reporter instances defined in configuration works', async () => {
const stdout = await runWithRetry('--config', 'deps-reporter.vitest.config.ts')
expect(stdout).includes('hello from package reporter')
}, 50000)

test('a path to a custom reporter defined in configuration works', async () => {
const stdout = await runWithRetry('--config', 'custom-reporter-path.vitest.config.ts', '--reporter', customJSReporterPath)
expect(stdout).includes('hello from custom reporter')
Expand Down
2 changes: 1 addition & 1 deletion test/reporters/tests/utils.test.ts
Expand Up @@ -10,7 +10,7 @@ import TestReporter from '../src/custom-reporter'

const customReporterPath = resolve(__dirname, '../src/custom-reporter.js')
const fetchModule = {
executeFile: (id: string) => import(id),
executeId: (id: string) => import(id),
} as ViteNodeRunner

describe('Reporter Utils', () => {
Expand Down