Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e34198
commit 79c2e37
Showing
4 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
# jsdom-quokka-plugin | ||
Quokka plugin to enable browser environment via jsdom | ||
[Quokka.js plugin](https://quokkajs.com/) to enable browser-like environment via [`jsdom`](https://github.com/tmpvar/jsdom). | ||
|
||
## Configuration | ||
|
||
Available [configuration settings](https://quokkajs.com/docs/configuration.html): | ||
|
||
```json | ||
{ | ||
"plugins": ["jsdom-quokka-plugin"], | ||
"jsdom": { | ||
"html": "...", | ||
"userAgent": "...", | ||
"config": {...} | ||
} | ||
} | ||
``` | ||
|
||
The `config` setting is [the `jsdom` config setting](https://github.com/tmpvar/jsdom). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
before: config => { | ||
const pluginConfig = config.jsdom || {}; | ||
const jsdomConfig = pluginConfig.config || {}; | ||
const html = pluginConfig.html || '<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>'; | ||
const jsdom = require('jsdom'); | ||
const document = jsdom.jsdom(html, jsdomConfig); | ||
|
||
Object.keys(document.defaultView).forEach((property) => { | ||
if (typeof global[property] === 'undefined') { | ||
global[property] = document.defaultView[property]; | ||
} | ||
}); | ||
|
||
global.navigator = { | ||
userAgent: pluginConfig.userAgent || 'quokka.js' | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "jsdom-quokka-plugin", | ||
"version": "1.0.0", | ||
"description": "Quokka plugin to enable browser environment via jsdom", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wallabyjs/jsdom-quokka-plugin.git" | ||
}, | ||
"keywords": [ | ||
"Quokka.js", | ||
"Wallaby.js" | ||
], | ||
"author": "Artem Govorov", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/wallabyjs/jsdom-quokka-plugin/issues" | ||
}, | ||
"homepage": "https://github.com/wallabyjs/jsdom-quokka-plugin#readme", | ||
"dependencies": { | ||
"jsdom": "^9.11.0" | ||
} | ||
} |