Skip to content

Commit

Permalink
added helper function for setup
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Dec 9, 2024
1 parent bb4da1d commit 45adee8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
23 changes: 2 additions & 21 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 { TEST_CONTENT } = require('../tests/fixtures/buildPostListData');
const { setupTestDirectories } = require('./helper/buildPostListSetup')
const { buildPostList, slugifyToC } = require('../scripts/build-post-list');

describe('buildPostList', () => {
Expand All @@ -20,27 +20,8 @@ describe('buildPostList', () => {
[join(tempDir, 'about'), '/about'],
];

await fs.ensureDir(join(tempDir, TEST_CONTENT.blog.dir));
await fs.writeFile(
join(tempDir, TEST_CONTENT.blog.dir, TEST_CONTENT.blog.file),
TEST_CONTENT.blog.content,
);

await fs.ensureDir(join(tempDir, TEST_CONTENT.docs.dir));
await fs.writeFile(
join(tempDir, TEST_CONTENT.docs.dir, TEST_CONTENT.docs.file),
TEST_CONTENT.docs.content,
);
await setupTestDirectories(tempDir);

await fs.ensureDir(
join(tempDir, TEST_CONTENT.docs.dir, TEST_CONTENT.docs.subDir),
);

await fs.ensureDir(join(tempDir, TEST_CONTENT.about.dir));
await fs.writeFile(
join(tempDir, TEST_CONTENT.about.dir, TEST_CONTENT.about.file),
TEST_CONTENT.about.content,
);
});

afterEach(async () => {
Expand Down
17 changes: 17 additions & 0 deletions tests/helper/buildPostListSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { TEST_CONTENT } = require("../fixtures/buildPostListData");
const fs = require('fs-extra');
const { join } = require("path")

async function setupTestDirectories(tempDir) {
const dirs = ['blog', 'docs', 'about'];
for (const dir of dirs) {
await fs.ensureDir(join(tempDir, TEST_CONTENT[dir].dir));
await fs.writeFile(
join(tempDir, TEST_CONTENT[dir].dir, TEST_CONTENT[dir].file),
TEST_CONTENT[dir].content
);
}
await fs.ensureDir(join(tempDir, TEST_CONTENT.docs.dir, TEST_CONTENT.docs.subDir));
}

module.exports = { setupTestDirectories };

0 comments on commit 45adee8

Please sign in to comment.