2017-08-16 17:14:00 +00:00
|
|
|
/* global describe, it, expect */
|
2018-06-14 17:30:14 +00:00
|
|
|
import { getModulePath } from '../../dist/build/babel/plugins/handle-import'
|
2017-08-16 17:14:00 +00:00
|
|
|
|
|
|
|
function cleanPath (mPath) {
|
|
|
|
return mPath
|
|
|
|
.replace(/\\/g, '/')
|
|
|
|
.replace(/^.*:/, '')
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('handle-import-babel-plugin', () => {
|
|
|
|
describe('getModulePath', () => {
|
|
|
|
it('should not do anything to NPM modules', () => {
|
|
|
|
const mPath = getModulePath('/abc/pages/about.js', 'cool-module')
|
|
|
|
expect(mPath).toBe('cool-module')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not do anything to private NPM modules', () => {
|
|
|
|
const mPath = getModulePath('/abc/pages/about.js', '@zeithq/cool-module')
|
|
|
|
expect(mPath).toBe('@zeithq/cool-module')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should resolve local modules', () => {
|
|
|
|
const mPath = getModulePath('/abc/pages/about.js', '../components/hello.js')
|
|
|
|
expect(cleanPath(mPath)).toBe('/abc/components/hello')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should remove index.js', () => {
|
|
|
|
const mPath = getModulePath('/abc/pages/about.js', '../components/c1/index.js')
|
|
|
|
expect(cleanPath(mPath)).toBe('/abc/components/c1')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should remove .js', () => {
|
|
|
|
const mPath = getModulePath('/abc/pages/about.js', '../components/bb.js')
|
|
|
|
expect(cleanPath(mPath)).toBe('/abc/components/bb')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should remove end slash', () => {
|
|
|
|
const mPath = getModulePath('/abc/pages/about.js', '../components/bb/')
|
|
|
|
expect(cleanPath(mPath)).toBe('/abc/components/bb')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|