forked from Shopify/hydrogen
-
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.
Support optional segments in
check routes
CLI command (Shopify#774)
* Add tests for missing-routes * Support optional segments in missing-routes * Changeset
- Loading branch information
Showing
3 changed files
with
72 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/cli-hydrogen': patch | ||
--- | ||
|
||
Fix the `check routes` command to match optional segments. |
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,52 @@ | ||
import {describe, it, expect} from 'vitest'; | ||
import {findMissingRoutes} from './missing-routes.js'; | ||
|
||
const createRoute = (path: string) => ({ | ||
routes: { | ||
'route-id': { | ||
file: 'a/file', | ||
id: 'route-id', | ||
path, | ||
}, | ||
}, | ||
}); | ||
|
||
describe('missing-routes', () => { | ||
it('matches routes with dots', async () => { | ||
const requiredRoutes = ['sitemap.xml']; | ||
|
||
expect(findMissingRoutes({routes: {}}, requiredRoutes)).toHaveLength(1); | ||
expect( | ||
findMissingRoutes(createRoute('sitemap.xml'), requiredRoutes), | ||
).toHaveLength(0); | ||
}); | ||
|
||
it('matches routes with different parameter names', async () => { | ||
const requiredRoutes = ['collections/:collectionHandle']; | ||
|
||
expect(findMissingRoutes({routes: {}}, requiredRoutes)).toHaveLength(1); | ||
expect( | ||
findMissingRoutes(createRoute('collections/:param'), requiredRoutes), | ||
).toHaveLength(0); | ||
}); | ||
|
||
it('matches optional segments in different positions', async () => { | ||
const requiredRoutes = ['collections/products']; | ||
const validRoutes = [ | ||
'segment?/collections/products', | ||
':segment?/collections/products', | ||
'collections/segment?/products', | ||
'collections/:segment?/products', | ||
'collections/products/segment?', | ||
'collections/products/:segment?', | ||
]; | ||
|
||
expect(findMissingRoutes({routes: {}}, requiredRoutes)).toHaveLength(1); | ||
|
||
for (const validRoute of validRoutes) { | ||
expect( | ||
findMissingRoutes(createRoute(validRoute), requiredRoutes), | ||
).toHaveLength(0); | ||
} | ||
}); | ||
}); |
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