Skip to content

Commit

Permalink
fix: ci error and typo
Browse files Browse the repository at this point in the history
  • Loading branch information
nieyuyao committed Apr 28, 2022
1 parent 7d6cda1 commit 214ea2e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
3 changes: 1 addition & 2 deletions packages/vitest/src/runtime/error.ts
@@ -1,8 +1,7 @@
import { format } from 'util'
import { util } from 'chai'
import { stringify } from '../integrations/chai/jest-matcher-utils'
import { clone } from '../utils'
import { getType } from './mocker'
import { clone, getType } from '../utils'

const OBJECT_PROTO = Object.getPrototypeOf({})

Expand Down
10 changes: 3 additions & 7 deletions packages/vitest/src/runtime/mocker.ts
Expand Up @@ -3,17 +3,13 @@ import { isNodeBuiltin } from 'mlly'
import { basename, dirname, resolve } from 'pathe'
import { normalizeRequestId, toFilePath } from 'vite-node/utils'
import type { ModuleCacheMap } from 'vite-node/client'
import { getAllProperties, getWorkerState, isWindows, mergeSlashes, slash } from '../utils'
import { getAllProperties, getType, getWorkerState, isWindows, mergeSlashes, slash } from '../utils'
import { distDir } from '../constants'
import type { PendingSuiteMock } from '../types/mocker'
import type { ExecuteOptions } from './execute'

type Callback = (...args: any[]) => unknown

export function getType(value: unknown): string {
return Object.prototype.toString.apply(value).slice(8, -1)
}

export class VitestMocker {
private static pendingIds: PendingSuiteMock[] = []
private static spyModule?: typeof import('../integrations/spy')
Expand Down Expand Up @@ -156,9 +152,9 @@ export class VitestMocker {

const newObj: Record<string | symbol, any> = {}

const proprieties = getAllProperties(value)
const properties = getAllProperties(value)

for (const k of proprieties) {
for (const k of properties) {
newObj[k] = this.mockValue(value[k])
const type = getType(value[k])

Expand Down
4 changes: 4 additions & 0 deletions packages/vitest/src/utils/base.ts
Expand Up @@ -32,6 +32,10 @@ export function mergeSlashes(str: string) {

export const noop = () => { }

export function getType(value: unknown): string {
return Object.prototype.toString.apply(value).slice(8, -1)
}

export function clone<T>(val: T): T {
let k: any, out: any, tmp: any

Expand Down
24 changes: 14 additions & 10 deletions test/core/test/replace-matcher.test.ts
Expand Up @@ -6,15 +6,26 @@ describe('replace asymmetric matcher', () => {
const replaced = replaceAsymmetricMatcher(actual, expected)
expect(replaced.replacedActual).toEqual(replaced.replacedExpected)
}
it('should works', () => {
it('should work when various types are passed in', () => {
expectReplaceAsymmetricMatcher(null, null)
expectReplaceAsymmetricMatcher(undefined, undefined)
expectReplaceAsymmetricMatcher({}, {})
expectReplaceAsymmetricMatcher([1, 2], [1, 2])
expectReplaceAsymmetricMatcher({}, expect.any(Object))
expectReplaceAsymmetricMatcher(() => {}, expect.any(Function))
expectReplaceAsymmetricMatcher(Promise, expect.any(Function))
expectReplaceAsymmetricMatcher(false, expect.any(Boolean))
expectReplaceAsymmetricMatcher([1, 2], [1, expect.any(Number)])
expectReplaceAsymmetricMatcher(false, expect.anything())
expectReplaceAsymmetricMatcher({}, expect.anything())
expectReplaceAsymmetricMatcher(Symbol, expect.anything())
expectReplaceAsymmetricMatcher(Promise, expect.anything())
expectReplaceAsymmetricMatcher(new Map([['a', 1]]), expect.anything())
expectReplaceAsymmetricMatcher(new Set([1, 2]), expect.anything())
expectReplaceAsymmetricMatcher(new ArrayBuffer(8), expect.anything())
expectReplaceAsymmetricMatcher([1, 2], [1, expect.anything()])
expectReplaceAsymmetricMatcher({
str: 'string',
str: 'a',
arr: [1, 2],
}, {
str: expect.any(String),
Expand All @@ -28,18 +39,11 @@ describe('replace asymmetric matcher', () => {
arr: expect.anything(),
})
expectReplaceAsymmetricMatcher({
str: 'world',
str: 'a',
arr: [1, 2],
}, {
str: expect.any(String),
arr: [1, expect.anything()],
})
expectReplaceAsymmetricMatcher({
str: 'world',
bool: false,
}, {
str: expect.any(String),
bool: expect.anything(),
})
})
})

0 comments on commit 214ea2e

Please sign in to comment.