@openwebf/webf 0.23.7 → 0.23.10

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.
@@ -2,18 +2,20 @@
2
2
  jest.mock('fs');
3
3
  jest.mock('child_process');
4
4
  jest.mock('../src/generator');
5
- jest.mock('glob');
5
+ jest.mock('glob', () => ({
6
+ globSync: jest.fn(),
7
+ }));
6
8
  jest.mock('inquirer');
7
9
  jest.mock('yaml');
8
10
 
9
11
  import fs from 'fs';
10
12
  import path from 'path';
11
13
  import { spawnSync } from 'child_process';
12
- import { glob } from 'glob';
14
+ import { globSync } from 'glob';
13
15
 
14
16
  const mockFs = fs as jest.Mocked<typeof fs>;
15
17
  const mockSpawnSync = spawnSync as jest.MockedFunction<typeof spawnSync>;
16
- const mockGlob = glob as jest.Mocked<typeof glob>;
18
+ const mockGlobSync = globSync as jest.MockedFunction<typeof globSync>;
17
19
 
18
20
  // Set up default mocks before importing commands
19
21
  mockFs.readFileSync = jest.fn().mockImplementation((filePath: any) => {
@@ -87,7 +89,7 @@ describe('Commands', () => {
87
89
  });
88
90
  // Default mock for readdirSync to avoid undefined
89
91
  mockFs.readdirSync.mockReturnValue([] as any);
90
- mockGlob.globSync.mockReturnValue([]);
92
+ mockGlobSync.mockReturnValue([]);
91
93
  });
92
94
 
93
95
 
@@ -224,11 +226,11 @@ describe('Commands', () => {
224
226
  // Mock that required files don't exist
225
227
  mockFs.existsSync.mockReturnValue(false);
226
228
 
227
- await generateCommand(target, options);
229
+ await generateCommand(target, options);
228
230
 
229
231
  expect(mockSpawnSync).toHaveBeenCalledWith(
230
232
  expect.stringMatching(/npm(\.cmd)?/),
231
- ['install', '--omit=peer'],
233
+ ['install'],
232
234
  { cwd: target, stdio: 'inherit' }
233
235
  );
234
236
  });
@@ -471,8 +473,8 @@ describe('Commands', () => {
471
473
  // Mock TypeScript validation
472
474
  mockTypeScriptValidation('/flutter/src');
473
475
 
474
- // Mock .d.ts files so copyMarkdownDocsToDist sees at least one entry
475
- mockGlob.globSync.mockReturnValue(['lib/src/alert.d.ts'] as any);
476
+ // Mock .d.ts files so copyMarkdownDocsToDist sees at least one entry
477
+ mockGlobSync.mockReturnValue(['lib/src/alert.d.ts'] as any);
476
478
 
477
479
  const originalExistsSync = mockFs.existsSync as jest.Mock;
478
480
  mockFs.existsSync = jest.fn().mockImplementation((filePath: any) => {
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { glob } from 'glob';
3
+ import { globSync } from 'glob';
4
4
  import { dartGen, reactGen, vueGen, clearAllCaches } from '../src/generator';
5
5
  import * as analyzer from '../src/analyzer';
6
6
  import * as dartGenerator from '../src/dart';
@@ -10,7 +10,9 @@ import { ClassObject } from '../src/declaration';
10
10
 
11
11
  // Mock dependencies
12
12
  jest.mock('fs');
13
- jest.mock('glob');
13
+ jest.mock('glob', () => ({
14
+ globSync: jest.fn(),
15
+ }));
14
16
  jest.mock('../src/analyzer');
15
17
  jest.mock('../src/dart');
16
18
  jest.mock('../src/react');
@@ -47,7 +49,7 @@ jest.mock('../src/logger', () => ({
47
49
  }));
48
50
 
49
51
  const mockFs = fs as jest.Mocked<typeof fs>;
50
- const mockGlob = glob as jest.Mocked<typeof glob>;
52
+ const mockGlobSync = globSync as jest.MockedFunction<typeof globSync>;
51
53
  const mockAnalyzer = analyzer as jest.Mocked<typeof analyzer>;
52
54
  const mockDartGenerator = dartGenerator as jest.Mocked<typeof dartGenerator>;
53
55
  const mockReactGenerator = reactGenerator as jest.Mocked<typeof reactGenerator>;
@@ -65,7 +67,7 @@ describe('Generator', () => {
65
67
  mockFs.writeFileSync.mockImplementation(() => undefined);
66
68
  mockFs.mkdirSync.mockImplementation(() => undefined);
67
69
 
68
- mockGlob.globSync.mockReturnValue(['test.d.ts', 'component.d.ts']);
70
+ mockGlobSync.mockReturnValue(['test.d.ts', 'component.d.ts']);
69
71
 
70
72
  mockAnalyzer.analyzer.mockImplementation(() => undefined);
71
73
  mockAnalyzer.clearCaches.mockImplementation(() => undefined);
@@ -84,7 +86,7 @@ describe('Generator', () => {
84
86
  command: 'test command'
85
87
  });
86
88
 
87
- expect(mockGlob.globSync).toHaveBeenCalledWith('**/*.d.ts', {
89
+ expect(mockGlobSync).toHaveBeenCalledWith('**/*.d.ts', {
88
90
  cwd: '/test/source',
89
91
  ignore: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/example/**']
90
92
  });
@@ -101,14 +103,14 @@ describe('Generator', () => {
101
103
  command: 'test command'
102
104
  });
103
105
 
104
- expect(mockGlob.globSync).toHaveBeenCalledWith('**/*.d.ts', {
106
+ expect(mockGlobSync).toHaveBeenCalledWith('**/*.d.ts', {
105
107
  cwd: expect.stringContaining('relative/source'),
106
108
  ignore: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/example/**']
107
109
  });
108
110
  });
109
111
 
110
112
  it('should filter out global.d.ts files', async () => {
111
- mockGlob.globSync.mockReturnValue(['test.d.ts', 'global.d.ts', 'component.d.ts']);
113
+ mockGlobSync.mockReturnValue(['test.d.ts', 'global.d.ts', 'component.d.ts']);
112
114
 
113
115
  await dartGen({
114
116
  source: '/test/source',
@@ -122,7 +124,7 @@ describe('Generator', () => {
122
124
  });
123
125
 
124
126
  it('should handle empty type files', async () => {
125
- mockGlob.globSync.mockReturnValue([]);
127
+ mockGlobSync.mockReturnValue([]);
126
128
 
127
129
  await dartGen({
128
130
  source: '/test/source',
@@ -135,7 +137,7 @@ describe('Generator', () => {
135
137
  });
136
138
 
137
139
  it('should continue processing if one file fails', async () => {
138
- mockGlob.globSync.mockReturnValue(['test1.d.ts', 'test2.d.ts']);
140
+ mockGlobSync.mockReturnValue(['test1.d.ts', 'test2.d.ts']);
139
141
  mockAnalyzer.analyzer
140
142
  .mockImplementationOnce(() => { throw new Error('Parse error'); })
141
143
  .mockImplementationOnce(() => undefined);
@@ -216,7 +218,7 @@ describe('Generator', () => {
216
218
  });
217
219
 
218
220
  it('should generate index.d.ts with references and exports', async () => {
219
- mockGlob.globSync.mockReturnValue(['components/button.d.ts', 'widgets/card.d.ts']);
221
+ mockGlobSync.mockReturnValue(['components/button.d.ts', 'widgets/card.d.ts']);
220
222
  mockFs.readFileSync.mockReturnValue('interface Test {}');
221
223
  mockFs.existsSync.mockImplementation((path) => {
222
224
  // Source directory exists
@@ -247,7 +249,7 @@ describe('Generator', () => {
247
249
  });
248
250
 
249
251
  it('should copy original .d.ts files to output directory', async () => {
250
- mockGlob.globSync.mockReturnValue(['test.d.ts']);
252
+ mockGlobSync.mockReturnValue(['test.d.ts']);
251
253
  const originalContent = 'interface Original {}';
252
254
  mockFs.readFileSync.mockReturnValue(originalContent);
253
255
  mockFs.existsSync.mockImplementation((path) => {
@@ -279,7 +281,7 @@ describe('Generator', () => {
279
281
  exclude: ['**/test/**', '**/docs/**']
280
282
  });
281
283
 
282
- expect(mockGlob.globSync).toHaveBeenCalledWith('**/*.d.ts', {
284
+ expect(mockGlobSync).toHaveBeenCalledWith('**/*.d.ts', {
283
285
  cwd: '/test/source',
284
286
  ignore: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/example/**', '**/test/**', '**/docs/**']
285
287
  });
@@ -419,7 +421,7 @@ describe('Generator', () => {
419
421
  });
420
422
 
421
423
  it('should only generate one index.d.ts file', async () => {
422
- mockGlob.globSync.mockReturnValue(['comp1.d.ts', 'comp2.d.ts', 'comp3.d.ts']);
424
+ mockGlobSync.mockReturnValue(['comp1.d.ts', 'comp2.d.ts', 'comp3.d.ts']);
423
425
 
424
426
  await vueGen({
425
427
  source: '/test/source',
@@ -436,7 +438,7 @@ describe('Generator', () => {
436
438
 
437
439
  describe('Error handling', () => {
438
440
  it('should handle glob errors', async () => {
439
- mockGlob.globSync.mockImplementation(() => {
441
+ mockGlobSync.mockImplementation(() => {
440
442
  throw new Error('Glob error');
441
443
  });
442
444