Nuxt开玩笑地进行端到端测试

时间:2020-09-25 14:22:09

标签: testing jestjs nuxt.js

您好,我正在寻找一种使用组件测试以及使用nuxt进行端到端测试的方法。

我们希望能够测试组件(已经工作),并检查页面是否正确解析了其url参数或站点地图是否正确创建以及其他页面级功能和路由器功能

我尝试使用av​​a,但是我们已经使用jest实施了组件测试,现在可以正常工作了,在nuxt文档中,使用ava描述了用于测试的服务器渲染,我现在将其调整为jest,但是我遇到了超时错误,所以我增加了时间到40秒,但仍然超时。

是否有人像示例(https://nuxtjs.org/guide/development-tools)中那样得到了与nuxt构建器一起使用的测试?

这是我的端到端测试示例文件

// test.spec.js:
const { resolve } = require('path')
const { Nuxt, Builder } = require('nuxt')

// We keep the nuxt and server instance
// So we can close them at the end of the test
let nuxt = null

// Init Nuxt.js and create a server listening on localhost:4000
beforeAll(async (done) => {
  jest.setTimeout(40000)

  const config = {
    dev: false,
    rootDir: resolve(__dirname, '../..'),
    telemetry: false,
  }
  nuxt = new Nuxt(config)
  try {
    await new Builder(nuxt).build()
    nuxt.server.listen(4000, 'localhost')
  } catch (e) {
    console.log(e)
  }

  done()
}, 30000)
describe('testing nuxt', () => {
  // Example of testing only generated html
  test('Route / exits and render HTML', async (t, done) => {
    const context = {}
    const { html } = await nuxt.server.renderRoute('/', context)
    t.true(html.includes('<h1 class="red">Hello world!</h1>'))
    jest.setTimeout(30000)
    done()
  })
})
// Close server and ask nuxt to stop listening to file changes
afterAll((t) => {
  nuxt.close()
})

我当前的错误是:

 ● Test suite failed to run

    Timeout - Async callback was not invoked within the 40000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 40000ms timeout specified by jest.setTimeout.

非常感谢任何信息,因为我自己无法解决此问题

0 个答案:

没有答案