-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from chaqchase/feat/better-support-improvements
better support and improvements
- Loading branch information
Showing
19 changed files
with
2,958 additions
and
2,729 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", | ||
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "restricted", | ||
"access": "public", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import fs from 'fs/promises'; | ||
import { generateDeclarations, generateLinkFunction } from '../src/codegen'; | ||
import { getRoutesMap } from '../src/utils'; | ||
|
||
jest.mock('fs/promises'); | ||
jest.mock('../src/utils'); | ||
|
||
describe('codegen', () => { | ||
const mockAppDir = '/mock/app'; | ||
const mockDeclarationPath = '/mock/declarations.d.ts'; | ||
const mockUtilsPath = '/mock/utils.ts'; | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('generateDeclarations', () => { | ||
it('should generate declarations correctly', async () => { | ||
const mockRoutesMap = { | ||
'/': { path: '/', params: {}, isDynamic: false }, | ||
'/blog/[slug]': { | ||
path: '/blog/[slug]', | ||
params: { slug: '' }, | ||
isDynamic: true, | ||
}, | ||
}; | ||
|
||
(getRoutesMap as jest.Mock).mockResolvedValue(mockRoutesMap); | ||
|
||
await generateDeclarations(mockAppDir, mockDeclarationPath); | ||
|
||
expect(fs.writeFile).toHaveBeenCalledWith( | ||
mockDeclarationPath, | ||
expect.stringContaining('const routes ='), | ||
); | ||
}); | ||
}); | ||
|
||
describe('generateLinkFunction', () => { | ||
it('should generate link function correctly', async () => { | ||
const mockRoutesMap = { | ||
'/': { path: '/', params: {}, isDynamic: false }, | ||
'/blog/[slug]': { | ||
path: '/blog/[slug]', | ||
params: { slug: '' }, | ||
isDynamic: true, | ||
}, | ||
}; | ||
|
||
(getRoutesMap as jest.Mock).mockResolvedValue(mockRoutesMap); | ||
|
||
await generateLinkFunction(mockAppDir, mockUtilsPath); | ||
|
||
expect(fs.writeFile).toHaveBeenCalledWith( | ||
mockUtilsPath, | ||
expect.stringContaining('const link$ ='), | ||
); | ||
}); | ||
}); | ||
}); |
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,3 @@ | ||
export default function About() { | ||
return <h1>About</h1>; | ||
} |
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,3 @@ | ||
export default function BlogPost({ params }: { params: { slug: string } }) { | ||
return <h1>Blog Post: {params.slug}</h1>; | ||
} |
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,3 @@ | ||
export default function Home() { | ||
return <h1>Home</h1>; | ||
} |
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,3 @@ | ||
export default function Products({ params }: { params: { categories: string[] } }) { | ||
return <h1>Products: {params.categories.join(', ')}</h1>; | ||
} |
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,3 @@ | ||
export default function Settings({ params }: { params: { sections?: string[] } }) { | ||
return <h1>Settings: {params.sections?.join(', ') || 'General'}</h1>; | ||
} |
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,85 @@ | ||
import path from 'path'; | ||
import { | ||
cleanPath, | ||
isValidPath, | ||
isDynamicPath, | ||
isCatchAllRoute, | ||
isOptionalCatchAllRoute, | ||
generateRoutes, | ||
} from '../src/utils'; | ||
|
||
describe('utils', () => { | ||
describe('cleanPath', () => { | ||
it('should clean the path correctly', () => { | ||
const input = '/app/(auth)/login/page.tsx'; | ||
const expected = '/login'; | ||
expect(cleanPath(input, '/app')).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('isValidPath', () => { | ||
it('should return true for valid paths', () => { | ||
expect(isValidPath('validPath')).toBe(true); | ||
}); | ||
|
||
it('should return false for paths starting with underscore', () => { | ||
expect(isValidPath('_invalidPath')).toBe(false); | ||
}); | ||
|
||
it('should return false for paths starting with dot', () => { | ||
expect(isValidPath('.invalidPath')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isDynamicPath', () => { | ||
it('should return true for dynamic paths', () => { | ||
expect(isDynamicPath('[id]')).toBe(true); | ||
}); | ||
|
||
it('should return false for static paths', () => { | ||
expect(isDynamicPath('static')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isCatchAllRoute', () => { | ||
it('should return true for catch-all routes', () => { | ||
expect(isCatchAllRoute('[...slug]')).toBe(true); | ||
}); | ||
|
||
it('should return false for non-catch-all routes', () => { | ||
expect(isCatchAllRoute('[id]')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isOptionalCatchAllRoute', () => { | ||
it('should return true for optional catch-all routes', () => { | ||
expect(isOptionalCatchAllRoute('[[...slug]]')).toBe(true); | ||
}); | ||
|
||
it('should return false for non-optional catch-all routes', () => { | ||
expect(isOptionalCatchAllRoute('[...slug]')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('generateRoutes', () => { | ||
it('should generate routes correctly', async () => { | ||
const mockAppDir = path.join(__dirname, 'mock-app'); | ||
const routes = await generateRoutes(mockAppDir); | ||
|
||
expect(routes).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ path: '/about' }), | ||
expect.objectContaining({ path: '/blog/[slug]', isDynamic: true }), | ||
expect.objectContaining({ | ||
path: '/products/[...categories]', | ||
isCatchAll: true, | ||
}), | ||
expect.objectContaining({ | ||
path: '/settings/[[...sections]]', | ||
isOptionalCatchAll: true, | ||
}), | ||
]), | ||
); | ||
}); | ||
}); | ||
}); |
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,15 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
roots: ['<rootDir>/src', '<rootDir>/__tests__'], | ||
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'], | ||
moduleFileExtensions: ['ts', 'js', 'json', 'node'], | ||
extensionsToTreatAsEsm: ['.ts'], | ||
moduleNameMapper: { | ||
'^(\\.{1,2}/.*)\\.js$': '$1', | ||
}, | ||
transform: { | ||
'^.+\\.tsx?$': ['ts-jest', { useESM: true }], | ||
}, | ||
transformIgnorePatterns: ['node_modules/(?!(chalk)/)'], | ||
}; |
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
Oops, something went wrong.