nuxt / test-utils

🧪 Test utilities for Nuxt
http://nuxt.com/docs/getting-started/testing
MIT License
287 stars 75 forks source link

[test-utils] testing for prerender build #343

Open kazupon opened 1 year ago

kazupon commented 1 year ago

Describe the feature

If we have a special implementation in the prerender environment, we may want to test it with its built from time to time. case: https://github.com/nuxt-modules/i18n/pull/1733

In @nuxt/test-utils setup, we can override the nuxtConfig option with _generate: true, which is equivalent to nuxi generate.

However, the server in @nuxt/test-utils is not yet ready to run a server for the prerender environment, so the test will stop with the following log output:

Error: Cannot find module '/path/to/nuxt/i18n/specs/fixtures/basic/.nuxt/ubpgju/output/server/index.mjs'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {

Additional information

Final checks

pi0 commented 1 year ago

Hi dear @kazupon. _generate is an internal flag an indeed unsupported for test-utils at the moment. What you can do, is to alternatively enable experimental.payloadExtraction and also enable nitro.prerender.crawlLinks: true. This generates server that serves static files as well. You can also use X-Powered-By header to assert if response is static or rendered on demand.

kazupon commented 1 year ago

Thank you for your kindful comment, as always! ❤️

I’ve felt that _generate is for internal. About experimental.payloadExtraction and nitro.prerender.crawlLinks: true, those are good and helpful for me. :) Thanks!