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

jsdom Error Doesn't Propagate to uncss Callback #433

Open
emmercm opened this issue Jun 13, 2020 · 0 comments
Open

jsdom Error Doesn't Propagate to uncss Callback #433

emmercm opened this issue Jun 13, 2020 · 0 comments

Comments

@emmercm
Copy link

emmercm commented Jun 13, 2020

Commented on #430 but I'm unsure if it's related or not.

Given some random HTML, where no CSS or JavaScript resources actually exist on disk:

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="static/style.css">
    <link rel="stylesheet" href="static/uncss.css">
</head>
<body>
<h1>Index</h1>
<script src="static/script.js"></script>
<script src="doesnt/exist.js"></script>
</body>
</html>

And when calling uncss where I'm passing all real CSS content through raw:

{
    "banner": false,
    "raw": ".some { css: styles }",
    "stylesheets": ["dummy.css"]
}

where dummy.css exists completely empty only so there isn't an error here:

throw new Error(`UnCSS: could not open ${path.join(process.cwd(), filename)}`);

Starting in v0.17.2 I get errors from jsdom similar to (v0.17.3 output shown):

Error: Could not load script: "static/script.js"
    at onErrorWrapped (.../node_modules/jsdom/lib/jsdom/browser/resources/per-document-resource-loader.js:38:19)
    at Object.check (.../node_modules/jsdom/lib/jsdom/browser/resources/resource-queue.js:72:23)
    at request.then.catch.err (.../node_modules/jsdom/lib/jsdom/browser/resources/resource-queue.js:124:14)
    at process._tickCallback (internal/process/next_tick.js:68:7) Error: Tried to fetch invalid URL static/script.js
    at CustomResourcesLoader.fetch (.../node_modules/jsdom/lib/jsdom/browser/resources/resource-loader.js:84:29)
    at CustomResourcesLoader.fetch (.../node_modules/uncss/src/jsdom.js:62:22)
    at PerDocumentResourceLoader.fetch (.../node_modules/jsdom/lib/jsdom/browser/resources/per-document-resource-loader.js:17:42)
    at HTMLScriptElementImpl._fetchExternalScript (.../node_modules/jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:93:30)
    at HTMLScriptElementImpl._eval (.../node_modules/jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:160:12)
    at HTMLScriptElementImpl._poppedOffStackOfOpenElements (.../node_modules/jsdom/lib/jsdom/living/nodes/HTMLScriptElement-impl.js:125:10)
    at OpenElementStack.JSDOMParse5Adapter.OpenElementStack.pop (.../node_modules/jsdom/lib/jsdom/browser/parser/html.js:45:16)
    at Object.endTagInText [as END_TAG_TOKEN] (.../node_modules/parse5/lib/parser/index.js:2153:20)
    at Parser._processToken (.../node_modules/parse5/lib/parser/index.js:657:55)
    at Parser._processInputToken (.../node_modules/parse5/lib/parser/index.js:684:18)
    at Parser._runParsingLoop (.../node_modules/parse5/lib/parser/index.js:440:18)
    at Parser.parse (.../node_modules/parse5/lib/parser/index.js:344:14)
    at Object.parse (.../node_modules/parse5/lib/index.js:10:19)
    at parseIntoDocument (.../node_modules/jsdom/lib/jsdom/browser/parser/html.js:175:17)
    at parseIntoDocument (.../node_modules/jsdom/lib/jsdom/browser/parser/index.js:31:10)
    at new JSDOM (.../node_modules/jsdom/lib/api.js:45:5)
    at Promise (.../node_modules/uncss/src/jsdom.js:94:43)
    at new Promise (<anonymous>)
    at Object.fromSource (.../node_modules/uncss/src/jsdom.js:89:12)
    at Promise.all.files.map (.../node_modules/uncss/src/uncss.js:36:50)
    at Array.map (<anonymous>)
    at getHTML (.../node_modules/uncss/src/uncss.js:36:30)
    at process (.../node_modules/uncss/src/uncss.js:221:12)
    at uncss (.../node_modules/uncss/src/uncss.js:213:5)

and this error does not propagate to the callback supplied to uncss, causing strange behavior in my application.


Changing the jsdom options does solve the problem:

{
    "banner": false,
    "raw": ".some { css: styles }",
    "stylesheets": ["dummy.css"],
    "jsdom": {
        "runScripts": "outside-only"
    }
}

but that doesn't fix my tests that were passing even though there was an error that didn't propagate.

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

No branches or pull requests

1 participant