Skip to content

Commit

Permalink
Merge pull request #36 from sparksuite/fix-window-reference-error
Browse files Browse the repository at this point in the history
Fix reference error to `window` object in Node.js environments
  • Loading branch information
WesCossick authored Feb 25, 2021
2 parents 7faaf04 + b2f162e commit 3d86bf0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "w3c-css-validator",
"version": "1.0.1",
"version": "1.0.2",
"description": "Easily validate CSS using W3C's public CSS validator service",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/retrieve-validation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface W3CCSSValidatorResponse {

// Function that detects the appropriate HTTP request client and returns a response accordingly
const retrieveValidation = async (url: string): Promise<W3CCSSValidatorResponse['cssvalidation']> => {
if (typeof window?.fetch === 'function') {
if (typeof window !== 'undefined' && typeof window?.fetch === 'function') {
return await retrieveInBrowser(url);
}

Expand Down
3 changes: 1 addition & 2 deletions tests/node/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Make sure it runs in Node.js outside the context of Jest
// -> Jest injects global variables into the runtime environment, which can alter behavior
// require('w3c-css-validator').validateText('.foo { text-align: center; }');
console.log('Test');
require('w3c-css-validator').validateText('.foo { text-align: center; }');

0 comments on commit 3d86bf0

Please sign in to comment.