Skip to content

refactor: tidy up #2051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/create-instance/add-mocks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import $$Vue from 'vue'
import { warn } from 'shared/util'
import { warn, keys } from 'shared/util'

export default function addMocks(
_Vue: Component,
Expand All @@ -9,7 +9,7 @@ export default function addMocks(
if (mockedProperties === false) {
return
}
Object.keys(mockedProperties).forEach(key => {
keys(mockedProperties).forEach(key => {
try {
// $FlowIgnore
_Vue.prototype[key] = mockedProperties[key]
Expand Down
2 changes: 1 addition & 1 deletion packages/create-instance/create-component-stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function createStubsFromStubsObject(
stubs: Object,
_Vue: Component
): Components {
return Object.keys(stubs || {}).reduce((acc, stubName) => {
return keys(stubs || {}).reduce((acc, stubName) => {
let stub = stubs[stubName]

validateStub(stub)
Expand Down
5 changes: 3 additions & 2 deletions packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { componentNeedsCompiling, isConstructor } from 'shared/validators'
import createScopedSlots from './create-scoped-slots'
import { createStubsFromStubsObject } from './create-component-stubs'
import { patchCreateElement } from './patch-create-element'
import { keys } from 'shared/util'

function createContext(options, scopedSlots, currentProps) {
const on = {
Expand Down Expand Up @@ -86,8 +87,8 @@ export default function createInstance(

// watchers provided in mounting options should override preexisting ones
if (componentOptions.watch && instanceOptions.watch) {
const componentWatchers = Object.keys(componentOptions.watch)
const instanceWatchers = Object.keys(instanceOptions.watch)
const componentWatchers = keys(componentOptions.watch)
const instanceWatchers = keys(instanceOptions.watch)

for (let i = 0; i < instanceWatchers.length; i++) {
const k = instanceWatchers[i]
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/compile-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { compileToFunctions } from 'vue-template-compiler'
import { componentNeedsCompiling } from './validators'
import { throwError } from './util'
import { throwError, keys } from './util'

export function compileTemplate(component: Component): void {
if (component.template) {
Expand Down Expand Up @@ -31,7 +31,7 @@ export function compileTemplate(component: Component): void {
}

if (component.components) {
Object.keys(component.components).forEach(c => {
keys(component.components).forEach(c => {
const cmp = component.components[c]
if (!cmp.render) {
compileTemplate(cmp)
Expand All @@ -49,7 +49,7 @@ export function compileTemplate(component: Component): void {
}

export function compileTemplateForSlots(slots: Object): void {
Object.keys(slots).forEach(key => {
keys(slots).forEach(key => {
const slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]
slot.forEach(slotValue => {
if (componentNeedsCompiling(slotValue)) {
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/create-local-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Vue from 'vue'
import cloneDeep from 'lodash/cloneDeep'
import { keys } from './util'

/**
* Used internally by vue-server-test-utils and test-utils to propagate/create vue instances.
Expand All @@ -17,7 +18,7 @@ function _createLocalVue(
const instance = _Vue.extend()

// clone global APIs
Object.keys(_Vue).forEach(key => {
keys(_Vue).forEach(key => {
if (!instance.hasOwnProperty(key)) {
const original = _Vue[key]
// cloneDeep can fail when cloning Vue instances
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/merge-options.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @flow
import { normalizeStubs, normalizeProvide } from './normalize'
import { warnDeprecated } from 'shared/util'
import { warnDeprecated, keys } from 'shared/util'

function getOption(option, config?: Object): any {
if (option === false) {
return false
}
if (option || (config && Object.keys(config).length > 0)) {
if (option || (config && keys(config).length > 0)) {
if (option instanceof Function) {
return option
}
Expand Down Expand Up @@ -34,7 +34,7 @@ export function mergeOptions(
const methods = (getOption(options.methods, config.methods): {
[key: string]: Function
})
if (methods && Object.keys(methods).length) {
if (methods && keys(methods).length) {
warnDeprecated(
'overwriting methods via the `methods` property',
'There is no clear migration path for the `methods` property - Vue does not support arbitrarily replacement of methods, nor should VTU. To stub a complex method extract it from the component and test it in isolation. Otherwise, the suggestion is to rethink those tests'
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/validate-slots.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import { throwError } from 'shared/util'
import { throwError, keys } from 'shared/util'
import { compileToFunctions } from 'vue-template-compiler'
import { isVueComponent } from './validators'

Expand All @@ -19,7 +19,7 @@ function requiresTemplateCompiler(slot: any): void {
}

export function validateSlots(slots: SlotsObject): void {
Object.keys(slots).forEach(key => {
keys(slots).forEach(key => {
const slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]

slot.forEach(slotValue => {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/validators.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import { throwError, capitalize, camelize, hyphenate } from './util'
import { throwError, capitalize, camelize, hyphenate, keys } from './util'

export function isDomSelector(selector: any): boolean {
if (typeof selector !== 'string') {
Expand Down Expand Up @@ -64,7 +64,7 @@ export function componentNeedsCompiling(component: Component): boolean {
export function isRefSelector(refOptionsObject: any): boolean {
if (
!isPlainObject(refOptionsObject) ||
Object.keys(refOptionsObject || {}).length !== 1
keys(refOptionsObject || {}).length !== 1
) {
return false
}
Expand Down
3 changes: 2 additions & 1 deletion packages/test-utils/src/create-dom-event.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import eventTypes from 'dom-event-types'
import { keys } from 'shared/util'

const defaultEventType = {
eventInterface: 'Event',
Expand Down Expand Up @@ -108,7 +109,7 @@ export default function createDOMEvent(type, options) {
: createOldEvent(eventParams)

const eventPrototype = Object.getPrototypeOf(event)
Object.keys(options || {}).forEach(key => {
keys(options || {}).forEach(key => {
const propertyDescriptor = Object.getOwnPropertyDescriptor(
eventPrototype,
key
Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/src/matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
FUNCTIONAL_OPTIONS
} from 'shared/consts'
import { isConstructor, isFunctionalComponent } from 'shared/validators'
import { capitalize, camelize } from 'shared/util'
import { capitalize, camelize, keys } from 'shared/util'

function vmMatchesName(vm, name) {
// We want to mirror how Vue resolves component names in SFCs:
Expand Down Expand Up @@ -48,7 +48,7 @@ function vmCtorMatches(vm, component) {
}

if (component.functional) {
return Object.keys(vm._Ctor || {}).some(c => {
return keys(vm._Ctor || {}).some(c => {
return component === vm._Ctor[c].extendOptions
})
}
Expand Down
5 changes: 3 additions & 2 deletions packages/test-utils/src/recursively-set-data.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { isPlainObject } from 'shared/validators'
import { keys } from 'shared/util'

export function recursivelySetData(vm, target, data) {
Object.keys(data).forEach(key => {
keys(data).forEach(key => {
const val = data[key]
const targetVal = target[key]

if (
isPlainObject(val) &&
isPlainObject(targetVal) &&
Object.keys(val).length > 0
keys(val).length > 0
) {
recursivelySetData(vm, targetVal, val)
} else {
Expand Down
28 changes: 13 additions & 15 deletions packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
nextTick,
warn,
warnDeprecated,
isVueWrapper
isVueWrapper,
keys
} from 'shared/util'
import { isPlainObject } from 'shared/validators'
import { isElementVisible } from 'shared/is-visible'
Expand Down Expand Up @@ -124,17 +125,14 @@ export default class Wrapper implements BaseWrapper {
let classes = classAttribute ? classAttribute.split(' ') : []
// Handle converting cssmodules identifiers back to the original class name
if (this.vm && this.vm.$style) {
const cssModuleIdentifiers = Object.keys(this.vm.$style).reduce(
(acc, key) => {
// $FlowIgnore
const moduleIdent = this.vm.$style[key]
if (moduleIdent) {
acc[moduleIdent.split(' ')[0]] = key
}
return acc
},
{}
)
const cssModuleIdentifiers = keys(this.vm.$style).reduce((acc, key) => {
// $FlowIgnore
const moduleIdent = this.vm.$style[key]
if (moduleIdent) {
acc[moduleIdent.split(' ')[0]] = key
}
return acc
}, {})
classes = classes.map(name => cssModuleIdentifiers[name] || name)
}

Expand Down Expand Up @@ -480,7 +478,7 @@ export default class Wrapper implements BaseWrapper {
const computed = this.vm._computedWatchers
? formatJSON(
// $FlowIgnore
...Object.keys(this.vm._computedWatchers).map(computedKey => ({
...keys(this.vm._computedWatchers).map(computedKey => ({
// $FlowIgnore
[computedKey]: this.vm[computedKey]
}))
Expand Down Expand Up @@ -680,7 +678,7 @@ export default class Wrapper implements BaseWrapper {
}
this.__warnIfDestroyed()

Object.keys(methods).forEach(key => {
keys(methods).forEach(key => {
// $FlowIgnore : Problem with possibly null this.vm
this.vm[key] = methods[key]
// $FlowIgnore : Problem with possibly null this.vm
Expand Down Expand Up @@ -717,7 +715,7 @@ export default class Wrapper implements BaseWrapper {

this.__warnIfDestroyed()

Object.keys(data).forEach(key => {
keys(data).forEach(key => {
// Don't let people set entire objects, because reactivity won't work
if (
isPlainObject(data[key]) &&
Expand Down