forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use deterministic names for dynamic import (vercel#2788)
* Always use the same name for the same dynamic import. * Add unit tests for the modulePath generation. * Allow tests to run correctly on Windows. * Make the chunk name a bit pretty. * Fix tests to run on Windows.
- Loading branch information
Showing
2 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,42 @@ | ||
/* global describe, it, expect */ | ||
import { getModulePath } from '../../dist/server/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') | ||
}) | ||
}) | ||
}) |