question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unit testing resource-loader on node.js

See original GitHub issue

Setup

I use pixi.js, which uses resource-loader. I have my own things in my app, and one of them is loader, which uses pixi.js loader. I use Jest for unit testing.

Issue

Because Jest works in node.js enviroment, I cannot get resource-loader to work. No errors, it just doesn’t finish loading (and callback is not called). My suspect is XHR requests are not working.

Moreover: mocking GET request with xhr-mock doesn’t work - request is not interrupted. I have even tested pure resource-loader with the following code:

      const l = new Loader();
      l.add('foo', 'data:image/gif;base64,R0lGODlhAQABAPAAAP8REf///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==');
      l.onProgress.add(() => { console.log('progress'); });
      l.onError.add(() => { console.log('error'); });
      l.onLoad.add(() => { console.log('load'); });
      l.onComplete.add(() => { console.log('complete'); });
      l.load(() => {
        done();
      });

where that base64 is image taken from resource-loader tests. And no done() is called, neither console logs are executed. Just nothing works. resource-loader tests are written using Karma, and seem to use Chrome as browser, to that may be, why node.js test don’t work.

And it’s not uncommon case to use some resource-loader on node.js. I imagine some node.js games.

Any ideas what can I do? It makes any unit testing pointless, if I cannot load resources.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
englercjcommented, Feb 4, 2018

I ran your code example and attached a node debugger. I stepped through resource-loader and everything is working correctly. Image just never calls the load or error callbacks.

A quick search shows that jsdom doesn’t load anything unless you configure it to:

https://github.com/jsdom/jsdom/issues/1816#issuecomment-310106280

Closing this since it is a jsdom/Jest configuration issue.

1reaction
soanvigcommented, Feb 4, 2018

You were extremelly generous to me. Thank You, sir!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js Unit Testing: Get Started Quickly With Examples
This post we'll show you how to get started with Node.js unit testing in practice, with examples. Think of this post as a...
Read more >
Fast and isolated JS unit tests - Wikimedia Phabricator
With this setup, tests have to go through to the MediaWiki server, ResourceLoader, and then run in the browser.
Read more >
Unit Testing in Node.js: The Basics and a Quick Tutorial
A comprehensive set of unit tests, run automatically every time your codebase changes, is highly effective at catching regressions. How to ...
Read more >
Unit Testing of Node.js Application - GeeksforGeeks
In Node.js there are many frameworks available for running unit tests. Some of them are: Mocha; Jest; Jasmine; AVA. Unit testing for a...
Read more >
Core Technologies - Spring
The configuration metadata is represented in XML, Java annotations, or Java code. It lets you express the objects that compose your application and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found