[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

perf: use ES2022 language features (#8492)

authored by

Trevor Burnham and committed by
GitHub
(Aug 28, 2025, 11:10 AM +0200) bb34c64d 22f03097

+25 -25
+9 -9
packages/expect/src/jest-expect.ts
··· 467 467 const actual = this._obj as any 468 468 const [propertyName, expected] = args 469 469 const getValue = () => { 470 - const hasOwn = Object.prototype.hasOwnProperty.call( 470 + const hasOwn = Object.hasOwn( 471 471 actual, 472 472 propertyName, 473 473 ) ··· 660 660 function (...args: any[]) { 661 661 const spy = getSpy(this) 662 662 const spyName = spy.getMockName() 663 - const lastCall = spy.mock.calls[spy.mock.calls.length - 1] 663 + const lastCall = spy.mock.calls.at(-1) 664 664 665 665 this.assert( 666 666 lastCall && equalsArgumentArray(lastCall, args), ··· 965 965 name: 'toHaveLastResolvedWith', 966 966 condition: (spy, value) => { 967 967 const result 968 - = spy.mock.settledResults[spy.mock.settledResults.length - 1] 969 - return ( 968 + = spy.mock.settledResults.at(-1) 969 + return Boolean( 970 970 result 971 971 && result.type === 'fulfilled' 972 - && jestEquals(result.value, value) 972 + && jestEquals(result.value, value), 973 973 ) 974 974 }, 975 975 action: 'resolve', ··· 977 977 { 978 978 name: ['toHaveLastReturnedWith', 'lastReturnedWith'], 979 979 condition: (spy, value) => { 980 - const result = spy.mock.results[spy.mock.results.length - 1] 981 - return ( 980 + const result = spy.mock.results.at(-1) 981 + return Boolean( 982 982 result 983 983 && result.type === 'return' 984 - && jestEquals(result.value, value) 984 + && jestEquals(result.value, value), 985 985 ) 986 986 }, 987 987 action: 'return', ··· 992 992 const spy = getSpy(this) 993 993 const results 994 994 = action === 'return' ? spy.mock.results : spy.mock.settledResults 995 - const result = results[results.length - 1] 995 + const result = results.at(-1) 996 996 const spyName = spy.getMockName() 997 997 this.assert( 998 998 condition(spy, value),
+3 -3
packages/expect/src/jest-utils.ts
··· 294 294 } 295 295 296 296 function hasKey(obj: any, key: string) { 297 - return Object.prototype.hasOwnProperty.call(obj, key) 297 + return Object.hasOwn(obj, key) 298 298 } 299 299 300 300 export function isA(typeName: string, value: unknown): boolean { ··· 342 342 return false 343 343 } 344 344 345 - if (Object.prototype.hasOwnProperty.call(obj, property)) { 345 + if (Object.hasOwn(obj, property)) { 346 346 return true 347 347 } 348 348 ··· 571 571 } 572 572 573 573 return ( 574 - Object.prototype.hasOwnProperty.call(object, key) 574 + Object.hasOwn(object, key) 575 575 || hasPropertyInObject(Object.getPrototypeOf(object), key) 576 576 ) 577 577 }
+1 -1
packages/expect/src/state.ts
··· 6 6 MATCHERS_OBJECT, 7 7 } from './constants' 8 8 9 - if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) { 9 + if (!Object.hasOwn(globalThis, MATCHERS_OBJECT)) { 10 10 const globalState = new WeakMap<ExpectStatic, MatcherState>() 11 11 const matchers = Object.create(null) 12 12 const customEqualityTesters: Array<Tester> = []
+1 -1
packages/pretty-format/src/index.ts
··· 449 449 450 450 function validateOptions(options: OptionsReceived) { 451 451 for (const key of Object.keys(options)) { 452 - if (!Object.prototype.hasOwnProperty.call(DEFAULT_OPTIONS, key)) { 452 + if (!Object.hasOwn(DEFAULT_OPTIONS, key)) { 453 453 throw new Error(`pretty-format: Unknown option "${key}".`) 454 454 } 455 455 }
+1 -1
packages/runner/src/fixture.ts
··· 395 395 if (s[i] === '{' || s[i] === '[') { 396 396 stack.push(s[i] === '{' ? '}' : ']') 397 397 } 398 - else if (s[i] === stack[stack.length - 1]) { 398 + else if (s[i] === stack.at(-1)) { 399 399 stack.pop() 400 400 } 401 401 else if (!stack.length && s[i] === ',') {
+1 -1
packages/utils/src/helpers.ts
··· 86 86 } 87 87 88 88 export function withTrailingSlash(path: string): string { 89 - if (path[path.length - 1] !== '/') { 89 + if (path.at(-1) !== '/') { 90 90 return `${path}/` 91 91 } 92 92 return path
+1 -1
packages/vite-node/src/client.ts
··· 254 254 255 255 /** @internal */ 256 256 async cachedRequest(id: string, fsPath: string, callstack: string[]) { 257 - const importee = callstack[callstack.length - 1] 257 + const importee = callstack.at(-1) 258 258 259 259 const mod = this.moduleCache.get(fsPath) 260 260 const { imports, importers } = mod
+1 -1
packages/vite-node/src/utils.ts
··· 242 242 } 243 243 244 244 export function withTrailingSlash(path: string): string { 245 - if (path[path.length - 1] !== '/') { 245 + if (path.at(-1) !== '/') { 246 246 return `${path}/` 247 247 } 248 248
+1 -1
packages/browser/src/node/serverOrchestrator.ts
··· 13 13 // it's possible to open the page without a context 14 14 if (!sessionId) { 15 15 const contexts = [...globalServer.children].flatMap(p => [...p.state.orchestrators.keys()]) 16 - sessionId = contexts[contexts.length - 1] ?? 'none' 16 + sessionId = contexts.at(-1) ?? 'none' 17 17 } 18 18 19 19 // it's ok to not have a session here, especially in the preview provider
+1 -1
packages/mocker/src/node/resolver.ts
··· 176 176 } 177 177 178 178 function withTrailingSlash(path: string): string { 179 - if (path[path.length - 1] !== '/') { 179 + if (path.at(-1) !== '/') { 180 180 return `${path}/` 181 181 } 182 182
+1 -1
packages/snapshot/src/port/inlineSnapshot.ts
··· 198 198 return inlineSnapshot 199 199 } 200 200 201 - if (lines[0].trim() !== '' || lines[lines.length - 1].trim() !== '') { 201 + if (lines[0].trim() !== '' || lines.at(-1)?.trim() !== '') { 202 202 // If not blank first and last lines, abort. 203 203 return inlineSnapshot 204 204 }
+1 -1
packages/ui/client/utils/task.ts
··· 1 1 import type { RunnerTask, RunnerTestSuite } from 'vitest' 2 2 3 3 export function isSuite(task: RunnerTask): task is RunnerTestSuite { 4 - return Object.hasOwnProperty.call(task, 'tasks') 4 + return Object.hasOwn(task, 'tasks') 5 5 } 6 6 7 7 export function isTaskDone(task: RunnerTask) {
+1 -1
packages/utils/src/diff/cleanupSemantic.ts
··· 501 501 break 502 502 } 503 503 } 504 - if (diffs[diffs.length - 1][1] === '') { 504 + if (diffs.at(-1)?.[1] === '') { 505 505 diffs.pop() 506 506 } // Remove the dummy entry at the end. 507 507
+1 -1
packages/vitest/src/node/projects/resolveProjects.ts
··· 370 370 projectsConfigFiles.push(configFile) 371 371 } 372 372 else { 373 - const directory = file[file.length - 1] === '/' ? file : `${file}/` 373 + const directory = file.at(-1) === '/' ? file : `${file}/` 374 374 nonConfigProjectDirectories.push(directory) 375 375 } 376 376 }
+1 -1
packages/browser/src/client/tester/expect/utils.ts
··· 132 132 array: string[], 133 133 { wordConnector = ', ', lastWordConnector = ' and ' }: ToSentenceOptions = {}, 134 134 ): string { 135 - return [array.slice(0, -1).join(wordConnector), array[array.length - 1]].join( 135 + return [array.slice(0, -1).join(wordConnector), array.at(-1)].join( 136 136 array.length > 1 ? lastWordConnector : '', 137 137 ) 138 138 }