Skip to content

Commit

Permalink
135 cicd jest integration step 1 (#145)
Browse files Browse the repository at this point in the history
* 🗑️chore: install vitest, but wtf

* 🗑️chore: install jst, BUT WTF

* 🗑️chore: install jst II

* 🗑️chore: init of api testing

* Setup Jest testing for expo

* Move cn to utils folder

* 🗑️chore: 1.5 api tested PASSED

* 🧙‍♀️api: users, excersize done

* add unit tests for notif APIs

* Add react testing library and fix jest config

* Fix jest config to allow ts custom paths

* 🚽api: sptofiy stuf

* 🐛fix: sync sync syc2

* Fix expo vector icons import

* unit tests for gcNotifs and RotatingBarbellIcon

* Add MessageInput and TimeAgo unit tests

* 🐛fix: sync sync sync33

* ✨feature: api testing done

* ✨feature: acionaction

* ✨feature: action action

* Add unit tests for toggle component and privacy policy page

* ✨feature: action 2

* ✨feature: action 3

* ✨feature: action 4

* ✨feature: action 5

* ✨feature: WE COOKED

* ✨feature: forgor we seed

* ✨feature: forgor we seed 2

* ✨feature: forgor we seed 3

* ✨feature: forgor we seed 4

* ✨feature: forgor we seed 5

* ✨feature: forgor we seed 6

* ✨feature: forgor we seed 7

* ✨feature: forgor we seed 8

---------

Co-authored-by: Marcos Villanueva <mva919@gmail.com>
Co-authored-by: Taylor Finelli <taylorfinelli@Taylors-MacBook-Pro.local>
  • Loading branch information
3 people authored Mar 27, 2024
1 parent 71931ef commit 68b6720
Show file tree
Hide file tree
Showing 46 changed files with 4,216 additions and 1,276 deletions.
45 changes: 44 additions & 1 deletion .github/workflows/cov.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
name: Workflow for Codecov

on: [push, pull_request]

jobs:
run:
runs-on: ubuntu-latest
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
DIRECT_URL: ${{ secrets.DIRECT_URL }}
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up pnpm
uses: pnpm/action-setup@v2
with:
version: 8.x

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 18.x
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'

- name: Install root dependencies
run: pnpm install --no-frozen-lockfile

- name: Install dependencies and setup Prisma
run: |
cd packages/db && pnpm prisma generate && pnpm dotenv -e ../../.env prisma db push
working-directory: .

- name: Run tests and collect coverage
run: |
pnpm run jest
env:
CI: true

- name: Run tests in expo
run: |
cd apps/expo && pnpm run test
working-directory: .
env:
CI: true

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: UNLV-CS472-672/2024-S-GROUP3-Barbell
slug: UNLV-CS472-672/2024-S-GROUP3-Barbell
directory: ./coverage/
fail_ci_if_error: true
44 changes: 44 additions & 0 deletions apps/expo/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type {Config} from 'jest';

const config: Config = {
setupFilesAfterEnv: ['<rootDir>/setup-jest.js'],
collectCoverageFrom: [
'**/*.{ts,tsx}',
'!**/node_modules/**',
'!**/vendor/**',
'!**/app.config.ts',
'!**/babel.config.ts',
'!**/tailwind.config.ts',
'!**/jest.config.ts',
'!**/.expo/**',
'!**/*.d.ts',
'!index.ts',
'!**/api.tsx',
// need to remove in future v
'!**/app/**',
'!**/custom-bottom-sheet-modal.tsx',
'!**/auth/**',
"!**/notif/**",
'!**/hooks/**',
'!**/context/**',
],
// coverageThreshold: {
// global: {
// branches: 80,
// functions: 80,
// lines: 80,
// statements: -10,
// },
// },
// preset: 'ts-jest',
// transform: {
// '^.+\\.(ts|tsx)?$': 'ts-jest',
// '^.+\\.(js|jsx)$': 'babel-jest',
// }
preset: 'jest-expo',
moduleNameMapper: {
"~/(.*)": "<rootDir>/src/$1"
},
};

export default config;
11 changes: 10 additions & 1 deletion apps/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"format": "prettier --check . --ignore-path ../../.gitignore",
"typecheck": "tsc --noEmit",
"android": "expo run:android",
"ios": "expo run:ios"
"ios": "expo run:ios",
"test": "jest --coverage"
},
"dependencies": {
"@clerk/clerk-expo": "^0.20.8",
Expand All @@ -37,6 +38,8 @@
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
"expo-updates": "~0.18.19",
"jest": "^29.2.1",
"jest-expo": "~49.0.0",
"nativewind": "^4.0.36",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand All @@ -59,14 +62,20 @@
"@acme/tsconfig": "workspace:^",
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"@babel/preset-typescript": "^7.24.1",
"@babel/runtime": "^7.23.9",
"@expo/config-plugins": "^7.2.5",
"@testing-library/react-native": "^12.4.4",
"@types/babel__core": "^7.20.5",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.42",
"@types/react-test-renderer": "^18.0.7",
"babel-jest": "^29.7.0",
"eslint": "^8.53.0",
"prettier": "^3.1.0",
"react-devtools-core": "^5.0.0",
"tailwindcss": "3.3.5",
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
},
"eslintConfig": {
Expand Down
1 change: 1 addition & 0 deletions apps/expo/setup-jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/react-native/extend-expect';
25 changes: 25 additions & 0 deletions apps/expo/src/app/__snapshots__/privacy-policy.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Privacy Policy Page 1`] = `
<RNCSafeAreaView
edges={
{
"bottom": "additive",
"left": "additive",
"right": "additive",
"top": "additive",
}
}
>
<Text
style={
{
"padding": 30,
"textAlign": "center",
}
}
>
PrivacyPolicy!
</Text>
</RNCSafeAreaView>
`;
8 changes: 8 additions & 0 deletions apps/expo/src/app/privacy-policy.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render, screen } from '@testing-library/react-native'

import PrivacyPolicy from './privacy-policy'

test('Privacy Policy Page', () => {
render(<PrivacyPolicy />)
expect(screen.toJSON()).toMatchSnapshot()
})
11 changes: 0 additions & 11 deletions apps/expo/src/components/forgotten/foo.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MessageInput 1`] = `
<View
onLayout={[Function]}
style={
{
"flex": 1,
"paddingBottom": 10,
}
}
>
<View
style={
{
"flex": 1,
"justifyContent": "flex-end",
}
}
>
<View
style={
{
"alignItems": "center",
"flexDirection": "row",
"paddingHorizontal": 10,
}
}
>
<TextInput
keyboardAppearance="dark"
placeholder="Message..."
placeholderTextColor="#CACACA"
style={
{
"borderColor": "#272727",
"borderRadius": 20,
"borderWidth": 1,
"color": "white",
"flex": 1,
"padding": 10,
}
}
/>
<View
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
{
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={false}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
{
"opacity": 1,
}
}
>
<View
style={
{
"backgroundColor": "#48476D",
"borderRadius": 20,
"marginLeft": 10,
"padding": 10,
}
}
>
<Text />
</View>
</View>
</View>
</View>
</View>
`;
8 changes: 8 additions & 0 deletions apps/expo/src/components/message/messageInput.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render, screen } from '@testing-library/react-native'

import MessageInput from './messageInput'

test('MessageInput', async () => {
render(<MessageInput />)
expect(screen.toJSON()).toMatchSnapshot()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import { render, screen } from '@testing-library/react-native'
import RotatingBarbellIcon from '../dmNotifs/RotatingBarbellIcon'

test('RotatingBarbellIcon', async () => {
render(<RotatingBarbellIcon />)

expect(screen.toJSON()).toMatchSnapshot()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RotatingBarbellIcon 1`] = `
<View
style={
{
"alignItems": "center",
"justifyContent": "center",
"paddingTop": 20,
}
}
>
<View
collapsable={false}
style={
{
"transform": [
{
"rotate": "0deg",
},
],
}
}
>
<Text />
</View>
</View>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RotatingBarbellIcon 1`] = `<View />`;
9 changes: 9 additions & 0 deletions apps/expo/src/components/notif/__tests__/gcNotifs.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import { render, screen } from '@testing-library/react-native'
import GcNotifs from '../gcNotifs'

test('RotatingBarbellIcon', async () => {
render(<GcNotifs />)

expect(screen.toJSON()).toMatchSnapshot()
})
18 changes: 18 additions & 0 deletions apps/expo/src/components/timeAgo/TimeAgo.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { render, screen } from '@testing-library/react-native'
import TimeAgo from './TimeAgo'

// Adjust the timeout for this test
test('TimeAgo', async () => {
const expectedCreatedAt = new Date('2021-01-01T00:00:00Z') // Corrected date string
const expectedTimeAgo = '168 weeks ago'

render(<TimeAgo createdAt={expectedCreatedAt} />)
const timeAgoOutput = await screen.findByTestId('timeAgoText')

expect(timeAgoOutput).toHaveTextContent(expectedTimeAgo)
expect(screen.toJSON()).toMatchSnapshot()

// The part below seems to be intended for testing bad date handling.
// Ensure that your TimeAgo component and calculateTimeAgo function are designed to handle and test such cases correctly.
// It's also not clear from the provided code how 'timeAgoBadDate' is set since the 'calculateTimeAgo' handling of bad dates is not shown.
}, 10000); // Increase the timeout for this test
Loading

0 comments on commit 68b6720

Please sign in to comment.