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.

why is the node application doesn't exit with jsdom?

See original GitHub issue

Hi all: I’m writing a node.js script to parse some html file with jsdom. The code looks like:

function parsingURL(file) {
    var fs = require('fs');
    var readFileSync = fs.readFileSync(file);
    var jsdom = require('jsdom');
    jsdom.env({
            html: readFileSync,
            scripts: ['http://code.jquery.com/jquery-1.11.2.min.js'],
            done: function (errors, window) {
                // free memory associated with the window
                if (errors) {
                    console.info(errors);
                } else {
                     console.info("success");
                }
            }
        }
    );
};

The “success” is printed as expected, but why the node application still hangs without exiting?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Sebmastercommented, Jan 15, 2015

Make sure you call window.close() in your done callback.

0reactions
mbrevdacommented, Dec 29, 2015

While I don’t have much helpful to add, I’m seeing the same. After my callbacks are called, the process hangs for about two minutes until being killed. Code:

    return new Promise(function(resolve, reject) {
        jsdom.env({
            url: url,
            features: {
              FetchExternalResources   : ["script", "frame", "iframe", "link"],
              ProcessExternalResources : ['script']
            },
            virtualConsole: jsdom.createVirtualConsole().sendTo(console),
            done: function(err, window) {
                if (err) return reject(err)

                setTimeout(() => {
                    var doc = jsdom.serializeDocument(window.document)

                    mkdirp(path.dirname(filepath))
                        .then(utils.saveFile(filepath, doc))
                        //.then(() => window.close()) //<--- tried with/without + different variations
                        .then(resolve)
                }, 1000)
            }
        })
    })

edit to add that my then()'s are all called

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSDOM - nodejs makes clean exit, doesn't load - Stack Overflow
I am trying to get the last step to work. I tried this initially with my own code as I am begining to...
Read more >
How to Exit a Process in Node.js: process.exit() Method
There could be several reasons that a Node.js application terminates either automatically or sometimes you need to do it forcefully or manually.
Read more >
jsdom - npm
jsdom. jsdom is a pure-JavaScript implementation of many web standards, notably the WHATWG DOM and HTML Standards, for use with Node.js.
Read more >
Configuring Jest
To read TypeScript configuration files Jest requires ts-node . Make sure it is installed in your project. The configuration also can be stored ......
Read more >
JSDOM: How to Get Started - Testim.io
By default JSDOM thinks the base URL for your application is about:blank. This can cause all sorts of testing errors inside your application,...
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