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.
@@ -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
@@ -1,4 +0,0 @@
1
- {
2
- "shallowTests": false,
3
- "base": "origin/dev"
4
- }