mo3ta-coverage 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -57
- package/RECOMMENDED_USAGE.md +67 -0
- package/coverage/clover.xml +236 -0
- package/coverage/coverage-final.json +4 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/cli.js.html +1090 -0
- package/coverage/lcov-report/coverage/index.html +116 -0
- package/coverage/lcov-report/coverage/index.js.html +364 -0
- package/coverage/lcov-report/coverage/src/cli.js.html +652 -0
- package/coverage/lcov-report/coverage/src/fileUtils.js.html +130 -0
- package/coverage/lcov-report/coverage/src/gitUtils.js.html +145 -0
- package/coverage/lcov-report/coverage/src/index.html +146 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/fileUtils.js.html +361 -0
- package/coverage/lcov-report/gitUtils.js.html +145 -0
- package/coverage/lcov-report/index.html +146 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +416 -0
- package/index.js +19 -8
- package/package.json +1 -1
- package/src/cli.js +202 -52
- package/src/cli.test.js +113 -0
- package/src/fileUtils.js +77 -0
- package/src/fileUtils.test.js +151 -1
- package/.github/workflows/publish.yml +0 -29
- package/.mo3ta-coverage.json +0 -4
package/src/fileUtils.test.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getJsOnlyFiles } from './fileUtils';
|
|
1
|
+
import { getJsOnlyFiles, separateSourceAndTestFiles, findTestFilesForSource } from './fileUtils';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
|
|
3
4
|
describe('getJsOnlyFiles', () => {
|
|
4
5
|
const files = [
|
|
@@ -81,4 +82,153 @@ describe('getJsOnlyFiles', () => {
|
|
|
81
82
|
'src/page.tsx'
|
|
82
83
|
]);
|
|
83
84
|
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('separateSourceAndTestFiles', () => {
|
|
88
|
+
it('should separate source and test files correctly', () => {
|
|
89
|
+
const files = [
|
|
90
|
+
'src/app.js',
|
|
91
|
+
'src/utils.ts',
|
|
92
|
+
'src/app.test.js',
|
|
93
|
+
'src/utils.spec.ts',
|
|
94
|
+
'src/component.jsx',
|
|
95
|
+
'src/component.test.jsx'
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const result = separateSourceAndTestFiles(files);
|
|
99
|
+
|
|
100
|
+
expect(result.sourceFiles).toEqual([
|
|
101
|
+
'src/app.js',
|
|
102
|
+
'src/utils.ts',
|
|
103
|
+
'src/component.jsx'
|
|
104
|
+
]);
|
|
105
|
+
expect(result.testFiles).toEqual([
|
|
106
|
+
'src/app.test.js',
|
|
107
|
+
'src/utils.spec.ts',
|
|
108
|
+
'src/component.test.jsx'
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should exclude config and json files', () => {
|
|
113
|
+
const files = [
|
|
114
|
+
'src/app.js',
|
|
115
|
+
'jest.config.js',
|
|
116
|
+
'package.json',
|
|
117
|
+
'src/data.json'
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
const result = separateSourceAndTestFiles(files);
|
|
121
|
+
|
|
122
|
+
expect(result.sourceFiles).toEqual(['src/app.js']);
|
|
123
|
+
expect(result.testFiles).toEqual([]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should handle empty array', () => {
|
|
127
|
+
const result = separateSourceAndTestFiles([]);
|
|
128
|
+
|
|
129
|
+
expect(result.sourceFiles).toEqual([]);
|
|
130
|
+
expect(result.testFiles).toEqual([]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('should handle all test files', () => {
|
|
134
|
+
const files = [
|
|
135
|
+
'src/app.test.js',
|
|
136
|
+
'src/utils.spec.ts'
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
const result = separateSourceAndTestFiles(files);
|
|
140
|
+
|
|
141
|
+
expect(result.sourceFiles).toEqual([]);
|
|
142
|
+
expect(result.testFiles).toEqual([
|
|
143
|
+
'src/app.test.js',
|
|
144
|
+
'src/utils.spec.ts'
|
|
145
|
+
]);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('findTestFilesForSource', () => {
|
|
150
|
+
// Mock fs.existsSync for testing
|
|
151
|
+
const originalExistsSync = fs.existsSync;
|
|
152
|
+
|
|
153
|
+
beforeEach(() => {
|
|
154
|
+
// Reset mock before each test
|
|
155
|
+
fs.existsSync = jest.fn();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
afterEach(() => {
|
|
159
|
+
// Restore original function
|
|
160
|
+
fs.existsSync = originalExistsSync;
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('should find test file in same directory with .test.js pattern', () => {
|
|
164
|
+
fs.existsSync.mockImplementation((path) => {
|
|
165
|
+
return path === 'src/utils/helper.test.js';
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const result = findTestFilesForSource('src/utils/helper.js');
|
|
169
|
+
|
|
170
|
+
expect(result).toContain('src/utils/helper.test.js');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should find test file in __tests__ subdirectory', () => {
|
|
174
|
+
fs.existsSync.mockImplementation((path) => {
|
|
175
|
+
return path === 'src/utils/__tests__/helper.test.js';
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const result = findTestFilesForSource('src/utils/helper.js');
|
|
179
|
+
|
|
180
|
+
expect(result).toContain('src/utils/__tests__/helper.test.js');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('should find multiple test files if they exist', () => {
|
|
184
|
+
fs.existsSync.mockImplementation((path) => {
|
|
185
|
+
return path === 'src/utils/helper.test.js' ||
|
|
186
|
+
path === 'src/utils/helper.spec.js';
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const result = findTestFilesForSource('src/utils/helper.js');
|
|
190
|
+
|
|
191
|
+
expect(result).toContain('src/utils/helper.test.js');
|
|
192
|
+
expect(result).toContain('src/utils/helper.spec.js');
|
|
193
|
+
expect(result.length).toBe(2);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should return empty array if no test files exist', () => {
|
|
197
|
+
fs.existsSync.mockReturnValue(false);
|
|
198
|
+
|
|
199
|
+
const result = findTestFilesForSource('src/utils/helper.js');
|
|
200
|
+
|
|
201
|
+
expect(result).toEqual([]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should find test files in parallel tests directory structure', () => {
|
|
205
|
+
fs.existsSync.mockImplementation((path) => {
|
|
206
|
+
// path.join normalizes paths, removing leading './'
|
|
207
|
+
return path === 'src/tests/utils/helper.test.js';
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const result = findTestFilesForSource('./src/utils/helper.js');
|
|
211
|
+
|
|
212
|
+
expect(result).toContain('src/tests/utils/helper.test.js');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('should handle TypeScript files', () => {
|
|
216
|
+
fs.existsSync.mockImplementation((path) => {
|
|
217
|
+
return path === 'src/utils/helper.test.ts';
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const result = findTestFilesForSource('src/utils/helper.ts');
|
|
221
|
+
|
|
222
|
+
expect(result).toContain('src/utils/helper.test.ts');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should handle JSX files', () => {
|
|
226
|
+
fs.existsSync.mockImplementation((path) => {
|
|
227
|
+
return path === 'src/components/Button.test.jsx';
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
const result = findTestFilesForSource('src/components/Button.jsx');
|
|
231
|
+
|
|
232
|
+
expect(result).toContain('src/components/Button.test.jsx');
|
|
233
|
+
});
|
|
84
234
|
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
name: Publish Package
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches:
|
|
5
|
-
- main
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
publish:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
steps:
|
|
11
|
-
- name: Checkout code
|
|
12
|
-
uses: actions/checkout@v2
|
|
13
|
-
|
|
14
|
-
- name: Set up Node.js
|
|
15
|
-
uses: actions/setup-node@v2
|
|
16
|
-
with:
|
|
17
|
-
node-version: '16'
|
|
18
|
-
|
|
19
|
-
- name: Install dependencies
|
|
20
|
-
run: npm install
|
|
21
|
-
|
|
22
|
-
# - name: Run tests
|
|
23
|
-
# run: npm test
|
|
24
|
-
|
|
25
|
-
- name: Configure npm authentication
|
|
26
|
-
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
|
|
27
|
-
|
|
28
|
-
- name: Publish package
|
|
29
|
-
run: npm publish
|
package/.mo3ta-coverage.json
DELETED