diff --git a/.github/workflows/gluestack-expo-app.yml b/.github/workflows/gluestack-expo-app.yml index 4e2bfb3..b48dc9a 100644 --- a/.github/workflows/gluestack-expo-app.yml +++ b/.github/workflows/gluestack-expo-app.yml @@ -30,13 +30,8 @@ jobs: working-directory: ${{ env.working-directory }} run: | yarn web --port 19006 & - echo $! > expo_pid.txt sleep 60 # Wait for Expo to start - name: Run tests working-directory: ${{ env.working-directory }} run: yarn test - - - name: Kill Expo server - run: | - kill $(cat expo_pid.txt) diff --git a/.github/workflows/universal-gluestack-app.yml b/.github/workflows/universal-gluestack-app.yml index 1369a21..d16e927 100644 --- a/.github/workflows/universal-gluestack-app.yml +++ b/.github/workflows/universal-gluestack-app.yml @@ -25,21 +25,10 @@ jobs: - name: Install dependencies run: yarn + - name: Install dependencies for Next app + working-directory: ${{ env.working-directory }}/apps/next + run: yarn + - name: Build Next working-directory: ${{ env.working-directory }} run: yarn build:next - - - name: Start Expo on port 19007 - working-directory: ${{ env.working-directory }} - run: | - cd apps/expo-app && yarn start:web --port 19007 & - echo $! > expo_pid.txt - sleep 60 # Wait for Expo to start - - - name: Run tests - working-directory: ${{ env.working-directory }} - run: yarn test - - - name: Kill Expo server - run: | - kill $(cat expo_pid.txt) diff --git a/universal/apps/expo-app/__tests__/expo-app.test.js b/universal/apps/expo-app/__tests__/expo-app.test.js new file mode 100644 index 0000000..d76b8b7 --- /dev/null +++ b/universal/apps/expo-app/__tests__/expo-app.test.js @@ -0,0 +1,10 @@ +import React from "react"; +import { render, screen } from "@testing-library/react-native"; +import App from "../app/index"; + +test("renders correctly", () => { + render(); + + // Check if a specific text or element is present in the component + expect(screen.getByText("SplashScreen")).toBeTruthy(); +}); diff --git a/universal/apps/expo-app/jest.config.js b/universal/apps/expo-app/jest.config.js new file mode 100644 index 0000000..1832e69 --- /dev/null +++ b/universal/apps/expo-app/jest.config.js @@ -0,0 +1,15 @@ +module.exports = { + preset: "jest-expo", + roots: ["/__tests__"], + moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], + testEnvironment: "jsdom", + transformIgnorePatterns: [ + "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg|@gluestack-ui/.*|tailwind-variants)", + ], + setupFilesAfterEnv: ["@testing-library/jest-native/extend-expect"], + collectCoverageFrom: ["app/**/*.{ts,tsx}"], + reporters: ["default", "jest-junit"], + + testMatch: ["/__tests__/**/*.test.(js|jsx)"], + forceExit: true, +}; diff --git a/universal/apps/expo-app/junit.xml b/universal/apps/expo-app/junit.xml new file mode 100644 index 0000000..2b5c3b0 --- /dev/null +++ b/universal/apps/expo-app/junit.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/universal/apps/expo-app/package.json b/universal/apps/expo-app/package.json index f112ae2..443ed86 100644 --- a/universal/apps/expo-app/package.json +++ b/universal/apps/expo-app/package.json @@ -7,10 +7,7 @@ "android": "EXPO_USE_METRO_WORKSPACE_ROOT=1 npx expo start --android", "ios": "EXPO_USE_METRO_WORKSPACE_ROOT=1 npx expo start --ios", "web": "EXPO_USE_METRO_WORKSPACE_ROOT=1 npx expo start --web", - "test": "jest --watchAll" - }, - "jest": { - "preset": "jest-expo" + "test": "jest" }, "dependencies": { "@expo/vector-icons": "^14.0.0", @@ -37,11 +34,14 @@ }, "devDependencies": { "@babel/core": "^7.24.0", + "@testing-library/jest-native": "^5.4.3", + "@testing-library/react-native": "^12.7.2", "@types/react": "~18.2.45", "@unitools/babel-plugin-universal-image": "^1.0.0", "babel-plugin-module-resolver": "^5.0.2", "jest": "^29.2.1", "jest-expo": "~51.0.1", + "jest-junit": "^16.0.0", "react-test-renderer": "18.2.0", "typescript": "~5.3.3" }, diff --git a/universal/package.json b/universal/package.json index 2f2c587..4bddeb1 100644 --- a/universal/package.json +++ b/universal/package.json @@ -11,6 +11,7 @@ "run:expo": "cd apps/expo-app && yarn start", "run:next": "cd apps/next && yarn dev", "build:next": "cd apps/next && yarn build", + "test:expo": "cd apps/expo-app && yarn test", "format": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\" --ignore-path .gitignore", "postinstall": "patch-package", "eject": "npx @gluestack-ui/universal-cli@latest eject" diff --git a/universal/yarn.lock b/universal/yarn.lock index 28e851b..49cbb50 100644 --- a/universal/yarn.lock +++ b/universal/yarn.lock @@ -3962,6 +3962,26 @@ dependencies: tslib "^2.4.0" +"@testing-library/jest-native@^5.4.3": + version "5.4.3" + resolved "https://registry.yarnpkg.com/@testing-library/jest-native/-/jest-native-5.4.3.tgz#9334c68eaf45db9eb20d0876728cc5d7fc2c3ea2" + integrity sha512-/sSDGaOuE+PJ1Z9Kp4u7PQScSVVXGud59I/qsBFFJvIbcn4P6yYw6cBnBmbPF+X9aRIsTJRDl6gzw5ZkJNm66w== + dependencies: + chalk "^4.1.2" + jest-diff "^29.0.1" + jest-matcher-utils "^29.0.1" + pretty-format "^29.0.3" + redent "^3.0.0" + +"@testing-library/react-native@^12.7.2": + version "12.7.2" + resolved "https://registry.yarnpkg.com/@testing-library/react-native/-/react-native-12.7.2.tgz#d9dc62979264902c22ac9154eee0dc10914d1518" + integrity sha512-fSUIruOUFcuwssC8+m9H+9ib7P/+JrtIszHS4eZ6O9e4FjpjS3m24UnkJXTRl+FCbknz8oxH5Tw+thzy0qsIMg== + dependencies: + jest-matcher-utils "^29.7.0" + pretty-format "^29.7.0" + redent "^3.0.0" + "@tootallnate/once@2": version "2.0.0" resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf" @@ -7978,7 +7998,7 @@ jest-config@^29.7.0: slash "^3.0.0" strip-json-comments "^3.1.1" -jest-diff@^29.7.0: +jest-diff@^29.0.1, jest-diff@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-29.7.0.tgz#017934a66ebb7ecf6f205e84699be10afd70458a" integrity sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw== @@ -8074,6 +8094,16 @@ jest-haste-map@^29.7.0: optionalDependencies: fsevents "^2.3.2" +jest-junit@^16.0.0: + version "16.0.0" + resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-16.0.0.tgz#d838e8c561cf9fdd7eb54f63020777eee4136785" + integrity sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ== + dependencies: + mkdirp "^1.0.4" + strip-ansi "^6.0.1" + uuid "^8.3.2" + xml "^1.0.1" + jest-leak-detector@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-29.7.0.tgz#5b7ec0dadfdfec0ca383dc9aa016d36b5ea4c728" @@ -8082,7 +8112,7 @@ jest-leak-detector@^29.7.0: jest-get-type "^29.6.3" pretty-format "^29.7.0" -jest-matcher-utils@^29.7.0: +jest-matcher-utils@^29.0.1, jest-matcher-utils@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz#ae8fec79ff249fd592ce80e3ee474e83a6c44f12" integrity sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g== @@ -10220,7 +10250,7 @@ pretty-format@^26.5.2, pretty-format@^26.6.2: ansi-styles "^4.0.0" react-is "^17.0.1" -pretty-format@^29.7.0: +pretty-format@^29.0.3, pretty-format@^29.7.0: version "29.7.0" resolved "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz" integrity sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ== @@ -10689,6 +10719,14 @@ recast@^0.23.3: tiny-invariant "^1.3.3" tslib "^2.0.1" +redent@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/redent/-/redent-3.0.0.tgz#e557b7998316bb53c9f1f56fa626352c6963059f" + integrity sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg== + dependencies: + indent-string "^4.0.0" + strip-indent "^3.0.0" + reflect.getprototypeof@^1.0.4: version "1.0.4" resolved "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.4.tgz" @@ -12594,6 +12632,11 @@ xml2js@0.6.0: sax ">=0.6.0" xmlbuilder "~11.0.0" +xml@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5" + integrity sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw== + xmlbuilder@^14.0.0: version "14.0.0" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-14.0.0.tgz#876b5aec4f05ffd5feb97b0a871c855d16fbeb8c"