Skip to content

Commit

Permalink
fix: env option
Browse files Browse the repository at this point in the history
okay, now env is working

BREAKING CHANGE: Default value for env option is changed
  • Loading branch information
Victor Chaptsev committed Dec 6, 2017
1 parent 5bf9978 commit b765a83
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Pass the VueRouter instance to the plugin and let it handle everything for you:

Vue.use(VueYandexMetrika, {
id: XXXXXXXX,
router: router
router: router,
env: process.env.NODE_ENV
// other options
})

Expand All @@ -62,7 +63,7 @@ Pass the VueRouter instance to the plugin and let it handle everything for you:
| -------------- | ----------------------------------------------------------------- | -------- | ------------------------------------------------ |
| id | Your tracking id | True | null |
| router | VueRouter object | True | null |
| env | "production" or "development" | False | [process.env.NODE_ENV] || "production" |
| env | "production" or "development" | False | "development" |
| productionOnly | Do not track a page visit if env is not "production" | False | true |
| skipSamePath | Do not track a page visit if previous and next routes URLs match | False | true |
| ignoreRoutes | List of ignored routes names | False | [] |
Expand Down
25 changes: 8 additions & 17 deletions __tests__/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,16 @@ describe('checkConfig', () => {
describe('checkConfig', () => {
it ('should pass checkConfig', () => {
expect(() => {
Vue.use(VueYandexMetrika, {id: 1, router: router, productionOnly: false})
Vue.use(VueYandexMetrika, {id: 1, router, productionOnly: false})
}).not.toThrowError()
})
})


describe('updateConfig', () => {
it ('env by default', () => {
process.env.NODE_ENV = ''
helpers.updateConfig({})
process.env.NODE_ENV = 'test' // restore default value
expect(config.env).toBe('production')
})
})


describe('updateConfig', () => {
it ('env from process.env', () => {
helpers.updateConfig({})
expect(config.env).toBe('test')
expect(config.env).toBe('development')
})
})

Expand All @@ -71,15 +61,16 @@ describe('updateConfig', () => {

describe('tracking', () => {
it ('productionOnly', () => {
helpers.updateConfig({id: 1, router: router, productionOnly: true, env: 'development'})
expect(helpers.createMetrika(Vue)).toBe(undefined)
helpers.updateConfig({id: 1, router, productionOnly: true, env: 'development'})
var metrika = helpers.createMetrika(Vue)
helpers.startTracking(metrika)
})
})


describe('tracking', () => {
it ('skipSamePath', () => {
helpers.updateConfig({id: 1, router: router, productionOnly: false})
helpers.updateConfig({id: 1, router, productionOnly: false})
var metrika = helpers.createMetrika(Vue)
helpers.startTracking(metrika)
router.push('/init') // init
Expand All @@ -90,7 +81,7 @@ describe('tracking', () => {

describe('tracking', () => {
it ('ignoreRoutes', () => {
helpers.updateConfig({id: 1, router: router, productionOnly: false, ignoreRoutes: ['test']})
helpers.updateConfig({id: 1, router, productionOnly: false, ignoreRoutes: ['test']})
var metrika = helpers.createMetrika(Vue)
helpers.startTracking(metrika)
router.push('/init') // init
Expand All @@ -101,7 +92,7 @@ describe('tracking', () => {

describe('tracking', () => {
it ('metrika.hit', () => {
helpers.updateConfig({id: 1, router: router, productionOnly: false})
helpers.updateConfig({id: 1, router, productionOnly: false})
var metrika = helpers.createMetrika(Vue)
helpers.startTracking(metrika)
router.push('/init') // init
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let config = {
id: null,
router: null,

env: null,
env: 'development',
productionOnly: true,
ignoreRoutes: [],
skipSamePath: true
Expand Down
1 change: 0 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import config from './config'
export function updateConfig (params) {

// Merges default config and plugin options
params['env'] = params['env'] || process.env.NODE_ENV || "production"
Object.keys(params).forEach(function (key) {config[key] = params[key]})
}

Expand Down

0 comments on commit b765a83

Please sign in to comment.