Skip to content

Commit

Permalink
Feat fix using windows path, now use normalizePath (#70)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Jackson Chen <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 15, 2024
1 parent ea71ef2 commit 471e9d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
34 changes: 24 additions & 10 deletions backend/src/build-system/__tests__/test-file-create.spec.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion backend/src/build-system/__tests__/testVirtualDir.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 471e9d2

Please sign in to comment.