diff --git a/jest.config.js b/jest.config.js
index 39211f19dc49..4a32c5b1cc04 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -4,7 +4,7 @@ module.exports = {
coverageReporters: ['text', 'lcov', 'json-summary'],
coverageDirectory: 'coverage',
collectCoverageFrom: ['scripts/**/*.js'],
- coveragePathIgnorePatterns: ['scripts/compose.js'],
+ coveragePathIgnorePatterns: ['scripts/compose.js', 'scripts/tools/categorylist.js', 'scripts/tools/tags-color.js'],
// To disallow netlify edge function tests from running
testMatch: ['**/tests/**/*.test.*', '!**/netlify/**/*.test.*'],
};
\ No newline at end of file
diff --git a/scripts/build-pages.js b/scripts/build-pages.js
index 48b3553e96b2..de46315bc326 100644
--- a/scripts/build-pages.js
+++ b/scripts/build-pages.js
@@ -7,10 +7,14 @@ const TARGET_DIR = 'pages';
const capitalizeTags = ['table', 'tr', 'td', 'th', 'thead', 'tbody'];
// Check if target directory doesn't exist then create it
-if (!fs.existsSync(TARGET_DIR)) {
- fs.mkdirSync(TARGET_DIR, { recursive: true });
+function ensureDirectoryExists(directory) {
+ if (!fs.existsSync(directory)) {
+ fs.mkdirSync(directory, { recursive: true });
+ }
}
+ensureDirectoryExists(TARGET_DIR);
+
function capitalizeJsxTags(content) {
return content.replace(/<\/?(\w+)/g, function (match, letter) {
if (capitalizeTags.includes(letter.toLowerCase())) {
@@ -57,4 +61,4 @@ function copyAndRenameFiles(srcDir, targetDir) {
copyAndRenameFiles(SRC_DIR, TARGET_DIR);
-module.exports = {copyAndRenameFiles,capitalizeJsxTags}
\ No newline at end of file
+module.exports = { copyAndRenameFiles,capitalizeJsxTags, ensureDirectoryExists }
\ No newline at end of file
diff --git a/tests/build-pages.test.js b/tests/build-pages.test.js
index 65947e9f629c..f811b1480158 100644
--- a/tests/build-pages.test.js
+++ b/tests/build-pages.test.js
@@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
-const { capitalizeJsxTags, copyAndRenameFiles } = require('../scripts/build-pages');
+const { capitalizeJsxTags, copyAndRenameFiles, ensureDirectoryExists } = require('../scripts/build-pages');
describe('capitalizeJsxTags', () => {
test('should capitalize JSX tags', () => {
@@ -45,4 +45,13 @@ describe('copyAndRenameFiles', () => {
expect(targetFile).toBe('
');
expect(nestedTargetFile).toBe('');
});
+
+ test('should create a directory if it does not exist', () => {
+ const NEW_TEST_DIR = 'testDir';
+
+ expect(fs.existsSync(NEW_TEST_DIR)).toBe(false);
+ ensureDirectoryExists(NEW_TEST_DIR);
+ expect(fs.existsSync(NEW_TEST_DIR)).toBe(true);
+ });
+
});
\ No newline at end of file
diff --git a/tests/dashboard/build-dashboard.test.js b/tests/dashboard/build-dashboard.test.js
index e7861c36dc65..b8f2f0a96ab4 100644
--- a/tests/dashboard/build-dashboard.test.js
+++ b/tests/dashboard/build-dashboard.test.js
@@ -195,4 +195,9 @@ describe('GitHub Discussions Processing', () => {
localConsoleErrorSpy.mockRestore();
});
+ it('should handle write failures gracefully', async () => {
+
+ await expect(writeToFile()).rejects.toThrow();
+ });
+
});
diff --git a/tests/index.test.js b/tests/index.test.js
index 37b124547efd..f1d3850a37c5 100644
--- a/tests/index.test.js
+++ b/tests/index.test.js
@@ -4,6 +4,7 @@ const buildCaseStudiesList = require('../scripts/casestudies');
const buildAdoptersList = require('../scripts/adopters');
const buildFinanceInfoList = require('../scripts/finance');
const start = require('../scripts/index');
+const fs = require('fs');
jest.mock('../scripts/build-rss');
jest.mock('../scripts/build-post-list');
@@ -32,4 +33,14 @@ describe('start function', () => {
expect(buildAdoptersList).toHaveBeenCalled();
expect(buildFinanceInfoList).toHaveBeenCalled();
});
+
+ test('should throw an error if no finance data is found', async () => {
+ jest.spyOn(fs, 'readdirSync').mockReturnValue([]);
+
+ await expect(start()).rejects.toThrow('No finance data found in the finance directory.');
+
+ expect(buildFinanceInfoList).not.toHaveBeenCalled();
+
+ fs.readdirSync.mockRestore();
+ });
});