diff --git a/scripts/build-pages.js b/scripts/build-pages.js
index e629389f53e5..de46315bc326 100644
--- a/scripts/build-pages.js
+++ b/scripts/build-pages.js
@@ -7,11 +7,14 @@ const TARGET_DIR = 'pages';
const capitalizeTags = ['table', 'tr', 'td', 'th', 'thead', 'tbody'];
// Check if target directory doesn't exist then create it
-/* istanbul ignore next */
-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())) {
@@ -58,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..ff23c1e23de8 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 TEST_DIR = 'testDir';
+
+ expect(fs.existsSync(TEST_DIR)).toBe(false);
+ ensureDirectoryExists(TEST_DIR);
+ expect(fs.existsSync(TEST_DIR)).toBe(true);
+ });
+
});
\ No newline at end of file