Skip to content

Commit 775f590

Browse files
committed
test(exportfunctions): add tests to catch nested folder bug regression & more
Deep nested folders were not being detected properly due to a bug with the replace function that only replaces the first match of a string. A test was added to catch this bug.
1 parent a4b06d3 commit 775f590

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

__tests__/exportFunctions.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ describe('exportFunctions() function exporter test suite', () => {
1919
'./empty-folder/',
2020
'folder/new.func.ts',
2121
'folder/not-a-func.ts',
22+
'folder/nestedFolder/sample-func.func.ts',
2223
];
2324
const { name: tempFuncDir } = tmp.dirSync();
2425
const randOutput = Math.floor(Math.random() * 10);
2526
const filePathToPropertyPath = (moduleFilePath: string) => {
2627
const funcName = bff.funcNameFromRelPathDefault(moduleFilePath);
27-
return funcName.replace('-', '.');
28+
return funcName.split('-').join('.');
2829
};
2930

3031
beforeEach(() => {
@@ -62,6 +63,8 @@ describe('exportFunctions() function exporter test suite', () => {
6263

6364
it('should properly nest submodules found in directories', () => {
6465
expect(exportTestFactory()).toHaveProperty(filePathToPropertyPath(testFiles[4]), randOutput);
66+
expect(exportTestFactory()).not.toHaveProperty(filePathToPropertyPath(testFiles[3]), randOutput);
67+
expect(exportTestFactory()).toHaveProperty(filePathToPropertyPath(testFiles[6]), randOutput);
6568
});
6669

6770
it('should correctly apply camelCase to kebab-case named files', () => {
@@ -109,9 +112,8 @@ describe('exportFunctions() function exporter test suite', () => {
109112
});
110113

111114
it('will provide a paths mode for buildtools', () => {
112-
expect(exportTestFactory({ exportPathMode: true })).toHaveProperty(
113-
filePathToPropertyPath(testFiles[4]),
114-
testFiles[4]
115-
);
115+
const output = exportTestFactory({ exportPathMode: true });
116+
console.log(output);
117+
expect(output).toHaveProperty(filePathToPropertyPath(testFiles[4]), testFiles[4]);
116118
});
117119
});

0 commit comments

Comments
 (0)