From 471e9d2eb185d46a34c18e00544890e10a393570 Mon Sep 17 00:00:00 2001 From: ZHallen122 <106571949+ZHallen122@users.noreply.github.com> Date: Sun, 15 Dec 2024 17:14:04 -0500 Subject: [PATCH] Feat fix using windows path, now use normalizePath (#70) ## Summary by CodeRabbit - **Bug Fixes** - Improved cross-platform compatibility by standardizing file path handling in test files. - **New Features** - Updated the instantiation method for `FileGeneratorHandler`, potentially altering its operational behavior. --------- Co-authored-by: Jackson Chen <90215880+Sma1lboy@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../__tests__/test-file-create.spec.ts | 34 +++++++++++++------ .../__tests__/testVirtualDir.spec.ts | 2 +- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/backend/src/build-system/__tests__/test-file-create.spec.ts b/backend/src/build-system/__tests__/test-file-create.spec.ts index f2ca5cd..3058a30 100644 --- a/backend/src/build-system/__tests__/test-file-create.spec.ts +++ b/backend/src/build-system/__tests__/test-file-create.spec.ts @@ -1,36 +1,50 @@ import * as fs from 'fs-extra'; import * as path from 'path'; import { FileGeneratorHandler } from '../handlers/file-generate'; // Update with actual file path to the handler +import * as normalizePath from 'normalize-path'; describe('FileGeneratorHandler', () => { - const projectSrcPath = 'src\\build-system\\__tests__\\test-project\\'; - // Read JSON data from file - const mdFilePath = path.resolve('src\\build-system\\__tests__\\file-arch.md'); - const structMdFilePath = path.resolve( - 'src\\build-system\\__tests__\\file-structure-document.md', + const projectSrcPath = normalizePath( + path.join('src', 'build-system', '__tests__', 'test-project'), + ); + + const mdFilePath = normalizePath( + path.join('src', 'build-system', '__tests__', 'file-arch.md'), + ); + + const structMdFilePath = normalizePath( + path.join('src', 'build-system', '__tests__', 'file-structure-document.md'), ); beforeEach(async () => { // Ensure the project directory is clean - await fs.remove('src\\build-system\\__tests__\\test-project\\src\\'); + await fs.remove( + normalizePath( + path.join('src', 'build-system', '__tests__', 'test-project', 'src'), + ), + ); }); afterEach(async () => { // Clean up the generated test files - await fs.remove('src\\build-system\\__tests__\\test-project\\src\\'); + await fs.remove( + normalizePath( + path.join('src', 'build-system', '__tests__', 'test-project', 'src'), + ), + ); }); it('should generate files based on file-arch.md', async () => { const archMarkdownContent = fs.readFileSync( - path.resolve(mdFilePath), + normalizePath(path.resolve(mdFilePath)), 'utf8', ); const structMarkdownContent = fs.readFileSync( - path.resolve(structMdFilePath), + normalizePath(path.resolve(structMdFilePath)), 'utf8', ); - const handler = new FileGeneratorHandler(structMarkdownContent); + const handler = new FileGeneratorHandler(); // Run the file generator with the JSON data const result = await handler.generateFiles( diff --git a/backend/src/build-system/__tests__/testVirtualDir.spec.ts b/backend/src/build-system/__tests__/testVirtualDir.spec.ts index 0de61db..cfcc2ca 100644 --- a/backend/src/build-system/__tests__/testVirtualDir.spec.ts +++ b/backend/src/build-system/__tests__/testVirtualDir.spec.ts @@ -5,7 +5,7 @@ import * as normalizePath from 'normalize-path'; describe('VirtualDirectory', () => { const structMdFilePath = normalizePath( - 'src\\build-system\\__tests__\\file-structure-document.md', + path.join('src', 'build-system', '__tests__', 'file-structure-document.md'), ); describe('VirtualDirectory', () => {