nuxt / test-utils

๐Ÿงช Test utilities for Nuxt
http://nuxt.com/docs/getting-started/testing
MIT License
322 stars 81 forks source link

tests are broken due to cucumber runner or don't work #974

Open GalacticHypernova opened 2 weeks ago

GalacticHypernova commented 2 weeks ago

Environment


Reproduction

I am unable to provide a reproduction for 2 main reasons:

  1. This is part of a production app, and I am willing to share it happening in real time privately
  2. It's inconsistent, as on Windows it fails completely and on Ubuntu it fails to run the e2e tests, so I can't even confirm it locally with a different configuration (I can provide the error it provides on Windows which causes it to abort even the initial test screen)

I can, however, provide the overall configuration and a sample of the tests: nuxt.config.ts modules:

modules: ["@nuxt/content","@nuxt/ui", "@pinia/nuxt", "@nuxt/image", '@nuxt/test-utils/module', "@nuxtjs/i18n", "@nuxtjs/seo",
        "@nuxtjs/turnstile", "nuxt-security", "@nuxt/scripts", "@nuxt/fonts"],

vitest.config.mts:

import { defineVitestConfig } from '@nuxt/test-utils/config'
export default defineVitestConfig({
    test:{
        environment:'nuxt',
        hookTimeout:50000
    }
})

Sample of test/e2e/e2e.nuxt.test.ts:

import { expect, describe, it } from "vitest"
import {setup, $fetch, fetch, createPage} from "@nuxt/test-utils/e2e"
describe("app", async () => {
    await setup({
        server:true,
        runner: 'vitest',
        build:true,
        setupTimeout:300000
    }
    )
       describe("images", async () => {
        it("should return correct data for existent images", async () => {
            const {body, status, headers} = await fetch('/images/image.webp')
            expect(status).toBe(200)
            expect(headers.get("Content-Type")).toBe("image/webp")
        })
        it("should return 404 for non-existent images", async () => {
            const {body, status} = await fetch('/images/nonExistent.jpg')
            expect(status).toBe(404)
        })
    })
})

Describe the bug

The cucumber test runner appears to execute the tests despite runner option of the setup of e2e to 'vitest' (or trying to use the default). Maybe because of this and maybe because of a different, unseen cause, it simply breaks all e2e tests with the error I provided in the Logs section.

I believe this is part of a bigger issue which I have not unearthed yet that could also explain the respective failures on both environments

Additional context

Attempting to upgrade/reinstall the project's deps does not appear to help. Unit tests are not affected by it, it affects only those that depend on the setup from the e2e section.

Logs

TypeError: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
 โฏ _build node_modules/nitropack/dist/nitro.mjs:2658:22
 โฏ node_modules/nuxt/dist/index.mjs:3630:5
 โฏ build node_modules/nuxt/dist/index.mjs:5778:3
 โฏ buildFixture node_modules/@nuxt/test-utils/dist/shared/test-utils.CaqvQLs_.mjs:121:3
    119|   const { After, AfterAll, Before, BeforeAll } = await import('@cucumber/cucumber');
    120|   BeforeAll({ timeout: hooks.ctx.options.setupTimeout }, hooks.setup);
    121|   Before(hooks.beforeEach);
       |   ^
    122|   After(hooks.afterEach);
    123|   AfterAll(hooks.afterAll);
 โฏ setup2 node_modules/@nuxt/test-utils/dist/shared/test-utils.CaqvQLs_.mjs:183:7
github-actions[bot] commented 18 hours ago

Would you be able to provide a reproduction? ๐Ÿ™

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a couple of templates for starting with a minimal reproduction: ๐Ÿ‘‰ https://stackblitz.com/github/nuxt/test-utils/tree/main/examples/app-vitest ๐Ÿ‘‰ https://stackblitz.com/github/nuxt/test-utils/tree/main/examples/app-jest ๐Ÿ‘‰ https://stackblitz.com/github/nuxt/test-utils/tree/main/examples/module A public GitHub repository is also perfect. ๐Ÿ‘Œ Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve)