mirror of
https://github.com/vitest-dev/vitest.git
synced 2026-02-01 17:36:51 +00:00
chore: apply linter
This commit is contained in:
parent
8b96432645
commit
f47a34514d
@ -12,7 +12,7 @@
|
||||
"docs:build": "npm -C docs run build",
|
||||
"docs:serve": "npm -C docs run serve",
|
||||
"postinstall": "cd test/vue2 && npx pnpm i",
|
||||
"lint": "eslint --ext .js,.vue .",
|
||||
"lint": "eslint --ext .js,.vue,.ts .",
|
||||
"release": "bumpp package.json packages/*/package.json --commit --push --tag && pnpm -r publish",
|
||||
"test": "vitest -r test/core",
|
||||
"test:all": "cross-env CI=true pnpm -r --stream --filter !vitest run test --",
|
||||
|
||||
@ -25,9 +25,9 @@ export const VitestUIPlugin = (): Plugin => {
|
||||
wss.emit('connection', ws, request)
|
||||
|
||||
/**
|
||||
* When user opens connection send inital list of tasks.
|
||||
* When user opens connection send initial list of tasks.
|
||||
*/
|
||||
ws.on('message', (data) => {
|
||||
ws.on('message', () => {
|
||||
|
||||
})
|
||||
})
|
||||
@ -35,7 +35,7 @@ export const VitestUIPlugin = (): Plugin => {
|
||||
}
|
||||
})
|
||||
|
||||
server.middlewares.use('/__vitest_api', async(req, res, next) => {
|
||||
server.middlewares.use('/__vitest_api', async(req, res) => {
|
||||
// const vitest = process.__vitest__
|
||||
|
||||
// const suites = getSuites(vitest.state.getFiles())
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
import { getSuites } from '../../../src/utils'
|
||||
// import { getSuites } from '../../../src/utils'
|
||||
|
||||
const getCircularReplacer = () => {
|
||||
const seen = new WeakSet()
|
||||
return (key: any, value: any) => {
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (seen.has(value))
|
||||
return
|
||||
// const getCircularReplacer = () => {
|
||||
// const seen = new WeakSet()
|
||||
// return (key: any, value: any) => {
|
||||
// if (typeof value === 'object' && value !== null) {
|
||||
// if (seen.has(value))
|
||||
// return
|
||||
|
||||
seen.add(value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
// seen.add(value)
|
||||
// }
|
||||
// return value
|
||||
// }
|
||||
// }
|
||||
|
||||
export const getSuitesAsJson = () => {
|
||||
// const vitest = process.__vitest__
|
||||
|
||||
@ -59,138 +59,126 @@ export class StringContaining extends AsymmetricMatcher<string> {
|
||||
}
|
||||
}
|
||||
|
||||
export class Anything extends AsymmetricMatcher<void>{
|
||||
export class Anything extends AsymmetricMatcher<void> {
|
||||
asymmetricMatch(other: unknown) {
|
||||
return other !== void 0 && other !== null;
|
||||
return other != null
|
||||
}
|
||||
|
||||
toString() {
|
||||
return 'Anything';
|
||||
return 'Anything'
|
||||
}
|
||||
|
||||
toAsymmetricMatcher() {
|
||||
return 'Anything';
|
||||
return 'Anything'
|
||||
}
|
||||
}
|
||||
|
||||
export class ArrayContaining extends AsymmetricMatcher<Array<unknown>> {
|
||||
constructor(sample: Array<unknown>, inverse = false) {
|
||||
super(sample, inverse);
|
||||
super(sample, inverse)
|
||||
}
|
||||
|
||||
asymmetricMatch(other: Array<unknown>) {
|
||||
if (!Array.isArray(this.sample)) {
|
||||
throw new Error(
|
||||
`You must provide an array to ${this.toString()}, not '` +
|
||||
typeof this.sample +
|
||||
"'.",
|
||||
);
|
||||
throw new TypeError(
|
||||
`You must provide an array to ${this.toString()}, not '${
|
||||
typeof this.sample
|
||||
}'.`,
|
||||
)
|
||||
}
|
||||
|
||||
const result =
|
||||
this.sample.length === 0 ||
|
||||
(Array.isArray(other) &&
|
||||
this.sample.every(item =>
|
||||
const result
|
||||
= this.sample.length === 0
|
||||
|| (Array.isArray(other)
|
||||
&& this.sample.every(item =>
|
||||
other.some(another => equals(item, another)),
|
||||
));
|
||||
))
|
||||
|
||||
return this.inverse ? !result : result;
|
||||
return this.inverse ? !result : result
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `Array${this.inverse ? 'Not' : ''}Containing`;
|
||||
return `Array${this.inverse ? 'Not' : ''}Containing`
|
||||
}
|
||||
|
||||
getExpectedType() {
|
||||
return 'array';
|
||||
return 'array'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class Any extends AsymmetricMatcher<any> {
|
||||
constructor(sample: unknown) {
|
||||
if (typeof sample === 'undefined') {
|
||||
throw new TypeError(
|
||||
'any() expects to be passed a constructor function. ' +
|
||||
'Please pass one or use anything() to match any object.',
|
||||
);
|
||||
'any() expects to be passed a constructor function. '
|
||||
+ 'Please pass one or use anything() to match any object.',
|
||||
)
|
||||
}
|
||||
super(sample);
|
||||
super(sample)
|
||||
}
|
||||
fnNameFor(func: Function) {
|
||||
if (func.name) {
|
||||
return func.name;
|
||||
}
|
||||
const functionToString = Function.prototype.toString;
|
||||
|
||||
fnNameFor(func: Function) {
|
||||
if (func.name)
|
||||
return func.name
|
||||
|
||||
const functionToString = Function.prototype.toString
|
||||
|
||||
const matches = functionToString
|
||||
.call(func)
|
||||
.match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
|
||||
return matches ? matches[1] : '<anonymous>';
|
||||
.match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/)
|
||||
return matches ? matches[1] : '<anonymous>'
|
||||
}
|
||||
|
||||
asymmetricMatch(other: unknown) {
|
||||
if (this.sample == String) {
|
||||
return typeof other == 'string' || other instanceof String;
|
||||
}
|
||||
if (this.sample === String)
|
||||
return typeof other == 'string' || other instanceof String
|
||||
|
||||
if (this.sample == Number) {
|
||||
return typeof other == 'number' || other instanceof Number;
|
||||
}
|
||||
if (this.sample === Number)
|
||||
return typeof other == 'number' || other instanceof Number
|
||||
|
||||
if (this.sample == Function) {
|
||||
return typeof other == 'function' || other instanceof Function;
|
||||
}
|
||||
if (this.sample === Function)
|
||||
return typeof other == 'function' || other instanceof Function
|
||||
|
||||
if (this.sample == Boolean) {
|
||||
return typeof other == 'boolean' || other instanceof Boolean;
|
||||
}
|
||||
if (this.sample === Boolean)
|
||||
return typeof other == 'boolean' || other instanceof Boolean
|
||||
|
||||
if (this.sample == BigInt) {
|
||||
return typeof other == 'bigint' || other instanceof BigInt;
|
||||
}
|
||||
if (this.sample === BigInt)
|
||||
return typeof other == 'bigint' || other instanceof BigInt
|
||||
|
||||
if (this.sample == Symbol) {
|
||||
return typeof other == 'symbol' || other instanceof Symbol;
|
||||
}
|
||||
if (this.sample === Symbol)
|
||||
return typeof other == 'symbol' || other instanceof Symbol
|
||||
|
||||
if (this.sample == Object) {
|
||||
return typeof other == 'object';
|
||||
}
|
||||
if (this.sample === Object)
|
||||
return typeof other == 'object'
|
||||
|
||||
return other instanceof this.sample;
|
||||
return other instanceof this.sample
|
||||
}
|
||||
|
||||
toString() {
|
||||
return 'Any';
|
||||
return 'Any'
|
||||
}
|
||||
|
||||
getExpectedType() {
|
||||
if (this.sample == String) {
|
||||
return 'string';
|
||||
}
|
||||
if (this.sample === String)
|
||||
return 'string'
|
||||
|
||||
if (this.sample == Number) {
|
||||
return 'number';
|
||||
}
|
||||
if (this.sample === Number)
|
||||
return 'number'
|
||||
|
||||
if (this.sample == Function) {
|
||||
return 'function';
|
||||
}
|
||||
if (this.sample === Function)
|
||||
return 'function'
|
||||
|
||||
if (this.sample == Object) {
|
||||
return 'object';
|
||||
}
|
||||
if (this.sample === Object)
|
||||
return 'object'
|
||||
|
||||
if (this.sample == Boolean) {
|
||||
return 'boolean';
|
||||
}
|
||||
if (this.sample === Boolean)
|
||||
return 'boolean'
|
||||
|
||||
return this.fnNameFor(this.sample);
|
||||
return this.fnNameFor(this.sample)
|
||||
}
|
||||
|
||||
toAsymmetricMatcher() {
|
||||
return 'Any<' + this.fnNameFor(this.sample) + '>';
|
||||
return `Any<${this.fnNameFor(this.sample)}>`
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,7 +202,7 @@ export const JestAsymmetricMatchers: ChaiPlugin = (chai, utils) => {
|
||||
'any',
|
||||
(expected: unknown) => {
|
||||
return new Any(expected)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
utils.addMethod(
|
||||
@ -224,5 +212,4 @@ export const JestAsymmetricMatchers: ChaiPlugin = (chai, utils) => {
|
||||
return new ArrayContaining(expected)
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@ -56,8 +56,8 @@ describe('jest-expect', () => {
|
||||
expect('string').toEqual(expect.any(String))
|
||||
expect('string').not.toEqual(expect.any(Number))
|
||||
|
||||
expect(['Bob', 'Eve']).toEqual(expect.arrayContaining(['Bob']));
|
||||
expect(['Bob', 'Eve']).not.toEqual(expect.arrayContaining(['Mohammad']));
|
||||
expect(['Bob', 'Eve']).toEqual(expect.arrayContaining(['Bob']))
|
||||
expect(['Bob', 'Eve']).not.toEqual(expect.arrayContaining(['Mohammad']))
|
||||
|
||||
// TODO: support set
|
||||
// expect(new Set(['bar'])).not.toEqual(new Set([expect.stringContaining('zoo')]))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user