Skip to content

Commit

Permalink
Switch to fast-glob
Browse files Browse the repository at this point in the history
  • Loading branch information
henryruhs committed Jan 10, 2023
1 parent a3dbfe6 commit a9e2f6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 138 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies":
{
"commander": "9.4.1",
"glob": "8.0.3"
"fast-glob": "3.2.12"
},
"devDependencies":
{
Expand Down
4 changes: 2 additions & 2 deletions src/core.class.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EOL } from 'os';
import fs from 'fs';
import PATH, { dirname, basename } from 'path';
import glob from 'glob';
import fg from 'fast-glob';
import { program } from 'commander';
import { Helper } from './helper.class.js';
import { Option } from './option.class.js';
Expand Down Expand Up @@ -62,7 +62,7 @@ export class Core
}
};

glob.sync(PATH.join(path, specPattern)).map(filePath =>
fg.sync(PATH.join(path, specPattern)).map(filePath =>
{
const fileContent : string = fs.readFileSync(filePath, 'utf8');

Expand Down
156 changes: 21 additions & 135 deletions tests/core.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,44 +98,44 @@ describe('core', () =>
filePath: 'tests/provider/04/01.spec.ts',
sizes:
{
it: 3,
describe: 2
describe: 2,
it: 3
}
},
{
filePath: 'tests/provider/04/01/01.spec.ts',
filePath: 'tests/provider/04/02.spec.ts',
sizes:
{
it: 3,
describe: 2
describe: 2,
it: 2
}
},
{
filePath: 'tests/provider/04/01/02.spec.ts',
filePath: 'tests/provider/04/03.spec.ts',
sizes:
{
it: 2,
describe: 2
describe: 0,
it: 0
}
},
{
filePath: 'tests/provider/04/01/03.spec.ts',
filePath: 'tests/provider/04/01/01.spec.ts',
sizes:
{
describe: 0,
it: 0
describe: 2,
it: 3
}
},
{
filePath: 'tests/provider/04/02.spec.ts',
filePath: 'tests/provider/04/01/02.spec.ts',
sizes:
{
it: 2,
describe: 2
describe: 2,
it: 2
}
},
{
filePath: 'tests/provider/04/03.spec.ts',
filePath: 'tests/provider/04/01/03.spec.ts',
sizes:
{
describe: 0,
Expand All @@ -152,140 +152,26 @@ describe('core', () =>
{
option.set('amount', 2);
option.set('path', 'tests/provider');
expect(core.cut(core.analyse())).to.have.length(9);
expect(core.cut(core.analyse())).to.eql(
[
{
filePath: 'tests/provider/01/01.spec.ts',
chunkPath: 'tests/__provider__0/01/01.spec.ts'
},
{
filePath: 'tests/provider/02/01.spec.ts',
chunkPath: 'tests/__provider__0/02/01.spec.ts'
},
{
filePath: 'tests/provider/03/01.spec.ts',
chunkPath: 'tests/__provider__0/03/01.spec.ts'
},
{
filePath: 'tests/provider/04/01.spec.ts',
chunkPath: 'tests/__provider__0/04/01.spec.ts'
},
{
filePath: 'tests/provider/04/01/01.spec.ts',
chunkPath: 'tests/__provider__0/04/01/01.spec.ts'
},
{
filePath: 'tests/provider/04/01/02.spec.ts',
chunkPath: 'tests/__provider__1/04/01/02.spec.ts'
},
{
filePath: 'tests/provider/04/01/03.spec.ts',
chunkPath: 'tests/__provider__1/04/01/03.spec.ts'
},
{
filePath: 'tests/provider/04/02.spec.ts',
chunkPath: 'tests/__provider__1/04/02.spec.ts'
},
{
filePath: 'tests/provider/04/03.spec.ts',
chunkPath: 'tests/__provider__1/04/03.spec.ts'
}
]);
expect(core.cut(core.analyse()).filter(chunk => chunk.chunkPath.startsWith('tests/__provider__0'))).to.have.length(5);
expect(core.cut(core.analyse()).filter(chunk => chunk.chunkPath.startsWith('tests/__provider__1'))).to.have.length(4);
});

it('per it', () =>
{
option.set('amount', 2);
option.set('mode', 'it');
option.set('path', 'tests/provider');
expect(core.cut(core.analyse())).to.have.length(9);
expect(core.cut(core.analyse())).to.eql(
[
{
filePath: 'tests/provider/01/01.spec.ts',
chunkPath: 'tests/__provider__0/01/01.spec.ts'
},
{
filePath: 'tests/provider/02/01.spec.ts',
chunkPath: 'tests/__provider__0/02/01.spec.ts'
},
{
filePath: 'tests/provider/03/01.spec.ts',
chunkPath: 'tests/__provider__0/03/01.spec.ts'
},
{
filePath: 'tests/provider/04/01.spec.ts',
chunkPath: 'tests/__provider__1/04/01.spec.ts'
},
{
filePath: 'tests/provider/04/01/01.spec.ts',
chunkPath: 'tests/__provider__1/04/01/01.spec.ts'
},
{
filePath: 'tests/provider/04/01/02.spec.ts',
chunkPath: 'tests/__provider__1/04/01/02.spec.ts'
},
{
filePath: 'tests/provider/04/01/03.spec.ts',
chunkPath: 'tests/__provider__1/04/01/03.spec.ts'
},
{
filePath: 'tests/provider/04/02.spec.ts',
chunkPath: 'tests/__provider__1/04/02.spec.ts'
},
{
filePath: 'tests/provider/04/03.spec.ts',
chunkPath: 'tests/__provider__1/04/03.spec.ts'
}
]);
expect(core.cut(core.analyse()).filter(chunk => chunk.chunkPath.startsWith('tests/__provider__0'))).to.have.length(3);
expect(core.cut(core.analyse()).filter(chunk => chunk.chunkPath.startsWith('tests/__provider__1'))).to.have.length(6);
});

it('per describe', () =>
{
option.set('amount', 2);
option.set('mode', 'describe');
option.set('path', 'tests/provider');
expect(core.cut(core.analyse())).to.have.length(9);
expect(core.cut(core.analyse())).to.eql(
[
{
filePath: 'tests/provider/01/01.spec.ts',
chunkPath: 'tests/__provider__0/01/01.spec.ts'
},
{
filePath: 'tests/provider/02/01.spec.ts',
chunkPath: 'tests/__provider__0/02/01.spec.ts'
},
{
filePath: 'tests/provider/03/01.spec.ts',
chunkPath: 'tests/__provider__0/03/01.spec.ts'
},
{
filePath: 'tests/provider/04/01.spec.ts',
chunkPath: 'tests/__provider__0/04/01.spec.ts'
},
{
filePath: 'tests/provider/04/01/01.spec.ts',
chunkPath: 'tests/__provider__1/04/01/01.spec.ts'
},
{
filePath: 'tests/provider/04/01/02.spec.ts',
chunkPath: 'tests/__provider__1/04/01/02.spec.ts'
},
{
filePath: 'tests/provider/04/01/03.spec.ts',
chunkPath: 'tests/__provider__1/04/01/03.spec.ts'
},
{
filePath: 'tests/provider/04/02.spec.ts',
chunkPath: 'tests/__provider__1/04/02.spec.ts'
},
{
filePath: 'tests/provider/04/03.spec.ts',
chunkPath: 'tests/__provider__1/04/03.spec.ts'
}
]);
expect(core.cut(core.analyse()).filter(chunk => chunk.chunkPath.startsWith('tests/__provider__0'))).to.have.length(4);
expect(core.cut(core.analyse()).filter(chunk => chunk.chunkPath.startsWith('tests/__provider__1'))).to.have.length(5);
});
});
});

0 comments on commit a9e2f6f

Please sign in to comment.