Skip to content

Commit

Permalink
apply coderabbit suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Dec 10, 2024
1 parent 98231ea commit 4893712
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
17 changes: 11 additions & 6 deletions tests/build-post-list.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs-extra');
const { resolve, join } = require('path');
const { setupTestDirectories } = require('./helper/buildPostListSetup')
const { setupTestDirectories, generateTempDirPath } = require('./helper/buildPostListSetup')
const { buildPostList, slugifyToC } = require('../scripts/build-post-list');

describe('buildPostList', () => {
Expand All @@ -9,10 +9,7 @@ describe('buildPostList', () => {
let postDirectories;

beforeEach(async () => {
tempDir = resolve(
__dirname,
`test-config-${Date.now()}-${Math.random().toString(36).slice(2)}`,
);
tempDir = generateTempDirPath(__dirname);
writeFilePath = resolve(tempDir, 'posts.json');
postDirectories = [
[join(tempDir, 'blog'), '/blog'],
Expand All @@ -28,12 +25,15 @@ describe('buildPostList', () => {
await fs.remove(tempDir);
});

it('builds a post list and writes the result to a file', async () => {
it('writes the result to a file', async () => {
await buildPostList(postDirectories, tempDir, writeFilePath);

const outputExists = await fs.pathExists(writeFilePath);
expect(outputExists).toBe(true);
});

it('correctly structures docs entries', async () => {
await buildPostList(postDirectories, tempDir, writeFilePath);
const output = JSON.parse(await fs.readFile(writeFilePath, 'utf-8'));

expect(output.docs).toEqual(
Expand All @@ -54,6 +54,11 @@ describe('buildPostList', () => {
}),
]),
);
});

it('correctly structures blog entries', async () => {
await buildPostList(postDirectories, tempDir, writeFilePath);
const output = JSON.parse(await fs.readFile(writeFilePath, 'utf-8'));

expect(output.blog).toEqual(
expect.arrayContaining([
Expand Down
11 changes: 9 additions & 2 deletions tests/helper/buildPostListSetup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { TEST_CONTENT } = require("../fixtures/buildPostListData");
const fs = require('fs-extra');
const { join } = require("path")
const { join, resolve } = require("path")

async function setupTestDirectories(tempDir) {
const dirs = ['blog', 'docs', 'about'];
Expand All @@ -14,4 +14,11 @@ async function setupTestDirectories(tempDir) {
await fs.ensureDir(join(tempDir, TEST_CONTENT.docs.dir, TEST_CONTENT.docs.subDir));
}

module.exports = { setupTestDirectories };
function generateTempDirPath(baseDir) {
return resolve(
baseDir,
`test-config-${Date.now()}-${Math.random().toString(36).slice(2)}`
);
}

module.exports = { setupTestDirectories, generateTempDirPath };

0 comments on commit 4893712

Please sign in to comment.