Skip to content

Commit

Permalink
fix: passing non array to reporters option did not effect (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Mar 1, 2022
1 parent 1fcb4ed commit cb5994b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/vitest/src/utils/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T> {
}

export const toString = (v: any) => Object.prototype.toString.call(v)
export const isPlainObject = (val: any): val is object => toString(val) === '[object Object]'
export const isPlainObject = (val: any): val is object =>
// `Object.create(null).constructor` is `undefined`
// `{}.constructor.name` is `Object`
// `new (class A{})().constructor.name` is `A`
toString(val) === '[object Object]' && (!val.constructor || val.constructor.name === 'Object')

export function isObject(item: unknown): boolean {
return item != null && typeof item === 'object' && !Array.isArray(item)
Expand Down
12 changes: 8 additions & 4 deletions test/core/test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ describe('assertTypes', () => {

describe('deepMerge', () => {
test('non plain objects retain their prototype, arrays are not merging, plain objects are merging', () => {
class Test {
class TestA {
baz = 'baz'

get foo() {
return 'foo'
}
}
class TestB {
bar = 'bar'
}

const testA = new Test()
const testB = new Test()
const testA = new TestA()
const testB = new TestB()

const a = {
test: testA,
Expand All @@ -53,7 +56,8 @@ describe('deepMerge', () => {

const merged = deepMerge(a, b)

expect(merged.test instanceof Test).toBe(true)
expect(merged.test instanceof TestB).toBe(true)
expect(merged.test.baz).toBeUndefined()
expect(merged.num).toBe(40)
expect(merged.array).toEqual([3, 4])
expect(merged.obj).toEqual({
Expand Down
2 changes: 1 addition & 1 deletion test/reporters/custom-reporter.vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class TestReporter implements Reporter {
export default defineConfig({
test: {
include: ['tests/reporters.spec.ts'],
reporters: ['default', new TestReporter()],
reporters: new TestReporter(),
},
})
2 changes: 1 addition & 1 deletion test/reporters/tests/custom-reporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { execa } from 'execa'
import { resolve } from 'pathe'
import { expect, test } from 'vitest'

test.skip('custom reporters work with threads', async() => {
test('custom reporters work', async() => {
const root = resolve(__dirname, '..')

const { stdout } = await execa('npx', ['vitest', 'run', '--config', 'custom-reporter.vitest.config.ts'], {
Expand Down

0 comments on commit cb5994b

Please sign in to comment.