我对 GitHub 操作和 Redis 还很陌生。 我正在 GitHub 操作上运行这个 CI(下面的代码)
name: sanity check
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
redis-version: [6]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14"
- uses: supercharge/redis-github-action@1.2.0 # sets up Redis
with:
redis-version: ${{ matrix.redis-version }}
- run: node -v
- run: yarn -v
# - run: redis-cli ping
- run: yarn install
- run: yarn test --detectOpenHandles
这样我就可以使用 Redis 执行集成测试,但是这个 CI 不会退出(我正在使用 Jest 运行测试)
是不是因为我没有使用 Docker?我需要做什么才能确保此测试退出?在本地,它运行良好(尽管我手动启动了 Redis 服务器)。我是否需要 Docker 才能很好地完成这项工作?如果这是问题,有关如何在 GitHub 操作上使用 Redis 运行 Docker 的任何链接?
PS:如果您需要更多关于此的信息,请告诉我
答案 0 :(得分:0)
Jest 不退出的问题可能是因为我在测试中使用了真正的 redis nodejs 客户端。 我把它换成这个
import { createNodeRedisClient } from "handy-redis";
import { createClient } from "redis-mock";
const cache =
process.env.NODE_ENV === "production"
? createNodeRedisClient({
url: process.env.REDIS_URL,
})
: createClient();
export { cache };
我没有再收到错误