/* @flow */

import * as Helpers from '../src/helpers'

describe('Helpers', function() {
  describe('mergeEnv', function() {
    it('returns env as is if not windows', function() {
      expect(Helpers.mergeEnv({ PATH: 'a;b' }, { PATH: 'c' })).toEqual({ PATH: 'c' })
      expect(Helpers.mergeEnv({ PATH: 'a;b' }, { Path: 'c' })).toEqual({ PATH: 'a;b', Path: 'c' })
      expect(Helpers.mergeEnv({ PATH: 'a;b', Path: 'c', a: 'b' }, { PATH: 'd', b: 'c' })).toEqual({ PATH: 'd', Path: 'c', a: 'b', b: 'c' })
    })
    it('merges env on windows', function() {
      const oldPlatform = process.platform
      let platform = 'win32'
      // $FlowIgnore: Flow is dumb?
      Object.defineProperty(process, 'platform', {
        get() {
          return platform
        },
      })
      expect(Helpers.mergeEnv({ PATH: 'a;b' }, { PATH: 'c' })).toEqual({ PATH: 'a;b;c' })
      expect(Helpers.mergeEnv({ PATH: 'a;b' }, { Path: 'c' })).toEqual({ PATH: 'a;b;c' })
      expect(Helpers.mergeEnv({ PATH: 'a;b', Path: 'c', e: 'f' }, { PATH: 'd', e: 'g' })).toEqual({ PATH: 'a;b;c;d', e: 'g' })
      expect(Helpers.mergeEnv({ PATH: 'a;b', Path: 'c', a: 'b', c: 'd' }, { })).toEqual({ PATH: 'a;b;c', a: 'b', c: 'd' })
      platform = oldPlatform
    })
  })
  describe('mergePath', function() {
    it('merges multiple paths', function() {
      expect(Helpers.mergePath('a;b', 'c;d')).toBe('a;b;c;d')
    })
    it('does not include duplicates', function() {
      expect(Helpers.mergePath('a;b', 'a;c')).toBe('a;b;c')
    })
    it('does not include empty stuff', function() {
      expect(Helpers.mergePath('', '')).toBe('')
      expect(Helpers.mergePath('a;', '')).toBe('a')
      expect(Helpers.mergePath('a;', ';c')).toBe('a;c')
    })
    it('trims the stuff included', function() {
      expect(Helpers.mergePath('; a ; b ; c ; d ;', 'g ; e')).toBe('a;b;c;d;g;e')
    })
  })
})

@@ -166,32 +166,254 @@
 ', function() %7B%0A
+      const oldPlatform = process.platform%0A      let platform = 'darwin'%0A      // $FlowIgnore: Flow is dumb?%0A      Object.defineProperty(process, 'platform', %7B%0A        get() %7B%0A          return platform%0A        %7D,%0A      %7D)%0A
       expect(Hel
@@ -717,24 +717,53 @@
 , b: 'c' %7D)%0A
+      platform = oldPlatform%0A
     %7D)%0A    i

Fix specs for windows