fix(fs): Fix inconsistent glob matching in listFileTree and update test imports and dependency versions for enhanced stability.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as path from 'path';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartfile from '../ts/index.js'; // adjust the import path as needed
|
||||
|
||||
// Test assets path
|
||||
|
39
test/test.ts
39
test/test.ts
@@ -1,7 +1,7 @@
|
||||
import * as smartfile from '../ts/index.js';
|
||||
import * as path from 'path';
|
||||
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
// ---------------------------
|
||||
// smartfile.fs
|
||||
@@ -59,6 +59,43 @@ tap.test('.fs.listFileTree() -> should get a file tree', async () => {
|
||||
expect(folderArrayArg).not.toContain('mytest.json');
|
||||
});
|
||||
|
||||
tap.test('.fs.listFileTree() -> should find both root and nested .ts files with **/*.ts pattern', async () => {
|
||||
const tsFiles = await smartfile.fs.listFileTree(
|
||||
process.cwd(),
|
||||
'**/*.ts'
|
||||
);
|
||||
// Should find both root-level and nested TypeScript files
|
||||
expect(tsFiles).toContain('ts/index.ts');
|
||||
expect(tsFiles).toContain('ts/classes.smartfile.ts');
|
||||
expect(tsFiles).toContain('test/test.ts');
|
||||
// Should find files in multiple levels of nesting
|
||||
expect(tsFiles.filter(f => f.endsWith('.ts')).length).toBeGreaterThan(5);
|
||||
// Verify it finds files at all levels (root 'ts/' and nested 'test/')
|
||||
const hasRootLevelTs = tsFiles.some(f => f.startsWith('ts/') && f.endsWith('.ts'));
|
||||
const hasNestedTs = tsFiles.some(f => f.startsWith('test/') && f.endsWith('.ts'));
|
||||
expect(hasRootLevelTs).toBeTrue();
|
||||
expect(hasNestedTs).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('.fs.listFileTree() -> should handle edge cases with **/ patterns consistently', async () => {
|
||||
// Test that our fix ensures no duplicate files in results
|
||||
const jsonFiles = await smartfile.fs.listFileTree(
|
||||
path.resolve('./test/testassets/'),
|
||||
'**/*.json'
|
||||
);
|
||||
const uniqueFiles = [...new Set(jsonFiles)];
|
||||
expect(jsonFiles.length).toEqual(uniqueFiles.length);
|
||||
|
||||
// Test that it finds root level files with **/ patterns
|
||||
const txtFiles = await smartfile.fs.listFileTree(
|
||||
path.resolve('./test/testassets/'),
|
||||
'**/*.txt'
|
||||
);
|
||||
// Should include both direct files and nested files
|
||||
expect(txtFiles).toContain('mytest.txt');
|
||||
expect(txtFiles).toContain('testfolder/testfile1.txt');
|
||||
});
|
||||
|
||||
tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async () => {
|
||||
const fileArrayArg = await smartfile.fs.fileTreeToObject(
|
||||
path.resolve('./test/testassets/'),
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
import * as smartfile from '../ts/index.js';
|
||||
|
||||
|
Reference in New Issue
Block a user