Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Dec 25, 2024
1 parent 0469f4f commit f5023ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
25 changes: 16 additions & 9 deletions scripts/build-post-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const result = {
const releaseNotes = []

const addItem = (details) => {
if (!details || typeof details.slug !== 'string') {
throw new Error('Invalid details object provided to addItem');
}
const sectionMap = {
'/docs': 'docs',
'/blog': 'blog',
Expand Down Expand Up @@ -71,6 +74,17 @@ async function buildPostList(postDirectories, basePath, writeFilePath) {
}
}

function handleSpecificationVersion(details, fileBaseName) {
if (fileBaseName.includes('next-spec') || fileBaseName.includes('next-major-spec')) {
details.isPrerelease = true;
details.title += " (Pre-release)";
}
if (fileBaseName.includes('explorer')) {
details.title += " - Explorer";
}
return details;
}

async function walkDirectories(
directories,
resultObj,
Expand Down Expand Up @@ -142,14 +156,7 @@ async function walkDirectories(
details.releaseNoteLink = `/blog/release-notes-${details.title}`
}

if (fileBaseName.includes('next-spec') || fileBaseName.includes('next-major-spec')) {
details.isPrerelease = true
// this need to be separate because the `-` in "Pre-release" will get removed by `capitalize()` function
details.title += " (Pre-release)"
}
if (fileBaseName.includes('explorer')) {
details.title += " - Explorer"
}
details = handleSpecificationVersion(details, fileBaseName);
}

// To create a list of available ReleaseNotes list, which will be used to add details.releaseNoteLink attribute.
Expand Down Expand Up @@ -199,4 +206,4 @@ function capitalize(text) {
.join(' ');
}

module.exports = { slugifyToC, buildPostList }
module.exports = { slugifyToC, buildPostList, addItem }
9 changes: 8 additions & 1 deletion tests/build-post-list.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs-extra');
const { resolve, join } = require('path');
const { setupTestDirectories, generateTempDirPath } = require('./helper/buildPostListSetup')
const { buildPostList, slugifyToC } = require('../scripts/build-post-list');
const { buildPostList, slugifyToC, addItem } = require('../scripts/build-post-list');

describe('buildPostList', () => {
let tempDir;
Expand Down Expand Up @@ -226,6 +226,13 @@ describe('buildPostList', () => {
);
});

it('throws an error when details object is invalid', () => {
expect(() => addItem(null)).toThrow('Invalid details object provided to addItem');
expect(() => addItem({})).toThrow('Invalid details object provided to addItem');
expect(() => addItem({ slug: 123 })).toThrow('Invalid details object provided to addItem');
expect(() => addItem(undefined)).toThrow('Invalid details object provided to addItem');
});

describe('slugifyToC', () => {
it('handles heading ids like {# myHeadingId}', () => {
const input = '## My Heading {#custom-id}';
Expand Down

0 comments on commit f5023ed

Please sign in to comment.