Skip to content

Commit 71f2f05

Browse files
coadofacebook-github-bot
authored andcommitted
Align breaking change detection with new snapshot format (#52353)
Summary: Pull Request resolved: #52353 This diff aligns breaking change detection script with new snapshot format. It compares hashes to determine if the API changed for each specifier. Changelog: [Internal] Reviewed By: huntie Differential Revision: D77377762 fbshipit-source-id: e1c69692ace389fb08ae9470b9f9631e53834206
1 parent 1c7b04d commit 71f2f05

File tree

2 files changed

+108
-205
lines changed

2 files changed

+108
-205
lines changed

scripts/diff-api-snapshot/__tests__/diffApiSnapshot-test.js

Lines changed: 45 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@ describe('diffApiSnapshot', () => {
1717
test('should detect breaking change when a statement is deleted', () => {
1818
const prevSnapshot = `
1919
import * as React from 'react';
20-
export declare type AccessibilityActionEvent = NativeSyntheticEvent<
20+
declare type AccessibilityActionEvent = NativeSyntheticEvent<
2121
Readonly<{
2222
actionName: string;
2323
}>
2424
>;
25-
export declare const AccessibilityInfo: typeof AccessibilityInfo_2;
26-
export declare const DeletedExport: string;
25+
declare const AccessibilityInfo: typeof AccessibilityInfo_2;
26+
declare const DeletedExport: string;
27+
export {
28+
AccessibilityActionEvent, // 00000001
29+
AccessibilityInfo, // 00000002
30+
DeletedExport, // 00000003
31+
}
2732
`;
2833
const newSnapshot = `
2934
import * as React from 'react';
30-
export declare type AccessibilityActionEvent = NativeSyntheticEvent<
35+
declare type AccessibilityActionEvent = NativeSyntheticEvent<
3136
Readonly<{
3237
actionName: string;
3338
}>
3439
>;
35-
export declare const AccessibilityInfo: typeof AccessibilityInfo_2;
40+
declare const AccessibilityInfo: typeof AccessibilityInfo_2;
41+
export {
42+
AccessibilityActionEvent, // 00000001
43+
AccessibilityInfo, // 00000002
44+
}
3645
`;
3746

3847
const res = diffApiSnapshot(prevSnapshot, newSnapshot);
@@ -48,7 +57,11 @@ describe('diffApiSnapshot', () => {
4857
actionName: string;
4958
}>
5059
>;
51-
export declare const AccessibilityInfo: typeof AccessibilityInfo_2;
60+
export declare const Foo: string;
61+
export {
62+
AccessibilityActionEvent, // 00000001
63+
Foo, // 00000002
64+
}
5265
`;
5366
const newSnapshot = `
5467
import * as React from 'react';
@@ -57,33 +70,46 @@ describe('diffApiSnapshot', () => {
5770
actionName: string;
5871
}>
5972
>;
60-
export declare const AccessibilityInfo: typeof AccessibilityInfo_3; // Changed from AccessibilityInfo_2 to AccessibilityInfo_3
73+
export declare const Foo: number;
74+
export {
75+
AccessibilityActionEvent, // 00000001
76+
Foo, // 00000003
77+
}
6178
`;
6279

6380
const res = diffApiSnapshot(prevSnapshot, newSnapshot);
6481
expect(res.result).toBe(Result.BREAKING);
65-
expect(res.changedApis).toEqual(['AccessibilityInfo']);
82+
expect(res.changedApis).toEqual(['Foo']);
6683
});
6784

6885
test('should detect potentially not breaking change when a statement is added', () => {
6986
const prevSnapshot = `
7087
import * as React from 'react';
71-
export declare type AccessibilityActionEvent = NativeSyntheticEvent<
88+
declare type AccessibilityActionEvent = NativeSyntheticEvent<
7289
Readonly<{
7390
actionName: string;
7491
}>
7592
>;
76-
export declare const AccessibilityInfo: typeof AccessibilityInfo_2;
93+
declare const AccessibilityInfo: typeof AccessibilityInfo_2;
94+
export {
95+
AccessibilityActionEvent, // 00000001
96+
AccessibilityInfo, // 00000002
97+
}
7798
`;
7899
const newSnapshot = `
79100
import * as React from 'react';
80-
export declare type AccessibilityActionEvent = NativeSyntheticEvent<
101+
declare type AccessibilityActionEvent = NativeSyntheticEvent<
81102
Readonly<{
82103
actionName: string;
83104
}>
84105
>;
85-
export declare const AccessibilityInfo: typeof AccessibilityInfo_2;
86-
export declare const NewExport: string; // New export added
106+
declare const AccessibilityInfo: typeof AccessibilityInfo_2;
107+
declare const NewExport: string; // New export added
108+
export {
109+
AccessibilityActionEvent, // 00000001
110+
AccessibilityInfo, // 00000002
111+
NewExport, // 00000003
112+
}
87113
`;
88114

89115
const res = diffApiSnapshot(prevSnapshot, newSnapshot);
@@ -94,85 +120,20 @@ describe('diffApiSnapshot', () => {
94120
test('should detect not breaking change when nothing is changed', () => {
95121
const prevSnapshot = `
96122
import * as React from 'react';
97-
export declare type AccessibilityActionEvent = NativeSyntheticEvent<
123+
declare type AccessibilityActionEvent = NativeSyntheticEvent<
98124
Readonly<{
99125
actionName: string;
100126
}>
101127
>;
102-
export declare const AccessibilityInfo: typeof AccessibilityInfo_2;
103-
`;
104-
105-
const res = diffApiSnapshot(prevSnapshot, prevSnapshot);
106-
expect(res.result).toBe(Result.NON_BREAKING);
107-
expect(res.changedApis).toEqual([]);
108-
});
109-
110-
test('should handle complex type declarations', () => {
111-
const prevSnapshot = `
112-
import * as React from 'react';
113-
export declare type ComplexType = {
114-
prop1: string;
115-
prop2: number;
116-
prop3: {
117-
nestedProp1: boolean;
118-
nestedProp2: Array<string>;
119-
};
120-
};
121-
`;
122-
const newSnapshot = `
123-
import * as React from 'react';
124-
export declare type ComplexType = {
125-
prop1: string;
126-
prop2: number;
127-
prop3: {
128-
nestedProp1: boolean;
129-
nestedProp2: Array<string>;
130-
nestedProp3: number; // Added property
131-
};
132-
};
133-
`;
128+
declare const AccessibilityInfo: typeof AccessibilityInfo_2;
134129
135-
const res = diffApiSnapshot(prevSnapshot, newSnapshot);
136-
expect(res.result).toBe(Result.BREAKING);
137-
expect(res.changedApis).toEqual(['ComplexType']);
138-
});
139-
140-
test('should handle interface declarations', () => {
141-
const prevSnapshot = `
142-
import * as React from 'react';
143-
export interface TestInterface {
144-
method1(): void;
145-
property1: string;
130+
export {
131+
AccessibilityActionEvent, // 00000001
132+
AccessibilityInfo, // 00000002
146133
}
147134
`;
148-
const newSnapshot = `
149-
import * as React from 'react';
150-
export interface TestInterface {
151-
method1(): void;
152-
property1: string;
153-
method2(): number; // Added method
154-
}
155-
`;
156-
157-
const res = diffApiSnapshot(prevSnapshot, newSnapshot);
158-
expect(res.result).toBe(Result.BREAKING);
159-
expect(res.changedApis).toEqual(['TestInterface']);
160-
});
161-
162-
test('should handle const and type of the same name', () => {
163-
const prevSnapshot = `
164-
import * as React from 'react';
165-
export declare const AccessibilityInfo: typeof AccessibilityInfo_2;
166-
export declare type AccessibilityInfo = typeof AccessibilityInfo;
167-
`;
168135

169-
const newSnapshot = `
170-
import * as React from 'react';
171-
export declare type AccessibilityInfo = typeof AccessibilityInfo;
172-
export declare const AccessibilityInfo: typeof AccessibilityInfo_2;
173-
`;
174-
175-
const res = diffApiSnapshot(prevSnapshot, newSnapshot);
136+
const res = diffApiSnapshot(prevSnapshot, prevSnapshot);
176137
expect(res.result).toBe(Result.NON_BREAKING);
177138
expect(res.changedApis).toEqual([]);
178139
});

0 commit comments

Comments
 (0)