Skip to content

Commit

Permalink
Merge branch 'main' into fix-test-extend-type
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Oct 15, 2024
2 parents 2efa152 + 5d07bba commit 7f5ad9a
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 109 deletions.
1 change: 0 additions & 1 deletion docs/.vitepress/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
AsideViteConf: typeof import('./components/AsideViteConf.vue')['default']
Contributors: typeof import('./components/Contributors.vue')['default']
CourseLink: typeof import('./components/CourseLink.vue')['default']
FeaturesList: typeof import('./components/FeaturesList.vue')['default']
Expand Down
73 changes: 0 additions & 73 deletions docs/.vitepress/components/AsideViteConf.vue

This file was deleted.

2 changes: 0 additions & 2 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
import HomePage from '../components/HomePage.vue'
import Version from '../components/Version.vue'
import AsideViteConf from '../components/AsideViteConf.vue'
import '@shikijs/vitepress-twoslash/style.css'

if (inBrowser) {
Expand All @@ -21,7 +20,6 @@ export default {
Layout() {
return h(DefaultTheme.Layout, null, {
'home-features-after': () => h(HomePage),
'aside-ads-before': () => h(AsideViteConf),
})
},
enhanceApp({ app }) {
Expand Down
24 changes: 0 additions & 24 deletions docs/public/viteconf.svg

This file was deleted.

3 changes: 2 additions & 1 deletion packages/expect/src/jest-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
|| typeof expected === 'undefined'
|| expected instanceof RegExp
) {
return this.throws(expected)
// Fixes the issue related to `chai` <https://github.com/vitest-dev/vitest/issues/6618>
return this.throws(expected === '' ? /^$/ : expected)
}

const obj = this._obj
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/integrations/css/css-modules.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createHash } from 'node:crypto'
import { hash } from '../../node/hash'
import type { CSSModuleScopeStrategy } from '../../node/types/config'

export function generateCssFilenameHash(filepath: string) {
return createHash('md5').update(filepath).digest('hex').slice(0, 6)
return hash('md5', filepath, 'hex').slice(0, 6)
}

export function generateScopedClassName(
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/cache/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from 'node:crypto'
import { resolve } from 'pathe'
import { slash } from '../../utils'
import { hash } from '../hash'
import { FilesStatsCache } from './files'
import { ResultsCache } from './results'

Expand All @@ -26,7 +26,7 @@ export class VitestCache {
? resolve(
root,
baseDir,
crypto.createHash('md5').update(projectName, 'utf-8').digest('hex'),
hash('md5', projectName, 'hex'),
)
: resolve(root, baseDir)
}
Expand Down
7 changes: 7 additions & 0 deletions packages/vitest/src/node/hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import crypto from 'node:crypto'

export const hash = crypto.hash ?? ((
algorithm: string,
data: crypto.BinaryLike,
outputEncoding: crypto.BinaryToTextEncoding,
) => crypto.createHash(algorithm).update(data).digest(outputEncoding))
4 changes: 2 additions & 2 deletions packages/vitest/src/node/pools/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createHash } from 'node:crypto'
import { mkdir, writeFile } from 'node:fs/promises'
import type { RawSourceMap } from 'vite-node'
import { join } from 'pathe'
import type { WorkspaceProject } from '../workspace'
import type { RuntimeRPC } from '../../types/rpc'
import { hash } from '../hash'

const created = new Set()
const promises = new Map<string, Promise<void>>()
Expand Down Expand Up @@ -47,7 +47,7 @@ export function createMethodsRPC(project: WorkspaceProject, options: MethodsOpti
}

const dir = join(project.tmpDir, transformMode)
const name = createHash('sha1').update(id).digest('hex')
const name = hash('sha1', id, 'hex')
const tmp = join(dir, name)
if (promises.has(tmp)) {
await promises.get(tmp)
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/sequencers/BaseSequencer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createHash } from 'node:crypto'
import { relative, resolve } from 'pathe'
import { slash } from 'vite-node/utils'
import { hash } from '../hash'
import type { Vitest } from '../core'
import type { WorkspaceSpec } from '../pool'
import type { TestSequencer } from './types'
Expand All @@ -25,7 +25,7 @@ export class BaseSequencer implements TestSequencer {
const specPath = fullPath?.slice(config.root.length)
return {
spec,
hash: createHash('sha1').update(specPath).digest('hex'),
hash: hash('sha1', specPath, 'hex'),
}
})
.sort((a, b) => (a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0))
Expand Down
7 changes: 7 additions & 0 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ describe('jest-expect', () => {
// eslint-disable-next-line no-throw-literal
throw ''
}).toThrow(/^$/)
expect(() => {
// eslint-disable-next-line no-throw-literal
throw ''
}).toThrow('')
expect(() => {
throw new Error('error')
}).not.toThrowError('')
expect([1, 2, 3]).toHaveLength(3)
expect('abc').toHaveLength(3)
expect('').not.toHaveLength(5)
Expand Down

0 comments on commit 7f5ad9a

Please sign in to comment.