Skip to content

Commit

Permalink
chore: replace picocolors with tinyrainbow
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jul 10, 2024
1 parent a169d25 commit 3e829e4
Show file tree
Hide file tree
Showing 85 changed files with 2,120 additions and 450 deletions.
2 changes: 1 addition & 1 deletion docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ Path to a diff config that will be used to generate diff interface. Useful if yo
:::code-group
```ts [vitest.diff.ts]
import type { DiffOptions } from 'vitest'
import c from 'picocolors'
import c from 'tinyrainbow'

export default {
aIndicator: c.bold('--'),
Expand Down
6 changes: 0 additions & 6 deletions packages/browser/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,9 @@ export default (browserServer: BrowserServer, base = '/'): Plugin[] => {
'msw/browser',
],
include: [
'vitest > @vitest/utils > pretty-format',
'vitest > @vitest/snapshot > pretty-format',
'vitest > @vitest/snapshot > magic-string',
'vitest > pretty-format',
'vitest > pretty-format > ansi-styles',
'vitest > pretty-format > ansi-regex',
'vitest > chai',
'vitest > chai > loupe',
'vitest > @vitest/utils > diff-sequences',
'vitest > @vitest/utils > loupe',
'@vitest/browser > @testing-library/user-event',
'@vitest/browser > @testing-library/dom',
Expand Down
4 changes: 2 additions & 2 deletions packages/coverage-istanbul/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"istanbul-lib-source-maps": "^5.0.6",
"istanbul-reports": "^3.1.7",
"magicast": "^0.3.4",
"picocolors": "^1.0.1",
"test-exclude": "^7.0.1"
"test-exclude": "^7.0.1",
"tinyrainbow": "^1.1.2"
},
"devDependencies": {
"@types/debug": "^4.1.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/coverage-istanbul/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
coverageConfigDefaults,
} from 'vitest/config'
import { BaseCoverageProvider } from 'vitest/coverage'
import c from 'picocolors'
import c from 'tinyrainbow'
import { parseModule } from 'magicast'
import createDebug from 'debug'
import libReport from 'istanbul-lib-report'
Expand Down
4 changes: 2 additions & 2 deletions packages/coverage-v8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"istanbul-reports": "^3.1.7",
"magic-string": "^0.30.10",
"magicast": "^0.3.4",
"picocolors": "^1.0.1",
"std-env": "^3.7.0",
"strip-literal": "^2.1.0",
"test-exclude": "^7.0.1"
"test-exclude": "^7.0.1",
"tinyrainbow": "^1.1.2"
},
"devDependencies": {
"@types/debug": "^4.1.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/coverage-v8/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import MagicString from 'magic-string'
import { parseModule } from 'magicast'
import remapping from '@ampproject/remapping'
import { normalize, resolve } from 'pathe'
import c from 'picocolors'
import c from 'tinyrainbow'
import { provider } from 'std-env'
import { stripLiteral } from 'strip-literal'
import createDebug from 'debug'
Expand Down
4 changes: 2 additions & 2 deletions packages/expect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
"dependencies": {
"@vitest/spy": "workspace:*",
"@vitest/utils": "workspace:*",
"chai": "^5.1.1"
"chai": "^5.1.1",
"tinyrainbow": "^1.1.2"
},
"devDependencies": {
"@types/chai": "4.3.6",
"@vitest/runner": "workspace:*",
"picocolors": "^1.0.1",
"rollup-plugin-copy": "^3.5.0"
}
}
1 change: 0 additions & 1 deletion packages/expect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ export { getState, setState } from './state'
export { JestChaiExpect } from './jest-expect'
export { addCustomEqualityTesters } from './jest-matcher-utils'
export { JestExtend } from './jest-extend'
export { setupColors } from '@vitest/utils'
20 changes: 10 additions & 10 deletions packages/expect/src/jest-expect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertTypes, getColors } from '@vitest/utils'
import { assertTypes } from '@vitest/utils'
import c from 'tinyrainbow'
import type { Constructable } from '@vitest/utils'
import type { MockInstance, MockResult, MockSettledResult } from '@vitest/spy'
import { isMockFunction } from '@vitest/spy'
Expand Down Expand Up @@ -35,7 +36,6 @@ declare class DOMTokenList {
// Jest Expect Compact
export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
const { AssertionError } = chai
const c = () => getColors()
const customTesters = getCustomEqualityTesters()

function def(
Expand Down Expand Up @@ -530,10 +530,10 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
showActualCall?: any,
) => {
if (spy.mock.calls) {
msg += c().gray(
msg += c.gray(
`\n\nReceived: \n\n${spy.mock.calls
.map((callArg, i) => {
let methodCall = c().bold(
let methodCall = c.bold(
` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`,
)
if (showActualCall) {
Expand All @@ -554,8 +554,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
.join('\n')}`,
)
}
msg += c().gray(
`\n\nNumber of calls: ${c().bold(spy.mock.calls.length)}\n`,
msg += c.gray(
`\n\nNumber of calls: ${c.bold(spy.mock.calls.length)}\n`,
)
return msg
}
Expand All @@ -565,10 +565,10 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
msg: string,
showActualReturn?: any,
) => {
msg += c().gray(
msg += c.gray(
`\n\nReceived: \n\n${results
.map((callReturn, i) => {
let methodCall = c().bold(
let methodCall = c.bold(
` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:\n\n`,
)
if (showActualReturn) {
Expand All @@ -588,8 +588,8 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
})
.join('\n')}`,
)
msg += c().gray(
`\n\nNumber of calls: ${c().bold(spy.mock.calls.length)}\n`,
msg += c.gray(
`\n\nNumber of calls: ${c.bold(spy.mock.calls.length)}\n`,
)
return msg
}
Expand Down
15 changes: 7 additions & 8 deletions packages/expect/src/jest-matcher-utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { getColors, getType, stringify } from '@vitest/utils'
import { getType, stringify } from '@vitest/utils'
import c from 'tinyrainbow'
import type { MatcherHintOptions, Tester } from './types'
import { JEST_MATCHERS_OBJECT } from './constants'

export { diff } from '@vitest/utils/diff'
export { stringify }

export function getMatcherUtils() {
const c = () => getColors()

const EXPECTED_COLOR = c().green
const RECEIVED_COLOR = c().red
const INVERTED_COLOR = c().inverse
const BOLD_WEIGHT = c().bold
const DIM_COLOR = c().dim
const EXPECTED_COLOR = c.green
const RECEIVED_COLOR = c.red
const INVERTED_COLOR = c.inverse
const BOLD_WEIGHT = c.bold
const DIM_COLOR = c.dim

function matcherHint(
matcherName: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

import type { Formatter } from 'picocolors/types'
import type { Formatter } from 'tinyrainbow'
import type { Constructable } from '@vitest/utils'
import type { diff, getMatcherUtils, stringify } from './jest-matcher-utils'

Expand Down
42 changes: 42 additions & 0 deletions packages/pretty-format/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@vitest/pretty-format",
"type": "module",
"version": "2.0.1",
"description": "Fork of pretty-format with support for ESM",
"license": "MIT",
"funding": "https://opencollective.com/vitest",
"homepage": "https://github.com/vitest-dev/vitest/tree/main/packages/utils#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/vitest-dev/vitest.git",
"directory": "packages/pretty-format"
},
"bugs": {
"url": "https://github.com/vitest-dev/vitest/issues"
},
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./*": "./*"
},
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"*.d.ts",
"dist"
],
"scripts": {
"build": "rimraf dist && rollup -c",
"dev": "rollup -c --watch"
},
"dependencies": {
"tinyrainbow": "^1.1.2"
},
"devDependencies": {
"react-is": "^18.3.1"
}
}
64 changes: 64 additions & 0 deletions packages/pretty-format/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { builtinModules, createRequire } from 'node:module'
import { defineConfig } from 'rollup'
import esbuild from 'rollup-plugin-esbuild'
import dts from 'rollup-plugin-dts'
import resolve from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'
import commonjs from '@rollup/plugin-commonjs'

const require = createRequire(import.meta.url)
const pkg = require('./package.json')

const entries = {
index: 'src/index.ts',
}

const external = [
...builtinModules,
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
]

const plugins = [
resolve({
preferBuiltins: true,
}),
json(),
esbuild({
target: 'node14',
}),
commonjs(),
]

export default defineConfig([
{
input: entries,
output: {
dir: 'dist',
format: 'esm',
entryFileNames: '[name].js',
chunkFileNames: 'chunk-[name].js',
},
external,
plugins,
onwarn,
},
{
input: entries,
output: {
dir: 'dist',
entryFileNames: '[name].d.ts',
format: 'esm',
},
external,
plugins: [dts({ respectExternal: true })],
onwarn,
},
])

function onwarn(message) {
if (['EMPTY_BUNDLE', 'CIRCULAR_DEPENDENCY'].includes(message.code)) {
return
}
console.error(message)
}
Loading

0 comments on commit 3e829e4

Please sign in to comment.