-
-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests for Index and build pages script (#3044)
Co-authored-by: Ansh Goyal <[email protected]>
- Loading branch information
1 parent
fa6e4c9
commit cf5f24a
Showing
4 changed files
with
88 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -17,4 +17,6 @@ async function start() { | |
await buildFinanceInfoList(); | ||
} | ||
|
||
start(); | ||
module.exports = start; | ||
|
||
start(); |
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,48 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { capitalizeJsxTags, copyAndRenameFiles } = require('../scripts/build-pages'); | ||
|
||
describe('capitalizeJsxTags', () => { | ||
test('should capitalize JSX tags', () => { | ||
const input = '<table><tr><td>Hello</td></tr></table>'; | ||
const output = '<Table><Tr><Td>Hello</Td></Tr></Table>'; | ||
expect(capitalizeJsxTags(input)).toBe(output); | ||
}); | ||
|
||
test('should not capitalize non-JSX tags', () => { | ||
const input = '<div>Hello</div>'; | ||
const output = '<div>Hello</div>'; | ||
expect(capitalizeJsxTags(input)).toBe(output); | ||
}); | ||
}); | ||
|
||
describe('copyAndRenameFiles', () => { | ||
const TEST_DIR = 'test'; | ||
const SRC_DIR = path.join(TEST_DIR, 'src'); | ||
const TARGET_DIR = path.join(TEST_DIR, 'target'); | ||
|
||
beforeAll(() => { | ||
fs.mkdirSync(TEST_DIR, { recursive: true }); | ||
fs.mkdirSync(SRC_DIR, { recursive: true }); | ||
fs.mkdirSync(TARGET_DIR, { recursive: true }); | ||
|
||
const fileContent = '<table><tr><td>Hello</td></tr></table>'; | ||
fs.writeFileSync(path.join(SRC_DIR, 'test.md'), fileContent, 'utf8'); | ||
fs.mkdirSync(path.join(SRC_DIR, 'nested'), { recursive: true }); | ||
fs.writeFileSync(path.join(SRC_DIR, 'nested', 'nested.md'), fileContent, 'utf8'); | ||
}); | ||
|
||
afterAll(() => { | ||
fs.rmSync(TEST_DIR, { recursive: true, force: true }); | ||
}); | ||
|
||
test('should copy and rename files correctly', () => { | ||
copyAndRenameFiles(SRC_DIR, TARGET_DIR); | ||
|
||
const targetFile = fs.readFileSync(path.join(TARGET_DIR, 'test.mdx'), 'utf8'); | ||
const nestedTargetFile = fs.readFileSync(path.join(TARGET_DIR, 'nested', 'nested.mdx'), 'utf8'); | ||
|
||
expect(targetFile).toBe('<Table><Tr><Td>Hello</Td></Tr></Table>'); | ||
expect(nestedTargetFile).toBe('<Table><Tr><Td>Hello</Td></Tr></Table>'); | ||
}); | ||
}); |
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,35 @@ | ||
const rssFeed = require('../scripts/build-rss'); | ||
const buildPostList = require('../scripts/build-post-list'); | ||
const buildCaseStudiesList = require('../scripts/casestudies'); | ||
const buildAdoptersList = require('../scripts/adopters'); | ||
const buildFinanceInfoList = require('../scripts/finance'); | ||
const start = require('../scripts/index'); | ||
|
||
jest.mock('../scripts/build-rss'); | ||
jest.mock('../scripts/build-post-list'); | ||
jest.mock('../scripts/casestudies'); | ||
jest.mock('../scripts/adopters'); | ||
jest.mock('../scripts/finance'); | ||
|
||
describe('start function', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('should call all functions in the correct order', async () => { | ||
await start(); | ||
|
||
expect(buildPostList).toHaveBeenCalled(); | ||
|
||
expect(rssFeed).toHaveBeenCalledWith( | ||
'blog', | ||
'AsyncAPI Initiative Blog RSS Feed', | ||
'AsyncAPI Initiative Blog', | ||
'rss.xml' | ||
); | ||
|
||
expect(buildCaseStudiesList).toHaveBeenCalled(); | ||
expect(buildAdoptersList).toHaveBeenCalled(); | ||
expect(buildFinanceInfoList).toHaveBeenCalled(); | ||
}); | ||
}); |