1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/test/unit/handle-import-babel-plugin.test.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

/* global describe, it, expect */
import { getModulePath } from '../../dist/build/babel/plugins/handle-import'
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')
})
})
})