Skip to content

Commit

Permalink
Merge pull request #38570 from VickyStash/ts-migration/g28-files
Browse files Browse the repository at this point in the history
[No QA] [TS migration] Migrate remaining Mock and Script files to TypeScript
  • Loading branch information
madmax330 authored Mar 25, 2024
2 parents 5817c99 + 45bdd47 commit 9f56f02
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
3 changes: 0 additions & 3 deletions __mocks__/@react-native-clipboard/clipboard.js

This file was deleted.

3 changes: 3 additions & 0 deletions __mocks__/@react-native-clipboard/clipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import clipboardMock from '@react-native-clipboard/clipboard/jest/clipboard-mock';

export default clipboardMock;
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
export default {
getConstants: jest.fn(),
import type {pick, pickDirectory, releaseSecureAccess, types} from 'react-native-document-picker';

type ReactNativeDocumentPickerMock = {
pick: typeof pick;
releaseSecureAccess: typeof releaseSecureAccess;
pickDirectory: typeof pickDirectory;
types: typeof types;
};

const reactNativeDocumentPickerMock: ReactNativeDocumentPickerMock = {
pick: jest.fn(),
releaseSecureAccess: jest.fn(),
pickDirectory: jest.fn(),

types: Object.freeze({
allFiles: 'public.item',
audio: 'public.audio',
Expand All @@ -21,3 +28,5 @@ export default {
zip: 'public.zip-archive',
}),
};

export default reactNativeDocumentPickerMock;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"analyze-packages": "ANALYZE_BUNDLE=true webpack --config config/webpack/webpack.common.js --env envFile=.env.production",
"symbolicate:android": "npx metro-symbolicate android/app/build/generated/sourcemaps/react/release/index.android.bundle.map",
"symbolicate:ios": "npx metro-symbolicate main.jsbundle.map",
"symbolicate-release:ios": "scripts/release-profile.js --platform=ios",
"symbolicate-release:android": "scripts/release-profile.js --platform=android",
"symbolicate-release:ios": "scripts/release-profile.ts --platform=ios",
"symbolicate-release:android": "scripts/release-profile.ts --platform=android",
"test:e2e": "ts-node tests/e2e/testRunner.ts --config ./config.local.ts",
"test:e2e:dev": "ts-node tests/e2e/testRunner.ts --config ./config.dev.ts",
"gh-actions-unused-styles": "./.github/scripts/findUnusedKeys.sh",
Expand Down
20 changes: 12 additions & 8 deletions scripts/release-profile.js → scripts/release-profile.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env node
#!/usr/bin/env ts-node

/* eslint-disable no-console */
import {execSync} from 'child_process';
import fs from 'fs';

const fs = require('fs');
const {execSync} = require('child_process');
type ArgsMap = Record<string, string>;

// Function to parse command-line arguments into a key-value object
function parseCommandLineArguments() {
function parseCommandLineArguments(): ArgsMap {
const args = process.argv.slice(2); // Skip node and script paths
const argsMap = {};
const argsMap: ArgsMap = {};
args.forEach((arg) => {
const [key, value] = arg.split('=');
if (key.startsWith('--')) {
Expand All @@ -20,14 +22,13 @@ function parseCommandLineArguments() {
// Function to find .cpuprofile files in the current directory
function findCpuProfileFiles() {
const files = fs.readdirSync(process.cwd());
// eslint-disable-next-line rulesdir/prefer-underscore-method
return files.filter((file) => file.endsWith('.cpuprofile'));
}

const argsMap = parseCommandLineArguments();

// Determine sourcemapPath based on the platform flag passed
let sourcemapPath;
let sourcemapPath: string | undefined;
if (argsMap.platform === 'ios') {
sourcemapPath = 'main.jsbundle.map';
} else if (argsMap.platform === 'android') {
Expand Down Expand Up @@ -57,7 +58,10 @@ if (cpuProfiles.length === 0) {
const output = execSync(command, {stdio: 'inherit'});
console.log(output.toString());
} catch (error) {
console.error(`Error executing command: ${error}`);
if (error instanceof Error) {
console.error(`Error executing command: ${error.toString()}`);
}

process.exit(1);
}
}
19 changes: 5 additions & 14 deletions src/types/modules/react-native-clipboard.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
declare module '@react-native-clipboard/clipboard/jest/clipboard-mock' {
const mockClipboard: {
getString: jest.MockedFunction<() => Promise<string>>;
getImagePNG: jest.MockedFunction<() => void>;
getImageJPG: jest.MockedFunction<() => void>;
setImage: jest.MockedFunction<() => void>;
setString: jest.MockedFunction<() => void>;
hasString: jest.MockedFunction<() => Promise<boolean>>;
hasImage: jest.MockedFunction<() => Promise<boolean>>;
hasURL: jest.MockedFunction<() => Promise<boolean>>;
addListener: jest.MockedFunction<() => void>;
removeAllListeners: jest.MockedFunction<() => void>;
useClipboard: jest.MockedFunction<() => [string, jest.MockedFunction<() => void>]>;
};
export default mockClipboard;
import type Clipboard from '@react-native-clipboard/clipboard';

const clipboardMock: typeof Clipboard;

export default clipboardMock;
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
}
},
"exclude": ["**/node_modules/*", "**/dist/*", ".github/actions/**/index.js", "**/docs/*"],
"include": ["src", "desktop", "web", "website", "docs", "assets", "config", "tests", "jest", "__mocks__", ".github/**/*", ".storybook/**/*", "workflow_tests"],
"include": ["src", "desktop", "web", "website", "docs", "assets", "config", "tests", "jest", "__mocks__", ".github/**/*", ".storybook/**/*", "workflow_tests", "scripts"],
"extends": "expo/tsconfig.base"
}

0 comments on commit 9f56f02

Please sign in to comment.