最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

react native - Testing Expo app using Realm on GitHub fails - Stack Overflow

programmeradmin1浏览0评论

I have created an Expo app using JavaScript. I have installed Realm in this Expo app. I have written snapshot tests for this app. I have also written tests for the Realm database. These tests work as expected.

The tests pass when I run them on my local machine.

I have pushed this app and the tests to GitHub. I have written a .github/workflows/testing.yml file to test this app each time I push to GitHub. These tests fail due to the fact that they take too long to run on GitHub. However, they run within seconds on my desktop PC, which is not a powerful machine.

How can I correctly run the tests each time I push to GitHub?

One example of the .github/workflows/testing.yml file I attempted to use:

name: Run Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: "20"
      - name: Install dependencies
        run: |
          npm install
      - name: Run tests
        env:
          CI: true
        run: |
          npm test --detectOpenHandles --forceExit

I have also attempted to create larger .github/workflows/testing.yml files which download Android Command Line Tools, install an Android Emulator and run the app on the Android Emulator before testing the code. However, this also fails.

I have created an Expo app using JavaScript. I have installed Realm in this Expo app. I have written snapshot tests for this app. I have also written tests for the Realm database. These tests work as expected.

The tests pass when I run them on my local machine.

I have pushed this app and the tests to GitHub. I have written a .github/workflows/testing.yml file to test this app each time I push to GitHub. These tests fail due to the fact that they take too long to run on GitHub. However, they run within seconds on my desktop PC, which is not a powerful machine.

How can I correctly run the tests each time I push to GitHub?

One example of the .github/workflows/testing.yml file I attempted to use:

name: Run Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: "20"
      - name: Install dependencies
        run: |
          npm install
      - name: Run tests
        env:
          CI: true
        run: |
          npm test --detectOpenHandles --forceExit

I have also attempted to create larger .github/workflows/testing.yml files which download Android Command Line Tools, install an Android Emulator and run the app on the Android Emulator before testing the code. However, this also fails.

Share Improve this question asked Nov 20, 2024 at 17:35 user27793975user27793975 197 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Instead of using the npm command, test the code using the correct testing method found in your package.json file.

For example, if the command in the package.json file is: "test": "jest --watchAll --runInBand --detectOpenHandles", the correct .github/workflows/testing.yml file would be:

name: Run Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Install Dependencies
        run: npm install
      - name: Run tests
        run: npx jest --runInBand --detectOpenHandles --forceExit

Don't use the --watchAll command as this could lead to the issue you were facing. Use the --forceExit command in the .github/workflows/testing.yml file to ensure the testing is exited.

This way, you can keep the command in the package.json file the same and can continue testing the app on your local machine in the same way.

发布评论

评论列表(0)

  1. 暂无评论