From 45adee8401c45d82d162809cf58f88c38d1302b6 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 9 Dec 2024 12:05:34 +0530 Subject: [PATCH] added helper function for setup --- tests/build-post-list.test.js | 23 ++--------------------- tests/helper/buildPostListSetup.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 21 deletions(-) create mode 100644 tests/helper/buildPostListSetup.js diff --git a/tests/build-post-list.test.js b/tests/build-post-list.test.js index 0bfd6ab3aa5f..bc9439a431fa 100644 --- a/tests/build-post-list.test.js +++ b/tests/build-post-list.test.js @@ -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', () => { @@ -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 () => { diff --git a/tests/helper/buildPostListSetup.js b/tests/helper/buildPostListSetup.js new file mode 100644 index 000000000000..7e793a2e7b9e --- /dev/null +++ b/tests/helper/buildPostListSetup.js @@ -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 }; \ No newline at end of file