From 56f6577e25af14896acb6b49a352f19b91d75436 Mon Sep 17 00:00:00 2001 From: pimlie Date: Thu, 11 Jul 2019 21:43:05 +0200 Subject: [PATCH] chore: fix lint --- src/browser.js | 2 +- src/client/$meta.js | 4 ++-- src/client/refresh.js | 4 ++-- src/client/update.js | 4 ++-- src/client/updateClientMetaInfo.js | 4 ++-- src/client/updaters/attribute.js | 2 +- src/client/updaters/tag.js | 3 +-- src/client/updaters/title.js | 2 +- src/index.js | 2 +- src/server/$meta.js | 4 ++-- src/server/generateServerInjector.js | 2 +- src/server/generators/attribute.js | 4 ++-- src/server/generators/tag.js | 5 ++--- src/server/generators/title.js | 4 ++-- src/server/inject.js | 4 ++-- src/shared/escaping.js | 6 +++--- src/shared/getComponentOption.js | 2 +- src/shared/getMetaInfo.js | 2 +- src/shared/merge.js | 4 ++-- src/shared/meta-helpers.js | 4 ++-- src/shared/mixin.js | 6 +++--- src/shared/nav-guards.js | 2 +- src/shared/options.js | 4 ++-- src/shared/pausing.js | 4 ++-- src/shared/template.js | 2 +- src/utils/array.js | 6 +++--- src/utils/ensure.js | 4 ++-- src/utils/is-type.js | 10 +++++----- src/utils/window.js | 2 +- test/e2e/browser.test.js | 6 +++--- test/fixtures/basic/router.js | 2 +- test/unit/components.test.js | 26 +++++++++++++------------- test/unit/getComponentOptions.test.js | 6 +++--- test/unit/getMetaInfo.test.js | 4 ++-- test/unit/plugin-browser.test.js | 4 ++-- test/utils/browser.js | 16 ++++++++-------- test/utils/build.js | 6 +++--- test/utils/chrome.js | 24 ++++++++++++------------ test/utils/index.js | 4 ++-- test/utils/meta-info-data.js | 6 +++--- 40 files changed, 105 insertions(+), 107 deletions(-) diff --git a/src/browser.js b/src/browser.js index 63b645e..4b1b237 100644 --- a/src/browser.js +++ b/src/browser.js @@ -9,7 +9,7 @@ import { hasMetaInfo } from './shared/meta-helpers' * Plugin install function. * @param {Function} Vue - the Vue constructor. */ -function install(Vue, options = {}) { +function install (Vue, options = {}) { if (Vue.__vuemeta_installed) { return } diff --git a/src/client/$meta.js b/src/client/$meta.js index bc55fc9..a18c980 100644 --- a/src/client/$meta.js +++ b/src/client/$meta.js @@ -3,7 +3,7 @@ import { getOptions } from '../shared/options' import { pause, resume } from '../shared/pausing' import refresh from './refresh' -export default function _$meta(options = {}) { +export default function _$meta (options = {}) { const _refresh = refresh(options) const inject = () => {} @@ -12,7 +12,7 @@ export default function _$meta(options = {}) { * @this {Object} - the Vue instance (a root component) * @return {Object} - injector */ - return function $meta() { + return function $meta () { if (!this.$root._vueMeta) { return { getOptions: showWarningNotSupported, diff --git a/src/client/refresh.js b/src/client/refresh.js index c87be7d..76dcadd 100644 --- a/src/client/refresh.js +++ b/src/client/refresh.js @@ -3,7 +3,7 @@ import { isFunction } from '../utils/is-type' import { clientSequences } from '../shared/escaping' import updateClientMetaInfo from './updateClientMetaInfo' -export default function _refresh(options = {}) { +export default function _refresh (options = {}) { /** * When called, will update the current meta info with new meta info. * Useful when updating meta info as the result of an asynchronous @@ -14,7 +14,7 @@ export default function _refresh(options = {}) { * * @return {Object} - new meta info */ - return function refresh() { + return function refresh () { const metaInfo = getMetaInfo(options, this.$root, clientSequences) const appId = this.$root._vueMeta.appId diff --git a/src/client/update.js b/src/client/update.js index e56d6f6..a61eb78 100644 --- a/src/client/update.js +++ b/src/client/update.js @@ -1,7 +1,7 @@ // store an id to keep track of DOM updates let batchId = null -export function triggerUpdate(vm, hookName) { +export function triggerUpdate (vm, hookName) { // if an update was triggered during initialization or when an update was triggered by the // metaInfo watcher, set initialized to null // then we keep falsy value but know we need to run a triggerUpdate after initialization @@ -22,7 +22,7 @@ export function triggerUpdate(vm, hookName) { * @param {Function} callback - the update to perform * @return {Number} id - a new ID */ -export function batchUpdate(callback, timeout = 10) { +export function batchUpdate (callback, timeout = 10) { clearTimeout(batchId) batchId = setTimeout(() => { diff --git a/src/client/updateClientMetaInfo.js b/src/client/updateClientMetaInfo.js index c4ab4f5..1b6313b 100644 --- a/src/client/updateClientMetaInfo.js +++ b/src/client/updateClientMetaInfo.js @@ -3,7 +3,7 @@ import { isArray } from '../utils/is-type' import { includes } from '../utils/array' import { updateAttribute, updateTag, updateTitle } from './updaters' -function getTag(tags, tag) { +function getTag (tags, tag) { if (!tags[tag]) { tags[tag] = document.getElementsByTagName(tag)[0] } @@ -16,7 +16,7 @@ function getTag(tags, tag) { * * @param {Object} newInfo - the meta info to update to */ -export default function updateClientMetaInfo(appId, options = {}, newInfo) { +export default function updateClientMetaInfo (appId, options = {}, newInfo) { const { ssrAttribute } = options // only cache tags for current update diff --git a/src/client/updaters/attribute.js b/src/client/updaters/attribute.js index cb68f70..fcf17eb 100644 --- a/src/client/updaters/attribute.js +++ b/src/client/updaters/attribute.js @@ -8,7 +8,7 @@ import { isArray } from '../../utils/is-type' * @param {Object} attrs - the new document html attributes * @param {HTMLElement} tag - the HTMLElement tag to update with new attrs */ -export default function updateAttribute({ attribute } = {}, attrs, tag) { +export default function updateAttribute ({ attribute } = {}, attrs, tag) { const vueMetaAttrString = tag.getAttribute(attribute) const vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : [] const toRemove = toArray(vueMetaAttrs) diff --git a/src/client/updaters/tag.js b/src/client/updaters/tag.js index affb0fb..1a36ebe 100644 --- a/src/client/updaters/tag.js +++ b/src/client/updaters/tag.js @@ -1,5 +1,4 @@ import { booleanHtmlAttributes } from '../../shared/constants' -import { isUndefined } from '../../utils/is-type' import { toArray, includes } from '../../utils/array' /** @@ -10,7 +9,7 @@ import { toArray, includes } from '../../utils/array' * @param {(Array|Object)} tags - an array of tag objects or a single object in case of base * @return {Object} - a representation of what tags changed */ -export default function updateTag(appId, { attribute, tagIDKeyName } = {}, type, tags, headTag, bodyTag) { +export default function updateTag (appId, { attribute, tagIDKeyName } = {}, type, tags, headTag, bodyTag) { const oldHeadTags = toArray(headTag.querySelectorAll(`${type}[${attribute}="${appId}"], ${type}[data-${tagIDKeyName}]`)) const oldBodyTags = toArray(bodyTag.querySelectorAll(`${type}[${attribute}="${appId}"][data-body="true"], ${type}[data-${tagIDKeyName}][data-body="true"]`)) const dataAttributes = [tagIDKeyName, 'body'] diff --git a/src/client/updaters/title.js b/src/client/updaters/title.js index 3db3f1c..07d577c 100644 --- a/src/client/updaters/title.js +++ b/src/client/updaters/title.js @@ -3,7 +3,7 @@ * * @param {String} title - the new title of the document */ -export default function updateTitle(title) { +export default function updateTitle (title) { if (title === undefined) { return } diff --git a/src/index.js b/src/index.js index 16c4a2c..275435a 100644 --- a/src/index.js +++ b/src/index.js @@ -8,7 +8,7 @@ import { hasMetaInfo } from './shared/meta-helpers' * Plugin install function. * @param {Function} Vue - the Vue constructor. */ -function install(Vue, options = {}) { +function install (Vue, options = {}) { if (Vue.__vuemeta_installed) { return } diff --git a/src/server/$meta.js b/src/server/$meta.js index 42694a6..d731ac9 100644 --- a/src/server/$meta.js +++ b/src/server/$meta.js @@ -3,7 +3,7 @@ import { pause, resume } from '../shared/pausing' import refresh from '../client/refresh' import inject from './inject' -export default function _$meta(options = {}) { +export default function _$meta (options = {}) { const _refresh = refresh(options) const _inject = inject(options) @@ -12,7 +12,7 @@ export default function _$meta(options = {}) { * @this {Object} - the Vue instance (a root component) * @return {Object} - injector */ - return function $meta() { + return function $meta () { return { getOptions: () => getOptions(options), refresh: _refresh.bind(this), diff --git a/src/server/generateServerInjector.js b/src/server/generateServerInjector.js index a0d8fa3..6b343f2 100644 --- a/src/server/generateServerInjector.js +++ b/src/server/generateServerInjector.js @@ -9,7 +9,7 @@ import { titleGenerator, attributeGenerator, tagGenerator } from './generators' * @return {Object} - the new injector */ -export default function generateServerInjector(appId, options, type, data) { +export default function generateServerInjector (appId, options, type, data) { if (type === 'title') { return titleGenerator(appId, options, type, data) } diff --git a/src/server/generators/attribute.js b/src/server/generators/attribute.js index ff0933e..25147e3 100644 --- a/src/server/generators/attribute.js +++ b/src/server/generators/attribute.js @@ -8,9 +8,9 @@ import { isUndefined, isArray } from '../../utils/is-type' * @param {Object} data - the attributes to generate * @return {Object} - the attribute generator */ -export default function attributeGenerator({ attribute } = {}, type, data) { +export default function attributeGenerator ({ attribute } = {}, type, data) { return { - text() { + text () { let attributeStr = '' const watchedAttrs = [] diff --git a/src/server/generators/tag.js b/src/server/generators/tag.js index 109aa54..ba560b8 100644 --- a/src/server/generators/tag.js +++ b/src/server/generators/tag.js @@ -1,5 +1,4 @@ import { booleanHtmlAttributes, tagsWithoutEndTag, tagsWithInnerContent, tagAttributeAsInnerContent } from '../../shared/constants' -import { isUndefined } from '../../utils/is-type' /** * Generates meta, base, link, style, script, noscript tags for use on the server @@ -8,9 +7,9 @@ import { isUndefined } from '../../utils/is-type' * @param {(Array|Object)} tags - an array of tag objects or a single object in case of base * @return {Object} - the tag generator */ -export default function tagGenerator(appId, { attribute, tagIDKeyName } = {}, type, tags) { +export default function tagGenerator (appId, { attribute, tagIDKeyName } = {}, type, tags) { return { - text({ body = false } = {}) { + text ({ body = false } = {}) { // build a string containing all tags of this type return tags.reduce((tagsStr, tag) => { const tagKeys = Object.keys(tag) diff --git a/src/server/generators/title.js b/src/server/generators/title.js index d8ed1e4..3c11690 100644 --- a/src/server/generators/title.js +++ b/src/server/generators/title.js @@ -5,9 +5,9 @@ * @param {String} data - the title text * @return {Object} - the title generator */ -export default function titleGenerator(appId, { attribute } = {}, type, data) { +export default function titleGenerator (appId, { attribute } = {}, type, data) { return { - text() { + text () { return `<${type}>${data}` } } diff --git a/src/server/inject.js b/src/server/inject.js index 8faf512..7d0de38 100644 --- a/src/server/inject.js +++ b/src/server/inject.js @@ -3,7 +3,7 @@ import { metaInfoOptionKeys } from '../shared/constants' import { serverSequences } from '../shared/escaping' import generateServerInjector from './generateServerInjector' -export default function _inject(options = {}) { +export default function _inject (options = {}) { /** * Converts the state of the meta info object such that each item * can be compiled to a tag string on the server @@ -11,7 +11,7 @@ export default function _inject(options = {}) { * @this {Object} - Vue instance - ideally the root component * @return {Object} - server meta info with `toString` methods */ - return function inject() { + return function inject () { // get meta info with sensible defaults const metaInfo = getMetaInfo(options, this.$root, serverSequences) diff --git a/src/shared/escaping.js b/src/shared/escaping.js index fe28a28..b9873b3 100644 --- a/src/shared/escaping.js +++ b/src/shared/escaping.js @@ -12,14 +12,14 @@ export const serverSequences = [ export const clientSequences = [ [/&/g, '\u0026'], - [//g, '\u003e'], + [//g, '\u003E'], [/"/g, '\u0022'], [/'/g, '\u0027'] ] // sanitizes potentially dangerous characters -export function escape(info, options, escapeOptions) { +export function escape (info, options, escapeOptions) { const { tagIDKeyName } = options const { doEscape = v => v } = escapeOptions const escaped = {} diff --git a/src/shared/getComponentOption.js b/src/shared/getComponentOption.js index 16485a0..27d8b3f 100644 --- a/src/shared/getComponentOption.js +++ b/src/shared/getComponentOption.js @@ -18,7 +18,7 @@ import { inMetaInfoBranch } from './meta-helpers' * @param {Object} [result={}] - result so far * @return {Object} result - final aggregated result */ -export default function getComponentOption(options = {}, component, result = {}) { +export default function getComponentOption (options = {}, component, result = {}) { const { keyName, metaTemplateKeyName, tagIDKeyName } = options const { $options, $children } = component diff --git a/src/shared/getMetaInfo.js b/src/shared/getMetaInfo.js index a94d79a..5be688a 100644 --- a/src/shared/getMetaInfo.js +++ b/src/shared/getMetaInfo.js @@ -11,7 +11,7 @@ import getComponentOption from './getComponentOption' * @param {Object} component - the Vue instance to get meta info from * @return {Object} - returned meta info */ -export default function getMetaInfo(options = {}, component, escapeSequences = []) { +export default function getMetaInfo (options = {}, component, escapeSequences = []) { // collect & aggregate all metaInfo $options let info = getComponentOption(options, component, defaultInfo) diff --git a/src/shared/merge.js b/src/shared/merge.js index 8c184d5..7015807 100644 --- a/src/shared/merge.js +++ b/src/shared/merge.js @@ -3,7 +3,7 @@ import { findIndex } from '../utils/array' import { applyTemplate } from './template' import { metaInfoAttributeKeys, booleanHtmlAttributes } from './constants' -export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) { +export function arrayMerge ({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) { // we concat the arrays without merging objects contained in, // but we check for a `vmid` property on each object in the array // using an O(1) lookup associative array exploit @@ -65,7 +65,7 @@ export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, conte return destination.concat(source) } -export function merge(target, source, options = {}) { +export function merge (target, source, options = {}) { // remove properties explicitly set to false so child components can // optionally _not_ overwrite the parents content // (for array properties this is checked in arrayMerge) diff --git a/src/shared/meta-helpers.js b/src/shared/meta-helpers.js index d1d7ac2..347dd08 100644 --- a/src/shared/meta-helpers.js +++ b/src/shared/meta-helpers.js @@ -1,11 +1,11 @@ import { isUndefined, isObject } from '../utils/is-type' // Vue $root instance has a _vueMeta object property, otherwise its a boolean true -export function hasMetaInfo(vm = this) { +export function hasMetaInfo (vm = this) { return vm && (vm._vueMeta === true || isObject(vm._vueMeta)) } // a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has -export function inMetaInfoBranch(vm = this) { +export function inMetaInfoBranch (vm = this) { return vm && !isUndefined(vm._vueMeta) } diff --git a/src/shared/mixin.js b/src/shared/mixin.js index 296738c..a06a8ff 100644 --- a/src/shared/mixin.js +++ b/src/shared/mixin.js @@ -6,16 +6,16 @@ import { addNavGuards } from './nav-guards' let appId = 1 -export default function createMixin(Vue, options) { +export default function createMixin (Vue, options) { // for which Vue lifecycle hooks should the metaInfo be refreshed const updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount'] // watch for client side component updates return { - beforeCreate() { + beforeCreate () { Object.defineProperty(this, '_hasMetaInfo', { configurable: true, - get() { + get () { // Show deprecation warning once when devtools enabled if (Vue.config.devtools && !this.$root._vueMeta.hasMetaInfoDeprecationWarningShown) { console.warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead') // eslint-disable-line no-console diff --git a/src/shared/nav-guards.js b/src/shared/nav-guards.js index edbae81..106c414 100644 --- a/src/shared/nav-guards.js +++ b/src/shared/nav-guards.js @@ -1,6 +1,6 @@ import { isFunction } from '../utils/is-type' -export function addNavGuards(vm) { +export function addNavGuards (vm) { // return when nav guards already added or no router exists if (vm.$root._vueMeta.navGuards || !vm.$root.$router) { /* istanbul ignore next */ diff --git a/src/shared/options.js b/src/shared/options.js index deb8079..88a3254 100644 --- a/src/shared/options.js +++ b/src/shared/options.js @@ -1,7 +1,7 @@ import { isObject } from '../utils/is-type' import { defaultOptions } from './constants' -export function setOptions(options) { +export function setOptions (options) { // combine options options = isObject(options) ? options : {} @@ -14,7 +14,7 @@ export function setOptions(options) { return options } -export function getOptions(options) { +export function getOptions (options) { const optionsCopy = {} for (const key in options) { optionsCopy[key] = options[key] diff --git a/src/shared/pausing.js b/src/shared/pausing.js index 65e5b45..44253cd 100644 --- a/src/shared/pausing.js +++ b/src/shared/pausing.js @@ -1,10 +1,10 @@ -export function pause(refresh = true) { +export function pause (refresh = true) { this.$root._vueMeta.paused = true return () => resume(refresh) } -export function resume(refresh = true) { +export function resume (refresh = true) { this.$root._vueMeta.paused = false if (refresh) { diff --git a/src/shared/template.js b/src/shared/template.js index 1de07b0..340ce51 100644 --- a/src/shared/template.js +++ b/src/shared/template.js @@ -1,6 +1,6 @@ import { isUndefined, isFunction } from '../utils/is-type' -export function applyTemplate({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) { +export function applyTemplate ({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) { if (isUndefined(template)) { template = headObject[metaTemplateKeyName] delete headObject[metaTemplateKeyName] diff --git a/src/utils/array.js b/src/utils/array.js index 7ac529c..3f77000 100644 --- a/src/utils/array.js +++ b/src/utils/array.js @@ -11,7 +11,7 @@ // which means the polyfills are removed for other build formats const polyfill = process.env.NODE_ENV === 'test' -export function findIndex(array, predicate) { +export function findIndex (array, predicate) { if (polyfill && !Array.prototype.findIndex) { // idx needs to be a Number, for..in returns string for (let idx = 0; idx < array.length; idx++) { @@ -24,14 +24,14 @@ export function findIndex(array, predicate) { return array.findIndex(predicate, arguments[2]) } -export function toArray(arg) { +export function toArray (arg) { if (polyfill && !Array.from) { return Array.prototype.slice.call(arg) } return Array.from(arg) } -export function includes(array, value) { +export function includes (array, value) { if (polyfill && !Array.prototype.includes) { for (const idx in array) { if (array[idx] === value) { diff --git a/src/utils/ensure.js b/src/utils/ensure.js index 865ac3e..e17e2aa 100644 --- a/src/utils/ensure.js +++ b/src/utils/ensure.js @@ -1,6 +1,6 @@ import { isArray, isObject } from './is-type' -export function ensureIsArray(arg, key) { +export function ensureIsArray (arg, key) { if (!key || !isObject(arg)) { return isArray(arg) ? arg : [] } @@ -11,7 +11,7 @@ export function ensureIsArray(arg, key) { return arg } -export function ensuredPush(object, key, el) { +export function ensuredPush (object, key, el) { ensureIsArray(object, key) object[key].push(el) diff --git a/src/utils/is-type.js b/src/utils/is-type.js index 83dfeb3..31ce5ea 100644 --- a/src/utils/is-type.js +++ b/src/utils/is-type.js @@ -3,22 +3,22 @@ * @param {any} arg - the object to check * @return {Boolean} - true if `arg` is an array */ -export function isArray(arg) { +export function isArray (arg) { return Array.isArray(arg) } -export function isUndefined(arg) { +export function isUndefined (arg) { return typeof arg === 'undefined' } -export function isObject(arg) { +export function isObject (arg) { return typeof arg === 'object' } -export function isFunction(arg) { +export function isFunction (arg) { return typeof arg === 'function' } -export function isString(arg) { +export function isString (arg) { return typeof arg === 'string' } diff --git a/src/utils/window.js b/src/utils/window.js index d31dbab..555207c 100644 --- a/src/utils/window.js +++ b/src/utils/window.js @@ -1,6 +1,6 @@ import { isUndefined } from './is-type' -export function hasGlobalWindowFn() { +export function hasGlobalWindowFn () { try { return !isUndefined(window) } catch (e) { diff --git a/test/e2e/browser.test.js b/test/e2e/browser.test.js index fd769f9..f872fb6 100644 --- a/test/e2e/browser.test.js +++ b/test/e2e/browser.test.js @@ -23,9 +23,9 @@ describe(browserString, () => { browser = await createBrowser(browserString, { BrowserStackLocal: { folder }, - extendPage(page) { + extendPage (page) { return { - async navigate(path) { + async navigate (path) { // IMPORTANT: use (arrow) function with block'ed body // see: https://github.com/tunnckoCoreLabs/parse-function/issues/179 await page.runAsyncScript((path) => { @@ -49,7 +49,7 @@ describe(browserString, () => { }) }, path) }, - routeData() { + routeData () { return page.runScript(() => ({ path: window.$vueMeta.$route.path, query: window.$vueMeta.$route.query diff --git a/test/fixtures/basic/router.js b/test/fixtures/basic/router.js index 35c8dcd..a75d67d 100644 --- a/test/fixtures/basic/router.js +++ b/test/fixtures/basic/router.js @@ -6,7 +6,7 @@ Vue.use(Router) const Post = () => import('./views/about.vue') -export default function createRouter() { +export default function createRouter () { return new Router({ mode: 'hash', base: '/', diff --git a/test/unit/components.test.js b/test/unit/components.test.js index 1abc9d5..431b647 100644 --- a/test/unit/components.test.js +++ b/test/unit/components.test.js @@ -110,7 +110,7 @@ describe('client', () => { const Component = Vue.extend({ metaInfo: { title: 'Test' }, - render(h) { + render (h) { return h('div', null, 'Test') } }) @@ -157,10 +157,10 @@ describe('client', () => { localVue: Vue, mocks: { $router: { - beforeEach(fn) { + beforeEach (fn) { guards.before = fn }, - afterEach(fn) { + afterEach (fn) { guards.after = fn } } @@ -192,10 +192,10 @@ describe('client', () => { localVue: Vue, mocks: { $router: { - beforeEach(fn) { + beforeEach (fn) { guards.before = fn }, - afterEach(fn) { + afterEach (fn) { guards.after = fn } } @@ -225,21 +225,21 @@ describe('client', () => { // this component uses a computed prop to simulate a non-synchronous // metaInfo update like you would have with a Vuex mutation const Component = Vue.extend({ - data() { + data () { return { hiddenTheme: 'light' } }, computed: { - theme() { + theme () { return this.hiddenTheme } }, - beforeMount() { + beforeMount () { this.hiddenTheme = 'dark' }, render: h => h('div'), - metaInfo() { + metaInfo () { return { htmlAttrs: { theme: this.theme @@ -270,21 +270,21 @@ describe('client', () => { document.body.appendChild(el) const Component = Vue.extend({ - data() { + data () { return { hiddenTheme: 'light' } }, computed: { - theme() { + theme () { return this.hiddenTheme } }, - mounted() { + mounted () { this.hiddenTheme = 'dark' }, render: h => h('div'), - metaInfo() { + metaInfo () { return { htmlAttrs: { theme: this.theme diff --git a/test/unit/getComponentOptions.test.js b/test/unit/getComponentOptions.test.js index 5d482b7..90ca394 100644 --- a/test/unit/getComponentOptions.test.js +++ b/test/unit/getComponentOptions.test.js @@ -23,7 +23,7 @@ describe('getComponentOption', () => { test('calls a function option, injecting the component as context', () => { const component = new Vue({ name: 'Foobar', - someFunc() { + someFunc () { return { opt: this.$options.name } } }) @@ -90,13 +90,13 @@ describe('getComponentOption', () => { localVue.component('meta-child', { foo: { bar: 'baz' }, - render(h) { + render (h) { return h('div', this.$slots.default) } }) localVue.component('nometa-child', { - render(h) { + render (h) { return h('div', this.$slots.default) } }) diff --git a/test/unit/getMetaInfo.test.js b/test/unit/getMetaInfo.test.js index 13573ed..475ee86 100644 --- a/test/unit/getMetaInfo.test.js +++ b/test/unit/getMetaInfo.test.js @@ -208,7 +208,7 @@ describe('getMetaInfo', () => { { charset: 'utf-8' } ] }, - data() { + data () { return { helloWorldText: 'Function World' } @@ -648,7 +648,7 @@ describe('getMetaInfo', () => { test('no errors when metaInfo returns nothing', () => { const component = new Vue({ - metaInfo() {}, + metaInfo () {}, el: document.createElement('div'), render: h => h('div', null, []) }) diff --git a/test/unit/plugin-browser.test.js b/test/unit/plugin-browser.test.js index e5871bb..9115455 100644 --- a/test/unit/plugin-browser.test.js +++ b/test/unit/plugin-browser.test.js @@ -90,7 +90,7 @@ describe('plugin', () => { }) const Component = Vue.component('test-component', { - metaInfo() { + metaInfo () { return { title: this.title } @@ -161,7 +161,7 @@ describe('plugin', () => { }) const Component = Vue.component('test-component', { - metaInfo() { + metaInfo () { return { title: this.title } diff --git a/test/utils/browser.js b/test/utils/browser.js index def5b19..197efc7 100644 --- a/test/utils/browser.js +++ b/test/utils/browser.js @@ -3,11 +3,11 @@ import puppeteer from 'puppeteer-core' import ChromeDetector from './chrome' export default class Browser { - constructor() { + constructor () { this.detector = new ChromeDetector() } - async start(options = {}) { + async start (options = {}) { // https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions const _opts = { args: [ @@ -25,13 +25,13 @@ export default class Browser { this.browser = await puppeteer.launch(_opts) } - async close() { - if (!this.browser) return + async close () { + if (!this.browser) { return } await this.browser.close() } - async page(url, globalName = 'vueMeta') { - if (!this.browser) throw new Error('Please call start() before page(url)') + async page (url, globalName = 'vueMeta') { + if (!this.browser) { throw new Error('Please call start() before page(url)') } const page = await this.browser.newPage() // pass on console messages @@ -69,7 +69,7 @@ export default class Browser { page.$vueMeta = await page.evaluateHandle(page.$globalHandle) page.vueMeta = { - async navigate(path, waitEnd = true) { + async navigate (path, waitEnd = true) { const hook = page.evaluate(` new Promise(resolve => ${page.$globalHandle}.$once('routeChanged', resolve) @@ -85,7 +85,7 @@ export default class Browser { } return { hook } }, - routeData() { + routeData () { return page.evaluate(($vueMeta) => { return { path: $vueMeta.$route.path, diff --git a/test/utils/build.js b/test/utils/build.js index ecfe7b8..b145fc3 100644 --- a/test/utils/build.js +++ b/test/utils/build.js @@ -7,7 +7,7 @@ import { createRenderer } from 'vue-server-renderer' const renderer = createRenderer() -export function webpackRun(config) { +export function webpackRun (config) { const compiler = webpack(config) return new Promise((resolve, reject) => { @@ -21,7 +21,7 @@ export function webpackRun(config) { }) } -export async function buildFixture(fixture, config = {}) { +export async function buildFixture (fixture, config = {}) { if (!fixture) { throw new Error('buildFixture should be called with a fixture name') } @@ -69,7 +69,7 @@ export async function buildFixture(fixture, config = {}) { } } -export function createWebpackConfig(config = {}) { +export function createWebpackConfig (config = {}) { const publicPath = '.vue-meta' return { diff --git a/test/utils/chrome.js b/test/utils/chrome.js index e6c54f4..96066aa 100644 --- a/test/utils/chrome.js +++ b/test/utils/chrome.js @@ -17,19 +17,19 @@ const newLineRegex = /\r?\n/ * https://github.com/gwuhaolin/chrome-finder */ export default class ChromeDetector { - constructor() { + constructor () { this.platform = isWsl ? 'wsl' : process.platform } - detect(platform = this.platform) { + detect (platform = this.platform) { const handler = this[platform] if (typeof handler !== 'function') { - throw new Error(`${platform} is not supported.`) + throw new TypeError(`${platform} is not supported.`) } return this[platform]()[0] } - darwin() { + darwin () { const suffixes = [ '/Contents/MacOS/Chromium', '/Contents/MacOS/Google Chrome Canary', @@ -88,7 +88,7 @@ export default class ChromeDetector { * 2. Look into the directories where .desktop are saved on gnome based distro's * 3. Look for google-chrome-stable & google-chrome executables by using the which command */ - linux() { + linux () { let installations = [] // 1. Look into CHROME_PATH env variable const customChromePath = this.resolveChromePath() @@ -147,7 +147,7 @@ export default class ChromeDetector { return this.sort(uniq(installations.filter(Boolean)), priorities) } - wsl() { + wsl () { // Manually populate the environment variables assuming it's the default config process.env.LOCALAPPDATA = this.getLocalAppDataPath(process.env.PATH) process.env.PROGRAMFILES = '/mnt/c/Program Files' @@ -155,7 +155,7 @@ export default class ChromeDetector { return this.win32() } - win32() { + win32 () { const installations = [] const sep = path.sep const suffixes = [ @@ -185,7 +185,7 @@ export default class ChromeDetector { return installations } - resolveChromePath() { + resolveChromePath () { if (this.canAccess(process.env.CHROME_PATH)) { return process.env.CHROME_PATH } @@ -198,13 +198,13 @@ export default class ChromeDetector { } } - getLocalAppDataPath(path) { + getLocalAppDataPath (path) { const userRegExp = /\/mnt\/([a-z])\/Users\/([^/:]+)\/AppData\// const results = userRegExp.exec(path) || [] return `/mnt/${results[1]}/Users/${results[2]}/AppData/Local` } - sort(installations, priorities) { + sort (installations, priorities) { const defaultPriority = 10 return installations .map((inst) => { @@ -219,7 +219,7 @@ export default class ChromeDetector { .map(pair => pair.path) } - canAccess(file) { + canAccess (file) { if (!file) { return false } @@ -231,7 +231,7 @@ export default class ChromeDetector { } } - findChromeExecutables(folder) { + findChromeExecutables (folder) { const argumentsRegex = /(^[^ ]+).*/ // Take everything up to the first space const chromeExecRegex = '^Exec=/.*/(google-chrome|chrome|chromium)-.*' const installations = [] diff --git a/test/utils/index.js b/test/utils/index.js index a1812df..76f916f 100644 --- a/test/utils/index.js +++ b/test/utils/index.js @@ -13,11 +13,11 @@ export { VueMetaServerPlugin } -export function getVue() { +export function getVue () { return createLocalVue() } -export function loadVueMetaPlugin(browser, options, localVue = getVue()) { +export function loadVueMetaPlugin (browser, options, localVue = getVue()) { if (browser) { localVue.use(VueMetaBrowserPlugin, Object.assign({}, defaultOptions, options)) } else { diff --git a/test/utils/meta-info-data.js b/test/utils/meta-info-data.js index 1e2e1ec..98979e2 100644 --- a/test/utils/meta-info-data.js +++ b/test/utils/meta-info-data.js @@ -5,7 +5,7 @@ const metaInfoData = { add: { data: 'Hello World', expect: ['Hello World'], - test(side, defaultTest) { + test (side, defaultTest) { if (side === 'client') { // client side vue-meta uses document.title and doesnt change the html return () => { @@ -65,7 +65,7 @@ const metaInfoData = { '', '' ], - test(side, defaultTest) { + test (side, defaultTest) { if (side === 'client') { return () => { const tags = defaultTest() @@ -120,7 +120,7 @@ const metaInfoData = { '', '' ], - test(side, defaultTest) { + test (side, defaultTest) { return () => { if (side === 'client') { for (const index in this.expect) {