forked from roadmapsh/deprecated-version
-
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.
- Loading branch information
Showing
44 changed files
with
2,153 additions
and
231 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,84 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const guides = require('../data/guides'); | ||
const roadmaps = require('../data/roadmaps'); | ||
|
||
const { | ||
getPageRoutes, | ||
getGuideRoutes, | ||
getRoadmapRoutes | ||
} = require("../path-map"); | ||
|
||
describe("Build scripts tests", () => { | ||
test('it should generate valid pathmap for pages', () => { | ||
const pageRoutes = getPageRoutes(); | ||
|
||
expect(pageRoutes).toEqual({ | ||
'/': { page: '/index' }, | ||
'/about': { page: '/about' }, | ||
'/privacy': { page: '/privacy' }, | ||
'/terms': { page: '/terms' }, | ||
'/guides': { page: '/guides/index' }, | ||
'/roadmaps': { page: '/roadmaps' }, | ||
}); | ||
}); | ||
|
||
test('it should generate valid guides pathmap', () => { | ||
const expectedGuideRoutes = guides.reduce((acc, guide) => { | ||
const [,, slug] = guide.url.split('/'); | ||
return { | ||
...acc, | ||
[guide.url]: { | ||
page: '/guides/[guide]', | ||
query: slug, | ||
} | ||
}; | ||
}, {}); | ||
|
||
// Valid path map is generated | ||
expect(expectedGuideRoutes).toEqual(getGuideRoutes()); | ||
|
||
const pageFilePath = path.join(__dirname, '../pages/guides/[guide].js'); | ||
const foundFilePath = fs.existsSync(pageFilePath) ? pageFilePath : ''; | ||
|
||
// Given page component exists | ||
expect(foundFilePath).toEqual(pageFilePath); | ||
}); | ||
|
||
test('it should have markdown file for each guide', () => { | ||
guides.forEach(guide => { | ||
const [,, slug] = guide.url.split('/'); | ||
|
||
const expectedFile = path.join(__dirname, `../data/guides/${slug}.md`); | ||
const foundFile = fs.existsSync(expectedFile) ? expectedFile : ''; | ||
|
||
expect(foundFile).toEqual(expectedFile); | ||
}) | ||
}); | ||
|
||
test('it should generate valid roadmap routes', () => { | ||
const expectedPathMap = roadmaps.reduce((roadmapAcc, roadmap) => { | ||
// Routes for each of the versions of this roadmap | ||
const versionRoutes = roadmap.versions.reduce((versionAcc, version) => ({ | ||
...versionAcc, | ||
[`${roadmap.url}/${version}`]: { | ||
page: '/[roadmap]/[version]', | ||
query: `${roadmap.url.split('/')[1]}/${version}`, | ||
} | ||
}), {}); | ||
|
||
// Route for the route roadmap itself | ||
return { | ||
...roadmapAcc, | ||
[roadmap.url]: { | ||
page: '/[roadmap]/index', | ||
query: roadmap.url.split('/')[1] | ||
}, | ||
// Expected roadmap for versions | ||
...versionRoutes | ||
}; | ||
}, {}); | ||
|
||
expect(getRoadmapRoutes()).toEqual(expectedPathMap); | ||
}) | ||
}); |
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 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
Oops, something went wrong.