Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflow-scripts/__tests__/publishTemplate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
* @format
*/

const {
publishTemplate,
verifyPublishedTemplate,
} = require('../publishTemplate');

const mockRun = jest.fn();
const mockSleep = jest.fn();
const mockGetNpmPackageInfo = jest.fn();
Expand All @@ -29,6 +24,11 @@ jest.mock('../verifyPublishedPackage.js', () => ({
verifyPublishedPackage: mockVerifyPublishedPackage,
}));

const {
publishTemplate,
verifyPublishedTemplate,
} = require('../publishTemplate');

const getMockGithub = () => ({
rest: {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* @format
*/

const {verifyArtifactsAreOnMaven} = require('../verifyArtifactsAreOnMaven');

const mockSleep = jest.fn();
const silence = () => {};
const mockFetch = jest.fn();
Expand All @@ -19,6 +17,8 @@ jest.mock('../utils.js', () => ({
sleep: mockSleep,
}));

const {verifyArtifactsAreOnMaven} = require('../verifyArtifactsAreOnMaven');

process.exit = mockExit;
global.fetch = mockFetch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* @format
*/

const {verifyPublishedPackage} = require('../verifyPublishedPackage');

const mockRun = jest.fn();
const mockSleep = jest.fn();
const mockGetNpmPackageInfo = jest.fn();
Expand All @@ -23,6 +21,8 @@ jest.mock('../utils.js', () => ({
getNpmPackageInfo: mockGetNpmPackageInfo,
}));

const {verifyPublishedPackage} = require('../verifyPublishedPackage');

describe('#verifyPublishedPackage', () => {
beforeEach(jest.clearAllMocks);

Expand Down
4 changes: 2 additions & 2 deletions .github/workflow-scripts/__tests__/verifyReleaseOnNpm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* @format
*/

const {verifyReleaseOnNpm} = require('../verifyReleaseOnNpm');

const mockVerifyPublishedPackage = jest.fn();
const silence = () => {};

Expand All @@ -21,6 +19,8 @@ jest.mock('../verifyPublishedPackage.js', () => ({
verifyPublishedPackage: mockVerifyPublishedPackage,
}));

const {verifyReleaseOnNpm} = require('../verifyReleaseOnNpm');

describe('#verifyReleaseOnNPM', () => {
beforeEach(jest.clearAllMocks);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,33 @@

'use-strict';

// The buildSchema tests spy on `getConfigType`, which parsers-commons reads when
// it loads, so it's wrapped before any module that uses it is required.
jest.mock('../utils', () => {
const actual = jest.requireActual<Utils>('../utils');
return {...actual, getConfigType: jest.fn(actual.getConfigType)};
});

import type {ParserType} from '../errors';
import typeof * as Utils from '../utils';

import {FlowParser} from '../flow/parser';
import {MockedParser} from '../parserMock';
import {
const {
IncorrectModuleRegistryCallArgumentTypeParserError,
IncorrectModuleRegistryCallArityParserError,
MisnamedModuleInterfaceParserError,
ModuleInterfaceNotFoundParserError,
MoreThanOneModuleInterfaceParserError,
MoreThanOneModuleRegistryCallsParserError,
ParserError,
UnsupportedObjectPropertyTypeAnnotationParserError,
UntypedModuleRegistryCallParserError,
UnusedModuleInterfaceParserError,
} = require('../errors');
const {buildComponentSchema} = require('../flow/components');
const {flowTranslateTypeAnnotation} = require('../flow/modules/index');
const {FlowParser} = require('../flow/parser');
const {MockedParser} = require('../parserMock');
const {
assertGenericTypeAnnotationHasExactlyOneTypeParameter,
buildSchema,
buildSchemaFromConfigType,
Expand All @@ -30,22 +52,7 @@ import {
propertyNames,
unwrapNullable,
wrapNullable,
} from '../parsers-commons';

const {
IncorrectModuleRegistryCallArgumentTypeParserError,
IncorrectModuleRegistryCallArityParserError,
MisnamedModuleInterfaceParserError,
ModuleInterfaceNotFoundParserError,
MoreThanOneModuleInterfaceParserError,
MoreThanOneModuleRegistryCallsParserError,
ParserError,
UnsupportedObjectPropertyTypeAnnotationParserError,
UntypedModuleRegistryCallParserError,
UnusedModuleInterfaceParserError,
} = require('../errors');
const {buildComponentSchema} = require('../flow/components');
const {flowTranslateTypeAnnotation} = require('../flow/modules/index');
} = require('../parsers-commons');
const {buildModuleSchema} = require('../parsers-commons.js');
const {Visitor} = require('../parsers-primitives');
const {wrapComponentSchema} = require('../schema.js');
Expand Down Expand Up @@ -665,7 +672,7 @@ describe('buildSchemaFromConfigType', () => {
});

describe('buildSchema', () => {
const getConfigTypeSpy = jest.spyOn(require('../utils'), 'getConfigType');
const getConfigTypeSpy = require('../utils').getConfigType;

describe('when there is no codegenNativeComponent and no TurboModule', () => {
const contents = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import * as React from 'react';

const {PlatformColor} = require('../../StyleSheet/PlatformColorValueTypes');
let Animated = require('../Animated').default;
const AnimatedProps = require('../nodes/AnimatedProps').default;
const {
let AnimatedProps = require('../nodes/AnimatedProps').default;
let {
create,
unmount,
update,
} = require('@react-native/jest-preset/jest/renderer');
const TestRenderer = require('react-test-renderer');
let TestRenderer = require('react-test-renderer');

// WORKAROUND: `jest.runAllTicks` skips tasks scheduled w/ `queueMicrotask`.
function mockQueueMicrotask() {
Expand All @@ -37,6 +37,16 @@ function mockQueueMicrotask() {
describe('Animated', () => {
beforeEach(() => {
jest.resetModules();
// Reload after the reset, so that Animated and the renderer share a copy
// of React.
Animated = require('../Animated').default;
AnimatedProps = require('../nodes/AnimatedProps').default;
({
create,
unmount,
update,
} = require('@react-native/jest-preset/jest/renderer'));
TestRenderer = require('react-test-renderer');
});

mockQueueMicrotask();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@

'use strict';

const BackHandler: $FlowFixMe = require('../../Utilities/BackHandler').default;
const LogBoxData = require('../Data/LogBoxData');
const LogBoxLog = require('../Data/LogBoxLog').default;
const {
_LogBoxInspectorContainer: LogBoxInspectorContainer,
} = require('../LogBoxInspectorContainer');
const render = require('@react-native/jest-preset/jest/renderer');
const React = require('react');

// Mock `LogBoxInspector` because we are interested in snapshotting the behavior
// of `LogBoxInspectorContainer`, not `LogBoxInspector`.
jest.mock('../UI/LogBoxInspector', () => ({
Expand All @@ -30,6 +21,15 @@ jest.mock('../../Utilities/BackHandler', () =>
require('../../Utilities/__mocks__/BackHandler'),
);

const BackHandler: $FlowFixMe = require('../../Utilities/BackHandler').default;
const LogBoxData = require('../Data/LogBoxData');
const LogBoxLog = require('../Data/LogBoxLog').default;
const {
_LogBoxInspectorContainer: LogBoxInspectorContainer,
} = require('../LogBoxInspectorContainer');
const render = require('@react-native/jest-preset/jest/renderer');
const React = require('react');

describe('LogBoxInspectorContainer', () => {
let output;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@

'use strict';

const BackHandler: $FlowFixMe = require('../../Utilities/BackHandler').default;
const LogBoxData = require('../Data/LogBoxData');
const LogBoxLog = require('../Data/LogBoxLog').default;
const {LogBoxNotificationContainer} = require('../LogBoxNotificationContainer');
const render = require('@react-native/jest-preset/jest/renderer');
const React = require('react');

// Mock `LogBoxLogNotification` because we are interested in snapshotting the
// behavior of `LogBoxNotificationContainer`, not `LogBoxLogNotification`.
jest.mock('../UI/LogBoxNotification', () => ({
Expand All @@ -28,6 +21,13 @@ jest.mock('../../Utilities/BackHandler', () =>
require('../../Utilities/__mocks__/BackHandler'),
);

const BackHandler: $FlowFixMe = require('../../Utilities/BackHandler').default;
const LogBoxData = require('../Data/LogBoxData');
const LogBoxLog = require('../Data/LogBoxLog').default;
const {LogBoxNotificationContainer} = require('../LogBoxNotificationContainer');
const render = require('@react-native/jest-preset/jest/renderer');
const React = require('react');

describe('LogBoxNotificationContainer', () => {
let output;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@

'use strict';

// headers-xcframework reads `execFileSync` when it loads, so it's mocked before
// the module is required.
const mockExecFileSync = jest.fn();
jest.mock('node:child_process', () => ({
...jest.requireActual('node:child_process'),
execFileSync: mockExecFileSync,
}));

const {
buildDepsHeadersXcframework,
stubSlicesFromXcframework,
} = require('../headers-xcframework');
const childProcess = require('node:child_process');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
Expand Down Expand Up @@ -67,9 +74,9 @@ describe('stubSlicesFromXcframework', () => {
// SupportedPlatform/Variant -> key mapping and the unknown-slice guard can be
// tested without a real xcframework or macOS tooling.
const mockPlist = (obj /*: unknown */) =>
jest
.spyOn(childProcess, 'execFileSync')
.mockReturnValue(Buffer.from(JSON.stringify(obj) ?? '', 'utf8'));
mockExecFileSync.mockReturnValue(
Buffer.from(JSON.stringify(obj) ?? '', 'utf8'),
);

afterEach(() => {
jest.restoreAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

'use strict';

// Mock all required modules
jest.mock('../utils');
jest.mock('../headers-mappings');
jest.mock('node:fs');
jest.mock('node:path');

const {
symlinkCodegenHeaders,
symlinkHeadersFromPath,
Expand All @@ -18,12 +24,6 @@ const {
symlinkThirdPartyDependenciesHeaders,
} = require('../headers-utils');

// Mock all required modules
jest.mock('../utils');
jest.mock('../headers-mappings');
jest.mock('node:fs');
jest.mock('node:path');

describe('symlinkHeadersFromPath', () => {
let mockUtils;
let mockFs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@

'use strict';

const {
configureAppForSwift,
createHardlinks,
findXcodeProjectDirectory,
generateCodegenArtifacts,
prepareHeaders,
runIosPrebuild,
runPodDeintegrate,
setBuildFromSource,
} = require('../prepare-app-utils');

// Mock child_process module
jest.mock('node:child_process');

Expand All @@ -33,8 +22,11 @@ jest.mock('../headers-utils');
// Mock prepare-app-dependencies-headers module
jest.mock('../prepare-app-dependencies-headers');

// Mock codegen executor module
jest.mock('../../codegen/generate-artifacts-executor');
// Mock codegen executor module. Automocking loads the real module, which reads
// package.json through the mocked `fs`.
jest.mock('../../codegen/generate-artifacts-executor', () => ({
execute: jest.fn(),
}));

// Mock path module for absolute paths
jest.mock('node:path', () => {
Expand All @@ -46,6 +38,17 @@ jest.mock('node:path', () => {
};
});

const {
configureAppForSwift,
createHardlinks,
findXcodeProjectDirectory,
generateCodegenArtifacts,
prepareHeaders,
runIosPrebuild,
runPodDeintegrate,
setBuildFromSource,
} = require('../prepare-app-utils');

describe('createHardlinks', () => {
let mockSymlinkReactNativeHeaders;
let mockSymlinkThirdPartyDependenciesHeaders;
Expand Down
8 changes: 7 additions & 1 deletion scripts/releases-ci/__tests__/publish-npm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ const getPackagesMock = jest.fn();
const updateHermesVersionsToPrebuiltMock = jest.fn();
const getBranchName = jest.fn();

import type {BuildType} from '../../releases/utils/version-utils';

const {REPO_ROOT} = require('../../shared/consts');
const {publishNpm} = require('../publish-npm');
const path = require('node:path');

// Required on each call, so that publish-npm picks up the mocks and module
// registry that each test sets up after this file loads.
const publishNpm = (buildType: BuildType): Promise<void> =>
require('../publish-npm').publishNpm(buildType);

let consoleLog;

describe('publish-npm', () => {
Expand Down
10 changes: 5 additions & 5 deletions scripts/releases-ci/__tests__/publish-updated-packages-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
* @format
*/

const {
getTagsFromCommitMessage,
publishUpdatedPackages,
} = require('../publish-updated-packages');

const getPackagesMock = jest.fn();
const execSync = jest.fn();
const execMock = jest.fn();
Expand All @@ -23,6 +18,11 @@ jest.mock('shelljs', () => ({exec: execMock}));
jest.mock('../../shared/monorepoUtils', () => ({
getPackages: getPackagesMock,
}));

const {
getTagsFromCommitMessage,
publishUpdatedPackages,
} = require('../publish-updated-packages');
// $FlowFixMe[cannot-write]
global.fetch = fetchMock;

Expand Down
Loading
Loading