You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions 中异步调用过多导致 Vue 路由测试批量失败的问题咨询

正在开发一款 Vue 应用,为提升性能,将大部分路由设置为异步导入,对应路由配置文件为 index.js,核心代码如下:

const ComponentA = () => import('path/to/ComponentA')
const ComponentB = () => import('path/to/ComponentB')

... 

export const routes = [
  {path: '/routeA', component: ComponentA},
  {path: '/routeB', component: ComponentB}
...
]

编写的 Jest 测试代码存放在 index.spec.js 中,核心实现大致如下:

import ComponentA from 'path/to/ComponentA'
import ComponentB from 'path/to/ComponentB'

...

describe('router/index.js navigation test', () => {
  it('/routeA', async () => {
    expect(wrapper.findAll(ComponentA)).toHaveLength(0)
    router.push('/routeA')
    await flushPromises()
    await wrapper.vm.$nextTick()
    expect(wrapper.findAll(ComponentA)).toHaveLength(1)
  })
 it('/routeB', async () => {
    expect(wrapper.findAll(ComponentB)).toHaveLength(0)
    router.push('/routeB')
    await flushPromises()
    await wrapper.vm.$nextTick()
    expect(wrapper.findAll(ComponentB)).toHaveLength(1)
  })
...
})

这份测试文件中每条路由对应1个测试用例,总计约80个测试,其中大部分为异步测试。

异常表现

  • 本地运行测试时没有任何问题
  • 在 GitHub Actions 上执行测试时,index.spec.js 中靠后的测试会全部失败
  • 排查过程中尝试过仅跳过失败的测试,发现从某个节点之后的所有测试都会失败;跳过失败点前的一个测试也无法解决问题
  • 唯一可让所有用例正常通过的方案是将过长的 index.spec.js 拆分为两个独立文件:不需要修改任何单个测试的逻辑,拆分后的 index.spec.js 和 index2.spec.js 在本地和 GitHub Actions 环境都能正常通过所有用例

核心疑问

是否存在未被了解的异步调用栈限制,导致这类场景下测试批量报错?

参考的 GitHub Actions 配置文件 test.yml 内容如下:

name: Test
on:
  pull_request:
    branches:
      - dev
jobs:
  testing:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: npm ci
      - run: npm test

欢迎大家给出相关见解,提前致谢。


内容的提问来源于stack exchange,提问作者ValleyCrisps

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.27 05:27:04