/
githubmirror
/
react-native
Обзор
Документация
Войти
/
githubmirror
/
react-native
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
scripts/js-api/diff-api-snapshot/__tests__/diffApiSnapshot-test.js
140 строк
4 KB
Alex Hunt
Fix diffApiSnapshot-test (#54903)
16 дек 2025, 21:04
16 дек 2025, 21:04
0c947c8
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow * @format * @oncall react_native */ 'use strict'; const {Result, diffApiSnapshot} = require('../diffApiSnapshot'); describe('diffApiSnapshot', () => { test('should detect breaking change when a statement is deleted', () => { const prevSnapshot = ` import * as React from 'react'; declare type AccessibilityActionEvent = NativeSyntheticEvent< Readonly<{ actionName: string; }> >; declare const AccessibilityInfo: typeof AccessibilityInfo_2; declare const DeletedExport: string; export { AccessibilityActionEvent, // 00000001 AccessibilityInfo, // 00000002 DeletedExport, // 00000003 } `; const newSnapshot = ` import * as React from 'react'; declare type AccessibilityActionEvent = NativeSyntheticEvent< Readonly<{ actionName: string; }> >; declare const AccessibilityInfo: typeof AccessibilityInfo_2; export { AccessibilityActionEvent, // 00000001 AccessibilityInfo, // 00000002 } `; const res = diffApiSnapshot(prevSnapshot, newSnapshot); expect(res.result).toBe(Result.BREAKING); expect(res.changedApis).toEqual(['DeletedExport']); }); test('should detect potentially breaking change when a statement is changed', () => { const prevSnapshot = ` import * as React from 'react'; export declare type AccessibilityActionEvent = NativeSyntheticEvent< Readonly<{ actionName: string; }> >; export declare const Foo: string; export { AccessibilityActionEvent, // 00000001 Foo, // 00000002 } `; const newSnapshot = ` import * as React from 'react'; export declare type AccessibilityActionEvent = NativeSyntheticEvent< Readonly<{ actionName: string; }> >; export declare const Foo: number; export { AccessibilityActionEvent, // 00000001 Foo, // 00000003 } `; const res = diffApiSnapshot(prevSnapshot, newSnapshot); expect(res.result).toBe(Result.POTENTIALLY_BREAKING); expect(res.changedApis).toEqual(['Foo']); }); test('should detect potentially non-breaking change when a statement is added', () => { const prevSnapshot = ` import * as React from 'react'; declare type AccessibilityActionEvent = NativeSyntheticEvent< Readonly<{ actionName: string; }> >; declare const AccessibilityInfo: typeof AccessibilityInfo_2; export { AccessibilityActionEvent, // 00000001 AccessibilityInfo, // 00000002 } `; const newSnapshot = ` import * as React from 'react'; declare type AccessibilityActionEvent = NativeSyntheticEvent< Readonly<{ actionName: string; }> >; declare const AccessibilityInfo: typeof AccessibilityInfo_2; declare const NewExport: string; // New export added export { AccessibilityActionEvent, // 00000001 AccessibilityInfo, // 00000002 NewExport, // 00000003 } `; const res = diffApiSnapshot(prevSnapshot, newSnapshot); expect(res.result).toBe(Result.POTENTIALLY_NON_BREAKING); expect(res.changedApis).toEqual(['NewExport']); }); test('should detect non-breaking change when nothing is changed', () => { const prevSnapshot = ` import * as React from 'react'; declare type AccessibilityActionEvent = NativeSyntheticEvent< Readonly<{ actionName: string; }> >; declare const AccessibilityInfo: typeof AccessibilityInfo_2; export { AccessibilityActionEvent, // 00000001 AccessibilityInfo, // 00000002 } `; const res = diffApiSnapshot(prevSnapshot, prevSnapshot); expect(res.result).toBe(Result.NON_BREAKING); expect(res.changedApis).toEqual([]); }); });