• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

henryruhs / specut / 3882082375

pending completion
3882082375

push

github

henryruhs
Initial commit

43 of 44 branches covered (97.73%)

Branch coverage included in aggregate %.

250 of 250 new or added lines in 5 files covered. (100.0%)

237 of 250 relevant lines covered (94.8%)

20.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.17
/src/core.class.ts
1
import os from 'os';
1✔
2
import fs from 'fs';
1✔
3
import PATH, { dirname, basename } from 'path';
1✔
4
import glob from 'glob';
1✔
5
import { program } from 'commander';
1✔
6
import { Helper } from './helper.class.js';
1✔
7
import { Option } from './option.class.js';
1✔
8
import { Metadata, Data, Chunk } from './core.interface.js';
1✔
9
import { Options } from './option.interface';
1✔
10

1✔
11
export class Core
1✔
12
{
1✔
13
        metadataObject : Metadata = this.helper.readJsonFromAbsolutePath('./assets/metadata.json') as Metadata;
1✔
14

1✔
15
        constructor(
1✔
16
                protected helper : Helper,
9✔
17
                protected option : Option
9✔
18
        )
9✔
19
        {
9✔
20
        }
9✔
21

1✔
22
        init() : void
1✔
23
        {
×
24
                this.cut(this.analyse()).map(chunk => fs.cp(chunk.filePath, chunk.chunkPath,
×
25
                {
×
26
                        recursive: true
×
27
                }, () => process.stdout.write('.')));
×
28
                process.stdout.write(os.EOL);
×
29
        }
×
30

1✔
31
        cli(process : NodeJS.Process) : void
1✔
32
        {
2✔
33
                program
2✔
34
                        .version(this.metadataObject.name + ' ' + this.metadataObject.version)
2✔
35
                        .option('-C, --config <config>')
2✔
36
                        .option('-A, --amount <amount>')
2✔
37
                        .option('-M, --mode <mode>')
2✔
38
                        .option('-P, --path <path>')
2✔
39
                        .parse(process.argv);
2✔
40

2✔
41
                this.option.init(
2✔
42
                {
2✔
43
                        config: program.getOptionValue('config'),
2✔
44
                        amount: program.getOptionValue('amount'),
2✔
45
                        mode: program.getOptionValue('mode'),
2✔
46
                        path: program.getOptionValue('path')
2✔
47
                });
2✔
48
                this.init();
2✔
49
        }
2✔
50

1✔
51
        analyse() : Data
1✔
52
        {
14✔
53
                const { path, specPattern } : Options = this.option.getAll();
14✔
54
                const data : Data =
14✔
55
                {
14✔
56
                        files: [],
14✔
57
                        sizes:
14✔
58
                        {
14✔
59
                                file: 0,
14✔
60
                                it: 0,
14✔
61
                                describe: 0
14✔
62
                        }
14✔
63
                };
14✔
64

14✔
65
                glob.sync(PATH.join(path, specPattern)).map(filePath =>
14✔
66
                {
72✔
67
                        const fileContent : string = fs.readFileSync(filePath, 'utf8');
72✔
68

72✔
69
                        data.sizes.file++;
72✔
70
                        data.files.push(
72✔
71
                        {
72✔
72
                                filePath,
72✔
73
                                sizes:
72✔
74
                                {
72✔
75
                                        it: (() =>
72✔
76
                                        {
72✔
77
                                                const size : number = fileContent.match(/it\(/g)?.length || 0;
72✔
78

72✔
79
                                                data.sizes.it += size;
72✔
80
                                                return size;
72✔
81
                                        })(),
72✔
82
                                        describe: (() =>
72✔
83
                                        {
72✔
84
                                                const size : number = fileContent.match(/describe\(/g)?.length || 0;
72✔
85

72✔
86
                                                data.sizes.describe += size;
72✔
87
                                                return size;
72✔
88
                                        })()
72✔
89
                                }
72✔
90
                        });
72✔
91
                });
14✔
92
                return data;
14✔
93
        }
14✔
94

1✔
95
        cut(data : Data) : Chunk[]
1✔
96
        {
6✔
97
                const { mode } : Options = this.option.getAll();
6✔
98
                let currentIndex : number = 0;
6✔
99

6✔
100
                return data.files
6✔
101
                        .map((file, index) =>
6✔
102
                        {
54✔
103
                                if (mode === 'it')
54✔
104
                                {
54✔
105
                                        currentIndex = currentIndex + file.sizes.it;
18✔
106
                                        return { file, chunkIndex: this.getChunkIndex(currentIndex, data) };
18✔
107
                                }
18✔
108
                                else if (mode === 'describe')
36✔
109
                                {
36✔
110
                                        currentIndex = currentIndex + file.sizes.describe;
18✔
111
                                        return { file, chunkIndex: this.getChunkIndex(currentIndex, data) };
18✔
112
                                }
18✔
113
                                return { file, chunkIndex: this.getChunkIndex(index, data) };
18✔
114
                        })
6✔
115
                        .map(({ file, chunkIndex }) =>
6✔
116
                        {
54✔
117
                                return { filePath: file.filePath, chunkPath: this.getChunkPath(file.filePath, chunkIndex) };
54✔
118
                        });
6✔
119
        }
6✔
120

1✔
121
        protected getChunkPath(filePath : string, chunkIndex : number) : string
1✔
122
        {
54✔
123
                const { chunkPrefix, chunkSuffix, path } : Options = this.option.getAll();
54✔
124

54✔
125
                return PATH.join(
54✔
126
                        dirname(path),
54✔
127
                        chunkPrefix + basename(path) + chunkSuffix + chunkIndex,
54✔
128
                        filePath.replace(path, '')
54✔
129
                );
54✔
130
        }
54✔
131

1✔
132
        protected getChunkIndex(currentIndex : number, data : Data) : number
1✔
133
        {
54✔
134
                const { amount } : Options = this.option.getAll();
54✔
135
                const chunkIndex : number = Math.floor(currentIndex / this.perChunk(data));
54✔
136

54✔
137
                return chunkIndex < amount ? chunkIndex : amount - 1;
54✔
138
        }
54✔
139

1✔
140
        protected perChunk(data : Data) : number
1✔
141
        {
54✔
142
                const { amount, mode } : Options = this.option.getAll();
54✔
143

54✔
144
                if (mode === 'it')
54✔
145
                {
54✔
146
                        return Math.ceil(data.sizes.it / amount);
18✔
147
                }
18✔
148
                if (mode === 'describe')
36✔
149
                {
54✔
150
                        return Math.ceil(data.sizes.describe / amount);
18✔
151
                }
18✔
152
                return Math.ceil(data.sizes.file / amount);
18✔
153
        }
18✔
154
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc