Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderAndGetWindow times out when testing with Ava and TypeScript #6008

Closed
JakubKoralewski opened this issue Jun 29, 2019 · 3 comments · Fixed by #6178
Closed

renderAndGetWindow times out when testing with Ava and TypeScript #6008

JakubKoralewski opened this issue Jun 29, 2019 · 3 comments · Fixed by #6178

Comments

@JakubKoralewski
Copy link

Version

v2.8.1

Reproduction link

https://github.com/JakubKoralewski/mireks/tree/5f609e843a21b1130ef8e8e9770015c8538d4c65

Steps to reproduce

  1. Run npm run test.
  • first tests should pass
  • when it gets to the second test ("Route / exists and renders HTML with CSS applied") it throws this Error:
test("Route / exists and renders HTML with CSS applied", async t => {
	console.log("Rendering window");
	// console.log("nuxt.server: ", nuxt.server);
	const window: Window = await nuxt.server.renderAndGetWindow(url("/"));
//(...)
});

What is expected ?

Maybe allow the user to change the timeout, since it is hardcoded as a default parameter even though it is not used anywhere.

Plus I'd like to actually be able to do some tests.

What is actually happening?

× test » index.ts » Route / exists and renders HTML with CSS applied Rejected promise returned by test

  1 test failed

  test » index.ts » Route / exists and renders HTML with CSS applied

  F:\projects\web\mireks\mireks_next\src\node_modules\@nuxt\utils\dist\utils.js:1849

  Rejected promise returned by test. Reason:

  Error {
    message: 'Components loading in renderAndGetWindow was not completed in 2s',
  }

npm ERR! code ELIFECYCLE
npm ERR! errno 1

Additional comments?

Here's the before test part:

test.before("Init Nuxt.js", async t => {
	const rootDir = resolve(__dirname, "..");
	let config: NuxtConfiguration = {};
	config = require(resolve(rootDir, "nuxt.config.ts")).default;
	config.rootDir = rootDir; // project folder
	config.dev = true; // production build
	config._typescript = { build: true };
	nuxt = new Nuxt(config);
	await new Builder(nuxt).build();
	await nuxt.server.listen(4000, "localhost");
});
This bug report is available on Nuxt community (#c9435)
@ghost ghost added the cmty:bug-report label Jun 29, 2019
@pimlie
Copy link

pimlie commented Jul 8, 2019

You can already change the loadingTimeout, 3rd arg of renderAndGetWindow is an obj with some nuxt specific configuration

Please check and see if that fixes your issue

@pimlie pimlie added the question label Jul 8, 2019
@JakubKoralewski
Copy link
Author

JakubKoralewski commented Jul 10, 2019

@pimlie By my understanding the actual exposed API is here: https://github.com/nuxt/nuxt.js/blob/32f9df76f39c93f7cdc36502f1ce194e9aaf429d/packages/server/src/server.js#L218-L224
And if you look closely you can see that the exposed API in server.js only takes two arguments and the third one in jsdom.js actually hardcoded.

I tried setting the third argument anyway like this: await nuxt.server.renderAndGetWindow(url("/"), undefined, {loadingTimeout: 10000});, but I got this:

Error {
    message: 'Components loading in renderAndGetWindow was not completed in 2s',
  }

which originates here: https://github.com/nuxt/nuxt.js/blob/32f9df76f39c93f7cdc36502f1ce194e9aaf429d/packages/server/src/jsdom.js#L64-L66

Meaning the loadingTimeout was not changed from the default :/

@pimlie
Copy link

pimlie commented Jul 29, 2019

@JakubKoralewski Sorry for the late response. What happens when you add

  globals: {
    loadingTimeout: XXX
  }

to your nuxt.config? That should work I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants