Skip to content

Commit

Permalink
fgegeq
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Oct 18, 2024
1 parent 7e7b82b commit bbce1a4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions tests/build-post-list.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } = require('fs');
const { join, resolve, normalize } = require('path');
const { buildPostList, slugifyToC } = require('../scripts/build-post-list');
const os = require('os');
const lineBreak = require('os').EOL;

describe('buildPostList', () => {
let tempDir;
let writeFilePath;
let postDirectories;
const lineBreak = os.EOL;

beforeEach(() => {
tempDir = resolve(__dirname, 'test-config');
Expand Down Expand Up @@ -43,15 +42,15 @@ describe('buildPostList', () => {
expect(outputExists).toBe(true);

const output = JSON.parse(readFileSync(writeFilePath, 'utf-8'));
console.log(output)
console.log(output);

expect(output).toHaveProperty('docs');
expect(output).toHaveProperty('blog');
expect(output).toHaveProperty('about');
expect(output).toHaveProperty('docsTree');

const blogEntry = output.blog.find(item => item.slug === '/blog/release-notes-2.1.0');
console.log(blogEntry)
console.log(blogEntry);
expect(blogEntry).toBeDefined();
expect(blogEntry.title).toBe('Release Notes 2.1.0');
});
Expand All @@ -63,7 +62,6 @@ describe('buildPostList', () => {
await buildPostList(postDirectories, tempDir, writeFilePath);

const output = JSON.parse(readFileSync(writeFilePath, 'utf-8'));

expect(output.docs.length).toBeGreaterThan(0);
expect(output.docs.find(item => item.title === 'Section 1')).toBeDefined();
});
Expand All @@ -74,7 +72,6 @@ describe('buildPostList', () => {
await buildPostList(postDirectories, tempDir, writeFilePath);

const output = JSON.parse(readFileSync(writeFilePath, 'utf-8'));

const firstReleaseNote = output.blog.find(item => item.slug === '/blog/release-notes-2.1.0');
const secondReleaseNote = output.blog.find(item => item.slug === '/blog/release-notes-2.1.1');

Expand All @@ -85,7 +82,7 @@ describe('buildPostList', () => {
expect(secondReleaseNote.title).toBe('Release Notes 2.1.1');
});

it('handles errors gracefully', async () => {
it('handles errors gracefully for non-existent directories', async () => {
const invalidDir = [normalize(join(tempDir, 'non-existent-dir')), '/invalid'];
await expect(buildPostList([invalidDir], tempDir, writeFilePath)).rejects.toThrow();
});
Expand Down Expand Up @@ -187,6 +184,6 @@ describe('buildPostList', () => {
}

expect(error).toBeDefined();
expect(error.message).toMatch(/Error while building post list/);
expect(error.message).toMatch(/No post directories provided/);
});
});

0 comments on commit bbce1a4

Please sign in to comment.