Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make pageExtensions configurable (#3787)
* Make page require faster * Add windows search/replace * Use normalize instead of resolve * Add remaining tests * Use sep instead of / * Add test files * Make component require faster * Add console.error * Make pageExtensions configurable * Remove resolve.js * Add test for `.jsx` * Also resolve `/nav/index` and the likes * Normalize page paths * Use config passed off by webpack
- Loading branch information
1 parent
64379ee
commit 903f15a
Showing
8 changed files
with
111 additions
and
167 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
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,68 @@ | ||
/* global describe, it, expect */ | ||
|
||
import {normalize} from 'path' | ||
import {getPageEntries, createEntry} from '../../dist/server/build/webpack/utils' | ||
|
||
describe('createEntry', () => { | ||
it('Should turn a path into a page entry', () => { | ||
const entry = createEntry('pages/index.js') | ||
expect(entry.name).toBe(normalize('bundles/pages/index.js')) | ||
expect(entry.files[0]).toBe('./pages/index.js') | ||
}) | ||
|
||
it('Should have a custom name', () => { | ||
const entry = createEntry('pages/index.js', {name: 'something-else.js'}) | ||
expect(entry.name).toBe(normalize('bundles/something-else.js')) | ||
expect(entry.files[0]).toBe('./pages/index.js') | ||
}) | ||
|
||
it('Should allow custom extension like .ts to be turned into .js', () => { | ||
const entry = createEntry('pages/index.ts', {pageExtensions: ['js', 'ts'].join('|')}) | ||
expect(entry.name).toBe(normalize('bundles/pages/index.js')) | ||
expect(entry.files[0]).toBe('./pages/index.ts') | ||
}) | ||
|
||
it('Should allow custom extension like .jsx to be turned into .js', () => { | ||
const entry = createEntry('pages/index.jsx', {pageExtensions: ['jsx', 'js'].join('|')}) | ||
expect(entry.name).toBe(normalize('bundles/pages/index.js')) | ||
expect(entry.files[0]).toBe('./pages/index.jsx') | ||
}) | ||
|
||
it('Should turn pages/blog/index.js into pages/blog.js', () => { | ||
const entry = createEntry('pages/blog/index.js') | ||
expect(entry.name).toBe(normalize('bundles/pages/blog.js')) | ||
expect(entry.files[0]).toBe('./pages/blog/index.js') | ||
}) | ||
}) | ||
|
||
describe('getPageEntries', () => { | ||
it('Should return paths', () => { | ||
const pagePaths = ['pages/index.js'] | ||
const pageEntries = getPageEntries(pagePaths) | ||
expect(pageEntries[normalize('bundles/pages/index.js')][0]).toBe('./pages/index.js') | ||
}) | ||
|
||
it('Should include default _error', () => { | ||
const pagePaths = ['pages/index.js'] | ||
const pageEntries = getPageEntries(pagePaths) | ||
expect(pageEntries[normalize('bundles/pages/_error.js')][0]).toMatch(/dist[/\\]pages[/\\]_error\.js/) | ||
}) | ||
|
||
it('Should not include default _error when _error.js is inside the pages directory', () => { | ||
const pagePaths = ['pages/index.js', 'pages/_error.js'] | ||
const pageEntries = getPageEntries(pagePaths) | ||
expect(pageEntries[normalize('bundles/pages/_error.js')][0]).toBe('./pages/_error.js') | ||
}) | ||
|
||
it('Should include default _document when isServer is true', () => { | ||
const pagePaths = ['pages/index.js'] | ||
const pageEntries = getPageEntries(pagePaths, {isServer: true}) | ||
expect(pageEntries[normalize('bundles/pages/_document.js')][0]).toMatch(/dist[/\\]pages[/\\]_document\.js/) | ||
}) | ||
|
||
it('Should not include default _document when _document.js is inside the pages directory', () => { | ||
const pagePaths = ['pages/index.js', 'pages/_document.js'] | ||
const pageEntries = getPageEntries(pagePaths, {isServer: true}) | ||
expect(pageEntries[normalize('bundles/pages/_document.js')][0]).toBe('./pages/_document.js') | ||
}) | ||
}) |