-
Notifications
You must be signed in to change notification settings - Fork 273
Add global configuration settings #53
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b8f3c75
feat: add globalProperties to mountingOptions
dobromir-hristov 9921db4
refactor: move globalProperties to global property
dobromir-hristov 3ffd3ec
feat: add global config
dobromir-hristov 327c710
refactor: update types and fix broken tests
lmiller1990 f84e87c
refactor: update rollup build
lmiller1990 e1b8a2b
tests: add mocks tests
dobromir-hristov 9d2805a
fix: fix missing type
dobromir-hristov 2ec6d17
chore: remove globalProperties
dobromir-hristov 6785dce
Merge branch 'master' into feat/add-global-properties
dobromir-hristov 0590a4c
chore: remove left over stubs
dobromir-hristov 4ab15cd
chore: merge conflicts
dobromir-hristov f04dfbd
Merge branch 'master' into feat/add-global-properties
dobromir-hristov f7cccd1
Merge branch 'master' into feat/add-global-properties
dobromir-hristov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { GlobalMountOptions } from './types' | ||
|
||
export const config: { global: GlobalMountOptions } = { | ||
global: {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { mount } from './mount' | ||
import { RouterLinkStub } from './components/RouterLinkStub' | ||
import { config } from './config' | ||
|
||
export { mount, RouterLinkStub } | ||
export { mount, RouterLinkStub, config } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,28 @@ import camelCase from 'lodash/camelCase' | |
import upperFirst from 'lodash/upperFirst' | ||
import kebabCase from 'lodash/kebabCase' | ||
import flow from 'lodash/flow' | ||
import mergeWith from 'lodash/mergeWith' | ||
import { GlobalMountOptions } from './types' | ||
|
||
const pascalCase = flow(camelCase, upperFirst) | ||
|
||
export { kebabCase, pascalCase } | ||
|
||
export function mergeGlobalProperties( | ||
configGlobal = {}, | ||
mountGlobal = {} | ||
): GlobalMountOptions { | ||
return mergeWith({}, configGlobal, mountGlobal, (objValue, srcValue, key) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 🙌 |
||
switch (key) { | ||
case 'mocks': | ||
case 'provide': | ||
case 'components': | ||
case 'directives': | ||
case 'globalProperties': | ||
return { ...objValue, ...srcValue } | ||
case 'plugins': | ||
case 'mixins': | ||
return [...(objValue || []), ...(srcValue || [])].filter(Boolean) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not overwrite a plugin or mixin if defined globally first, it will concat them. That should be fine though? |
||
} | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { config, mount } from '../src' | ||
import Hello from './components/Hello.vue' | ||
|
||
describe('config', () => { | ||
beforeEach(() => { | ||
config.global = { | ||
components: undefined, | ||
directives: undefined, | ||
mixins: undefined, | ||
plugins: undefined, | ||
mocks: undefined, | ||
provide: undefined | ||
} | ||
}) | ||
|
||
describe('components', () => { | ||
const Component = { | ||
template: '<div>{{ msg }} <hello/></div>', | ||
props: ['msg'] | ||
} | ||
|
||
it('allows setting components globally', () => { | ||
config.global.components = { Hello } | ||
const wrapper1 = mount(Component, { props: { msg: 'Wrapper1' } }) | ||
const wrapper2 = mount(Component, { props: { msg: 'Wrapper2' } }) | ||
expect(wrapper1.text()).toEqual('Wrapper1 Hello world') | ||
expect(wrapper2.text()).toEqual('Wrapper2 Hello world') | ||
}) | ||
|
||
it('allows overwriting globally set component config on a per mount instance', () => { | ||
config.global.components = { Hello } | ||
const HelloLocal = { template: '<div>Hello Overwritten</div>' } | ||
const wrapper1 = mount(Component, { props: { msg: 'Wrapper1' } }) | ||
const wrapper2 = mount(Component, { | ||
props: { msg: 'Wrapper2' }, | ||
global: { components: { Hello: HelloLocal } } | ||
}) | ||
expect(wrapper1.text()).toEqual('Wrapper1 Hello world') | ||
expect(wrapper2.text()).toEqual('Wrapper2 Hello Overwritten') | ||
}) | ||
}) | ||
|
||
describe('directives', () => { | ||
const Directive = { | ||
beforeMount(el: Element) { | ||
el.classList.add('DirectiveAdded') | ||
} | ||
} | ||
const Component = { template: '<div v-directive>msg</div>' } | ||
|
||
it('allows setting directives globally', () => { | ||
config.global.directives = { Directive } | ||
expect(mount(Component).classes()).toContain('DirectiveAdded') | ||
expect(mount(Component).classes()).toContain('DirectiveAdded') | ||
}) | ||
|
||
it('allows overwriting globally set directives', () => { | ||
config.global.directives = { Directive } | ||
const LocalDirective = { | ||
beforeMount(el: Element) { | ||
el.classList.add('LocallyDirectiveAdded') | ||
} | ||
} | ||
|
||
expect(mount(Component).classes()).toContain('DirectiveAdded') | ||
expect( | ||
mount(Component, { | ||
global: { directives: { Directive: LocalDirective } } | ||
}).classes() | ||
).toContain('LocallyDirectiveAdded') | ||
}) | ||
}) | ||
|
||
describe('mocks', () => { | ||
it('sets mock everywhere', () => { | ||
config.global.mocks = { | ||
foo: 'bar' | ||
} | ||
const Component = { template: '<div>{{ foo }}</div>' } | ||
expect(mount(Component).text()).toEqual('bar') | ||
expect(mount(Component).text()).toEqual('bar') | ||
}) | ||
|
||
it('allows overwriting a global mock', () => { | ||
config.global.mocks = { | ||
foo: 'bar' | ||
} | ||
const Component = { template: '<div>{{ foo }}</div>' } | ||
|
||
expect(mount(Component).text()).toEqual('bar') | ||
expect( | ||
mount(Component, { global: { mocks: { foo: 'baz' } } }).text() | ||
).toEqual('baz') | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add each of the properties here, with an empty array or object?