Skip to content

Commit 532da2f

Browse files
Copilotanupriya13
andcommitted
Fix build error: make ModuleWindowsSetup properties public for testing
Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>
1 parent 728a26e commit 532da2f

2 files changed

Lines changed: 46 additions & 29 deletions

File tree

packages/@react-native-windows/cli/src/commands/moduleWindowsSetup/__tests__/moduleWindowsSetup.test.ts

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@ describe('ModuleWindowsSetup', () => {
2929
const setup = new ModuleWindowsSetup('/test', mockOptions);
3030
// Access private method for testing
3131
const getModuleName = (setup as any).getModuleName.bind(setup);
32-
32+
3333
expect(getModuleName('react-native-webview')).toBe('ReactNativeWebview');
34-
expect(getModuleName('@react-native-community/slider')).toBe('ReactNativeCommunitySlider');
34+
expect(getModuleName('@react-native-community/slider')).toBe(
35+
'ReactNativeCommunitySlider',
36+
);
3537
expect(getModuleName('simple-module')).toBe('SimpleModule');
36-
expect(getModuleName('@scope/complex-package-name')).toBe('ScopeComplexPackageName');
38+
expect(getModuleName('@scope/complex-package-name')).toBe(
39+
'ScopeComplexPackageName',
40+
);
3741
});
3842

3943
it('should handle edge cases', () => {
4044
const setup = new ModuleWindowsSetup('/test', mockOptions);
4145
const getModuleName = (setup as any).getModuleName.bind(setup);
42-
46+
4347
expect(getModuleName('')).toBe('');
4448
expect(getModuleName('single')).toBe('Single');
4549
expect(getModuleName('---multiple---dashes---')).toBe('MultipleDashes');
@@ -49,45 +53,49 @@ describe('ModuleWindowsSetup', () => {
4953
describe('extractMethodsFromSpecInterface', () => {
5054
it('should parse method signatures from TypeScript interface', () => {
5155
const setup = new ModuleWindowsSetup('/test', mockOptions);
52-
const extractMethods = (setup as any).extractMethodsFromSpecInterface.bind(setup);
53-
56+
const extractMethods = (
57+
setup as any
58+
).extractMethodsFromSpecInterface.bind(setup);
59+
5460
const specContent = `
5561
export interface Spec extends TurboModule {
5662
getString(value: string): Promise<string>;
5763
getNumber(count: number): Promise<number>;
5864
getBool(): Promise<boolean>;
5965
syncMethod(data: object): void;
6066
}`;
61-
67+
6268
const methods = extractMethods(specContent);
63-
69+
6470
expect(methods).toHaveLength(4);
6571
expect(methods[0]).toEqual({
6672
name: 'getString',
6773
returnType: 'Promise<string>',
68-
parameters: [{ name: 'value', type: 'string' }]
74+
parameters: [{name: 'value', type: 'string'}],
6975
});
7076
expect(methods[1]).toEqual({
7177
name: 'getNumber',
7278
returnType: 'Promise<number>',
73-
parameters: [{ name: 'count', type: 'number' }]
79+
parameters: [{name: 'count', type: 'number'}],
7480
});
7581
expect(methods[2]).toEqual({
7682
name: 'getBool',
7783
returnType: 'Promise<boolean>',
78-
parameters: []
84+
parameters: [],
7985
});
8086
expect(methods[3]).toEqual({
8187
name: 'syncMethod',
8288
returnType: 'void',
83-
parameters: [{ name: 'data', type: 'object' }]
89+
parameters: [{name: 'data', type: 'object'}],
8490
});
8591
});
8692

8793
it('should handle complex parameter types', () => {
8894
const setup = new ModuleWindowsSetup('/test', mockOptions);
89-
const extractMethods = (setup as any).extractMethodsFromSpecInterface.bind(setup);
90-
95+
const extractMethods = (
96+
setup as any
97+
).extractMethodsFromSpecInterface.bind(setup);
98+
9199
const specContent = `
92100
export interface Spec extends TurboModule {
93101
complexMethod(
@@ -98,9 +106,9 @@ export interface Spec extends TurboModule {
98106
callback: (result: any) => void
99107
): Promise<any>;
100108
}`;
101-
109+
102110
const methods = extractMethods(specContent);
103-
111+
104112
expect(methods).toHaveLength(1);
105113
expect(methods[0].name).toBe('complexMethod');
106114
expect(methods[0].parameters).toHaveLength(2);
@@ -111,7 +119,7 @@ export interface Spec extends TurboModule {
111119
it('should map TypeScript types to C++ types correctly', () => {
112120
const setup = new ModuleWindowsSetup('/test', mockOptions);
113121
const mapTsToCpp = (setup as any).mapTSToCppType.bind(setup);
114-
122+
115123
expect(mapTsToCpp('string')).toBe('std::string');
116124
expect(mapTsToCpp('number')).toBe('double');
117125
expect(mapTsToCpp('boolean')).toBe('bool');
@@ -125,10 +133,15 @@ export interface Spec extends TurboModule {
125133
describe('constructor', () => {
126134
it('should create instance with correct root and options', () => {
127135
const root = '/test/project';
128-
const options = {logging: true, telemetry: true, skipDeps: true, skipBuild: true};
129-
136+
const options = {
137+
logging: true,
138+
telemetry: true,
139+
skipDeps: true,
140+
skipBuild: true,
141+
};
142+
130143
const setup = new ModuleWindowsSetup(root, options);
131-
144+
132145
expect(setup.root).toBe(root);
133146
expect(setup.options).toBe(options);
134147
});
@@ -138,21 +151,23 @@ export interface Spec extends TurboModule {
138151
it('should log when logging is enabled', () => {
139152
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
140153
const setup = new ModuleWindowsSetup('/test', {logging: true});
141-
154+
142155
(setup as any).verboseMessage('test message');
143-
144-
expect(consoleSpy).toHaveBeenCalledWith('[ModuleWindowsSetup] test message');
156+
157+
expect(consoleSpy).toHaveBeenCalledWith(
158+
'[ModuleWindowsSetup] test message',
159+
);
145160
consoleSpy.mockRestore();
146161
});
147162

148163
it('should not log when logging is disabled', () => {
149164
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
150165
const setup = new ModuleWindowsSetup('/test', {logging: false});
151-
166+
152167
(setup as any).verboseMessage('test message');
153-
168+
154169
expect(consoleSpy).not.toHaveBeenCalled();
155170
consoleSpy.mockRestore();
156171
});
157172
});
158-
});
173+
});

packages/@react-native-windows/cli/src/commands/moduleWindowsSetup/moduleWindowsSetup.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ interface MethodSignature {
4242

4343
export class ModuleWindowsSetup {
4444
private actualModuleName?: string;
45-
private root: string;
46-
private options: ModuleWindowsSetupOptions;
45+
public root: string;
46+
public options: ModuleWindowsSetupOptions;
4747

4848
constructor(root: string, options: ModuleWindowsSetupOptions) {
4949
this.root = root;
@@ -890,7 +890,9 @@ ${defaultMethods}
890890
const exampleReturn =
891891
method.returnType === 'void'
892892
? ''
893-
: `\n // TODO: Return appropriate value\n return ${this.generateDefaultValue(method.returnType)};`;
893+
: `\n // TODO: Return appropriate value\n return ${this.generateDefaultValue(
894+
method.returnType,
895+
)};`;
894896

895897
return `${returnTypeIsCpp} ${moduleName}::${method.name}(${cppParams}) noexcept {
896898
// TODO: Implement ${method.name}${exampleReturn}

0 commit comments

Comments
 (0)