Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'),
),
);
Comment on lines +21 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Deduplicate cleanup path and reuse projectSrcPath

The cleanup path is duplicated in both hooks and doesn't reuse the previously defined projectSrcPath. Consider refactoring to reduce duplication and maintain consistency.

+  const cleanupPath = normalizePath(path.join(projectSrcPath, 'src'));

   beforeEach(async () => {
-    await fs.remove(
-      normalizePath(
-        path.join('src', 'build-system', '__tests__', 'test-project', 'src'),
-      ),
-    );
+    await fs.remove(cleanupPath);
   });

   afterEach(async () => {
-    await fs.remove(
-      normalizePath(
-        path.join('src', 'build-system', '__tests__', 'test-project', 'src'),
-      ),
-    );
+    await fs.remove(cleanupPath);
   });

Committable suggestion skipped: line range outside the PR's diff.

});

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