Skip to content

Commit

Permalink
Merge e13773a into 276144e
Browse files Browse the repository at this point in the history
  • Loading branch information
henryruhs committed Jan 11, 2023
2 parents 276144e + e13773a commit b840d9e
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 38 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ Usage
Run the command:

```
specut [options]
specut [options] [path]
-V, --version
-C, --config <config>
-A, --amount <amount>
-M, --mode <mode>
-P, --path <path>
-c, --config <config>
-a, --amount <amount>
-m, --mode <mode>
-v, --version
-h, --help
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "specut",
"description": "Cut massive test suites into equal chunks",
"version": "1.1.0",
"version": "2.0.0",
"license": "MIT",
"type": "module",
"keywords":
Expand Down
2 changes: 1 addition & 1 deletion src/assets/metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "specut",
"version": "1.1.0"
"version": "2.0.0"
}
12 changes: 9 additions & 3 deletions src/assets/option.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"config": ".specut",
"path": ".",
"config": ".specutrc",
"amount": 5,
"mode": "file",
"modeArray":
[
"file",
"it",
"describe"
],
"specPattern": "**/*.spec.{js,jsx,ts,tsx}",
"ignorePattern": "**/node_modules",
"chunkPrefix": "__",
"chunkSuffix": "__",
"path": "."
"chunkSuffix": "__"
}
48 changes: 28 additions & 20 deletions src/core.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EOL } from 'os';
import fs from 'fs';
import glob from 'fast-glob';
import PATH, { dirname, basename } from 'path';
import { program } from 'commander';
import { program, Option as CommanderOption } from 'commander';
import { Helper } from './helper.class.js';
import { Option } from './option.class.js';
import { Metadata, File, Data, Chunk } from './core.interface.js';
Expand All @@ -22,30 +22,37 @@ export class Core

init() : void
{
this.cut(this.analyse())
.map(chunk => fs.cpSync(chunk.filePath, chunk.chunkPath))
.map(() => this.stream.write('.'));
this.stream.write(EOL);
const chunks : Chunk[] = this.cut(this.analyse());

chunks.map(chunk => fs.cpSync(chunk.filePath, chunk.chunkPath)).map(() => this.stream.write('.'));
if (chunks.length)
{
this.stream.write(EOL);
}
}

cli(process : NodeJS.Process) : void
{
const { modeArray } : Options = this.option.getAll();

program
.version(this.metadataObject.name + ' ' + this.metadataObject.version)
.option('-C, --config <config>')
.option('-A, --amount <amount>')
.option('-M, --mode <mode>')
.option('-P, --path <path>')
.argument('[path]')
.option('-c, --config <config>')
.option('-a, --amount <amount>')
.addOption(new CommanderOption('-m, --mode <mode>').choices(modeArray))
.version(this.metadataObject.name + ' ' + this.metadataObject.version, '-v, --version')
.action(path =>
{
this.option.init(
{
path,
config: program.getOptionValue('config'),
amount: program.getOptionValue('amount'),
mode: program.getOptionValue('mode')
});
this.init();
})
.parse(process.argv);

this.option.init(
{
config: program.getOptionValue('config'),
amount: program.getOptionValue('amount'),
mode: program.getOptionValue('mode'),
path: program.getOptionValue('path')
});
this.init();
}

analyse() : Data
Expand Down Expand Up @@ -94,10 +101,11 @@ export class Core

cut(data : Data) : Chunk[]
{
const { mode } : Options = this.option.getAll();
const { mode, modeArray } : Options = this.option.getAll();
let currentIndex : number = 0;

return data.files
.filter(value => modeArray.includes(mode) ? value : null)
.map((file, index) =>
{
if (mode === 'it')
Expand Down
1 change: 1 addition & 0 deletions src/option.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Options
config : string;
amount : number;
mode : Mode;
modeArray : Mode[];
specPattern : string;
ignorePattern : string;
chunkPrefix : string,
Expand Down
2 changes: 1 addition & 1 deletion tests/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('cli', () =>
{
it('run main command', done =>
{
exec('node --loader ts-node/esm src/cli.ts --path=tests/provider --amount=2', error =>
exec('node --loader ts-node/esm src/cli.ts tests/provider --amount=2', error =>
{
expect(error).to.be.null;
expect(fs.readdirSync('tests/__provider__0')).to.be.eql([ '01', '02', '03', '04' ]);
Expand Down
12 changes: 6 additions & 6 deletions tests/option.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ describe('option', () =>

it('init', () =>
{
expect(option.get('config')).to.equal('.specut');
expect(option.get('amount')).to.equal(5);
expect(option.get('path')).to.equal('.');
expect(option.get('config')).to.equal('.specutrc');
expect(option.get('amount')).to.equal(5);
option.init(
{
config: 'tests/provider/.specut',
path: '..'
path: 'tests/provider',
config: 'tests/provider/.specutrc'
});
expect(option.get('config')).to.equal('tests/provider/.specut');
expect(option.get('path')).to.equal('tests/provider');
expect(option.get('config')).to.equal('tests/provider/.specutrc');
expect(option.get('amount')).to.equal(10);
expect(option.get('path')).to.equal('..');
});

it('get and set', () =>
Expand Down
File renamed without changes.

0 comments on commit b840d9e

Please sign in to comment.