-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support App Router & Pages Router #22
Closed
Closed
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1ab0604
(Incomplete) Add support for multiple pages directories
alvesvin c790241
Set todo old app dir test case
alvesvin c5c7c49
support for multiple pages dirs
alvesvin ba96ccd
updated templateAppDir snapshot
alvesvin 98c839c
fixed pagesInDir tests
alvesvin 1d48a58
wip: loader tests
alvesvin 44048e0
prefering props.params.lang over search params when using app router
alvesvin 0aa1998
updated snapshots
alvesvin 5d17fab
added determineResourceType to get the type of the file the loader is…
alvesvin 57d1b78
removed console.log and extra line
alvesvin ff5e898
removed unused import
alvesvin 9320544
adding helpers for layout, error & loading
alvesvin babe896
fixed getResourceType types
alvesvin 4cff474
tweaked templates for layout, loading & error pages
alvesvin e9fa3af
basic loader tests
alvesvin 042b19d
add translation to layout
alvesvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,46 +1,65 @@ | ||
import { possiblePagesDirs } from '../src/utils' | ||
import nextTranslate from '../src/index' | ||
import path from 'path' | ||
import fs from 'fs' | ||
|
||
jest.spyOn(fs, 'existsSync') | ||
jest.spyOn(fs, 'readdirSync') | ||
|
||
jest.mock( | ||
'../i18n', | ||
() => ({ | ||
locales: ['en'], | ||
defaultLocale: 'en', | ||
const pagesInDirTests = [ | ||
{ | ||
name: 'pagesInDir should become array in loader pagesPaths config', | ||
pagesInDir: 'src/app', | ||
pages: { | ||
'*': ['common'], | ||
}, | ||
}), | ||
{ virtual: true } | ||
) | ||
pagesPaths: expect.arrayContaining([expect.stringMatching(/src\/app\/$/)]), | ||
}, | ||
{ | ||
name: 'pagesPaths should be defaulted to possible pages paths if pagesInDir is undefined', | ||
pagesInDir: undefined, | ||
pagesPaths: possiblePagesDirs.map((possiblePagesDir) => path.resolve(possiblePagesDir) + '/'), | ||
}, | ||
] | ||
|
||
describe('nextTranslate', () => { | ||
describe('nextTranslate -> pagesInDir', () => { | ||
test('uses app dir loader if pagesInDir points to app dir', () => { | ||
fs.readdirSync.mockImplementationOnce(() => []) | ||
fs.existsSync.mockImplementationOnce(() => true) | ||
beforeEach(() => { | ||
jest.resetModules() | ||
}) | ||
|
||
pagesInDirTests.forEach(({ name, pagesInDir, pagesPaths }) => { | ||
test(name, () => { | ||
fs.readdirSync.mockImplementation(() => []) | ||
fs.existsSync.mockImplementation(() => true) | ||
|
||
jest.doMock( | ||
'../i18n', | ||
() => ({ | ||
locales: ['en'], | ||
defaultLocale: 'en', | ||
pagesInDir, | ||
pages: { | ||
'*': ['common'], | ||
}, | ||
}), | ||
{ virtual: true } | ||
) | ||
|
||
const config = nextTranslate({}) | ||
const config = nextTranslate({}) | ||
|
||
expect(config.webpack({})).toEqual( | ||
expect.objectContaining({ | ||
module: { | ||
rules: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
use: expect.objectContaining({ | ||
loader: 'next-translate-plugin/loader', | ||
options: expect.objectContaining({ | ||
isAppDirNext13: true, | ||
expect(config.webpack({})).toEqual( | ||
expect.objectContaining({ | ||
module: { | ||
rules: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
use: expect.objectContaining({ | ||
loader: 'next-translate-plugin/loader', | ||
options: expect.objectContaining({ pagesPaths }), | ||
}), | ||
}), | ||
}), | ||
]), | ||
}, | ||
}) | ||
) | ||
]), | ||
}, | ||
}) | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |
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,10 @@ | ||
import webpack from 'webpack' | ||
|
||
describe('nextTranslate', () => { | ||
describe('nextTranslate -> loader', () => { | ||
test.todo('loader should use server page helpers') | ||
test.todo('loader should use client page helpers') | ||
test.todo('loader should use client component helpers') | ||
test.todo('loader should use legacy page helpers') | ||
}) | ||
}) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️