Skip to content

Commit

Permalink
chore: Enable typescript coverage for all the files (#10745)
Browse files Browse the repository at this point in the history
## **Description**

This PR enables the TS coverage for the mobile app. From now on all the
TS issues will be spotted.

* Ignore termsOfUseContent.ts diff since it's generated on the CI

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
tommasini authored Aug 27, 2024
1 parent 5b65086 commit 46c4c43
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ module.exports = {
radix: 0,
},

ignorePatterns: ['wdio.conf.js', 'app/util/termsOfUse/termsOfUseContent.js'],
ignorePatterns: ['wdio.conf.js', 'app/util/termsOfUse/termsOfUseContent.ts'],
};
108 changes: 108 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,31 @@ jobs:
- name: Require clean working directory
shell: bash
run: |
# Read the file into an array using mapfile
mapfile -t EXCLUDES < git-diff-exclusions.txt
# Apply git update-index --assume-unchanged to each entry
echo "Assuming unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --assume-unchanged "$path"
done
# Run git diff
echo "Running git diff command:"
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
else
echo "No changes detected"
fi
# Revert git update-index --no-assume-unchanged for each entry
echo "Reverting assume unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --no-assume-unchanged "$path"
done
dedupe:
runs-on: ubuntu-20.04
needs: setup
Expand Down Expand Up @@ -73,10 +94,31 @@ jobs:
- name: Require clean working directory
shell: bash
run: |
# Read the file into an array using mapfile
mapfile -t EXCLUDES < git-diff-exclusions.txt
# Apply git update-index --assume-unchanged to each entry
echo "Assuming unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --assume-unchanged "$path"
done
# Run git diff
echo "Running git diff command:"
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
else
echo "No changes detected"
fi
# Revert git update-index --no-assume-unchanged for each entry
echo "Reverting assume unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --no-assume-unchanged "$path"
done
unit-tests:
runs-on: ubuntu-20.04
needs: setup
Expand Down Expand Up @@ -107,10 +149,31 @@ jobs:
- name: Require clean working directory
shell: bash
run: |
# Read the file into an array using mapfile
mapfile -t EXCLUDES < git-diff-exclusions.txt
# Apply git update-index --assume-unchanged to each entry
echo "Assuming unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --assume-unchanged "$path"
done
# Run git diff
echo "Running git diff command:"
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
else
echo "No changes detected"
fi
# Revert git update-index --no-assume-unchanged for each entry
echo "Reverting assume unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --no-assume-unchanged "$path"
done
merge-unit-tests:
runs-on: ubuntu-20.04
needs: unit-tests
Expand Down Expand Up @@ -138,17 +201,41 @@ jobs:
- name: Require clean working directory
shell: bash
run: |
# Read the file into an array using mapfile
mapfile -t EXCLUDES < git-diff-exclusions.txt
# Apply git update-index --assume-unchanged to each entry
echo "Assuming unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --assume-unchanged "$path"
done
# Run git diff
echo "Running git diff command:"
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
else
echo "No changes detected"
fi
# Revert git update-index --no-assume-unchanged for each entry
echo "Reverting assume unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --no-assume-unchanged "$path"
done
sonar-cloud:
runs-on: ubuntu-20.04
needs: merge-unit-tests
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # SonarCloud needs a full checkout to perform necessary analysis
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- uses: actions/download-artifact@v3
with:
name: coverage
Expand All @@ -166,10 +253,31 @@ jobs:
- name: Require clean working directory
shell: bash
run: |
# Read the file into an array using mapfile
mapfile -t EXCLUDES < git-diff-exclusions.txt
# Apply git update-index --assume-unchanged to each entry
echo "Assuming unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --assume-unchanged "$path"
done
# Run git diff
echo "Running git diff command:"
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
else
echo "No changes detected"
fi
# Revert git update-index --no-assume-unchanged for each entry
echo "Reverting assume unchanged for the following paths:"
for path in "${EXCLUDES[@]}"; do
echo "$path"
git update-index --no-assume-unchanged "$path"
done
check-workflows:
name: Check workflows
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ ccache
html-report/

# terms of use
app/util/termsOfUse/termsOfUseContent.js
app/util/termsOfUse/termsOfUseContent.ts
docs/assets/termsOfUse.html
6 changes: 3 additions & 3 deletions app/components/UI/AssetOverview/TokenDetails/TokenDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export interface TokenDetails {

export interface MarketDetails {
marketCap: string | null;
totalVolume: number | null;
totalVolume: string | null;
volumeToMarketCap: string | null;
circulatingSupply: number | null;
circulatingSupply: string | null;
allTimeHigh: string | null;
allTimeLow: string | null;
fullyDiluted: number | null;
fullyDiluted: string | null;
}

interface TokenDetailsProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('NotificationIcon', () => {
it('matches snapshot when icon is provided', () => {
const { toJSON } = renderWithProvider(
<NotificationIcon
image={{ url: walletNotification.imageUrl }}
image={{ url: walletNotification.imageUrl.name }}
badgeIcon={walletNotification.badgeIcon}
/>,
{ state: mockInitialState },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports[`NotificationIcon matches snapshot when icon is provided 1`] = `
}
source={
{
"uri": "SvgMock",
"uri": "MockImage",
}
}
style={
Expand Down
6 changes: 5 additions & 1 deletion app/components/UI/ProfileSyncing/ProfileSyncing.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ const handleSwitchToggle = jest.fn();
describe('ProfileSyncing', () => {
it('should render correctly', () => {
const { toJSON } = renderWithProvider(
<ProfileSyncingComponent handleSwitchToggle={handleSwitchToggle} />,
<ProfileSyncingComponent
handleSwitchToggle={handleSwitchToggle}
isBasicFunctionalityEnabled={false}
isProfileSyncingEnabled={false}
/>,
);
expect(toJSON()).toMatchSnapshot();
});
Expand Down
3 changes: 2 additions & 1 deletion app/components/Views/ImportPrivateKey/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Text,
View,
ActivityIndicator,
DimensionValue,
} from 'react-native';
import { useNavigation } from '@react-navigation/native';
import StyledButton from '../../UI/StyledButton';
Expand All @@ -26,7 +27,7 @@ import { ImportAccountFromPrivateKeySelectorsIDs } from '../../../../e2e/selecto
const ImportPrivateKey = () => {
const [privateKey, setPrivateKey] = useState('');
const [loading, setLoading] = useState(false);
const [inputWidth, setInputWidth] = useState(
const [inputWidth, setInputWidth] = useState<DimensionValue | undefined>(
Device.isAndroid() ? '99%' : undefined,
);
const navigation = useNavigation();
Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/NetworkSelector/NetworkSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ const NetworkSelector = () => {
networkName: string,
) => {
const searchResult: ExtendedNetwork[] = networks.filter(({ name }) =>
name.toLowerCase().includes(networkName.toLowerCase()),
name?.toLowerCase().includes(networkName.toLowerCase()),
);

return searchResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('SDKSessionItem', () => {
icon: 'http://icon-url.com',
platform: 'test',
connected: true,
dappId: '123',
},
},
trigger: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface Network {
}

export interface ExtendedNetwork extends Network {
name: string;
name?: string;
formattedRpcUrl?: string | null;
}

Expand Down
6 changes: 3 additions & 3 deletions app/components/hooks/useAccounts/useAccounts.types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Third party dependencies.
import { KeyringTypes } from '@metamask/keyring-controller';
import { Hex } from '@metamask/utils';

// External dependencies.
import { AvatarGroupToken } from '../../../component-library/components/Avatars/AvatarGroup/AvatarGroup.types';
import { Hex } from '@metamask/utils';
import { AvatarTokenProps } from '../../../component-library/components/Avatars/Avatar/variants/AvatarToken/AvatarToken.types';

/**
* Asset information associated with the account, which includes both the fiat balance and owned tokens.
Expand All @@ -16,7 +16,7 @@ export interface Assets {
/**
* Tokens owned by this account.
*/
tokens?: AvatarGroupToken[];
tokens?: AvatarTokenProps[];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/declarations/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ declare module '@metamask/contract-metadata' {
export default content;
}

declare module './util/termsOfUse/termsOfUseContent' {
declare module './util/termsOfUse/termsOfUseContent.ts' {
const content: string;
export default content;
}
Expand Down
1 change: 1 addition & 0 deletions app/util/termsOfUse/termsOfUseContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default '';
1 change: 1 addition & 0 deletions git-diff-exclusions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/util/termsOfUse/termsOfUseContent.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"clean-android": "yarn clean:android && yarn clean:node",
"lint": "eslint '**/*.{js,ts,tsx}'",
"lint:fix": "eslint '**/*.{js,ts,tsx}' --fix",
"lint:tsc": "tsc --project ./tsconfig.lint.json",
"lint:tsc": "tsc --project ./tsconfig.json",
"format": "prettier '**/*.{js,ts,tsx,json,feature}' --write",
"setup": "yarn clean && node scripts/setup.mjs",
"setup:node": "yarn clean:node && yarn allow-scripts && yarn patch-package",
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const generateTermsOfUseContentTask = {
task: async () => {
const termsOfUsePath = path.resolve('./docs/assets/termsOfUse.html');
const outputDir = path.resolve('./app/util/termsOfUse');
const outputPath = path.join(outputDir, 'termsOfUseContent.js');
const outputPath = path.join(outputDir, 'termsOfUseContent.ts');

let termsOfUse = '';
try {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": [
"app/declarations/index.d.ts",
"app/**/*",
"node_modules/expect-webdriverio",
"node_modules/expect-webdriverio/jest",
"app/components/UI/QRHardware/AnimatedQRScanner.tsx"
"node_modules/expect-webdriverio/jest"
],
"exclude": [
"node_modules",
Expand Down
24 changes: 0 additions & 24 deletions tsconfig.lint.json

This file was deleted.

0 comments on commit 46c4c43

Please sign in to comment.