-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure
ReadingTimePlugin
runs on MDX pages only
- Loading branch information
Showing
2 changed files
with
129 additions
and
14 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
100 changes: 100 additions & 0 deletions
100
packages/plugins/src/__tests__/ReadingTimePlugin.test.ts
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,100 @@ | ||
import type { Page } from '@jpmorganchase/mosaic-types'; | ||
import ReadingTimePlugin, { type ReadingTimePluginPage } from '../ReadingTimePlugin'; | ||
|
||
let updatedPages: ReadingTimePluginPage[] = []; | ||
const $afterSource = ReadingTimePlugin.$afterSource; | ||
|
||
describe('GIVEN the ReadingTimePlugin', () => { | ||
test('THEN it should use the `$afterSource` lifecycle event', () => { | ||
expect(ReadingTimePlugin).toHaveProperty('$afterSource'); | ||
}); | ||
|
||
describe('AND WHEN pages have the `.mdx` extension', () => { | ||
const ignorePages = ['shared-config.json', 'sitemap.xml', 'sidebar.json']; | ||
const pageExtensions = ['.mdx', '.json', '.md']; | ||
beforeEach(async () => { | ||
updatedPages = | ||
(await $afterSource?.( | ||
[ | ||
{ | ||
fullPath: '/FolderA/index.mdx', | ||
route: 'route/folderA/index.mdx', | ||
title: 'Folder A Index' | ||
}, | ||
{ | ||
fullPath: '/FolderA/pageA.json', | ||
route: 'route/folderA/pageA.json', | ||
title: 'Folder A Page A' | ||
} | ||
], | ||
{ ignorePages, pageExtensions }, | ||
{} | ||
)) || []; | ||
}); | ||
|
||
test('THEN the reading time is calculated', () => { | ||
expect(updatedPages[0].readingTime).toBeDefined(); | ||
expect(updatedPages[1].readingTime).not.toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('AND WHEN `.mdx` is not a configured page extension', () => { | ||
const ignorePages = ['shared-config.json', 'sitemap.xml', 'sidebar.json']; | ||
const pageExtensions = ['.json']; | ||
beforeEach(async () => { | ||
updatedPages = | ||
// @ts-ignore | ||
(await $afterSource?.( | ||
[ | ||
{ | ||
fullPath: '/FolderA/index.mdx', | ||
route: 'route/folderA/index.mdx', | ||
title: 'Folder A Index' | ||
}, | ||
{ | ||
fullPath: '/FolderA/pageA.json', | ||
route: 'route/folderA/pageA.json', | ||
title: 'Folder A Page A' | ||
} | ||
], | ||
{ ignorePages, pageExtensions }, | ||
{} | ||
)) || []; | ||
}); | ||
|
||
test('THEN no page has the reading time metadata', () => { | ||
expect(updatedPages[0].readingTime).not.toBeDefined(); | ||
expect(updatedPages[1].readingTime).not.toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('AND WHEN a page itself is ignored', () => { | ||
const pageExtensions = ['.mdx']; | ||
const ignorePages = ['index.mdx']; | ||
beforeEach(async () => { | ||
updatedPages = | ||
(await $afterSource?.( | ||
[ | ||
{ | ||
fullPath: '/FolderA/index.mdx', | ||
route: 'route/folderA/index.mdx', | ||
title: 'Folder A Index' | ||
}, | ||
|
||
{ | ||
fullPath: '/FolderA/pageA.json', | ||
route: 'route/folderA/pageA.json', | ||
title: 'Folder A Page A' | ||
} | ||
], | ||
{ ignorePages, pageExtensions }, | ||
{} | ||
)) || []; | ||
}); | ||
|
||
test('THEN no page has the reading time metadata', () => { | ||
expect(updatedPages[0].readingTime).not.toBeDefined(); | ||
expect(updatedPages[1].readingTime).not.toBeDefined(); | ||
}); | ||
}); | ||
}); |
9cbd4ff
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.
Successfully deployed to the following URLs:
mosaic – ./
mosaic-git-main-mosaic-dev-team.vercel.app
mosaic-mosaic-dev-team.vercel.app