Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemGovorov committed Mar 9, 2017
1 parent 6e34198 commit 79c2e37
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
.idea
20 changes: 18 additions & 2 deletions README.md
@@ -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).
19 changes: 19 additions & 0 deletions index.js
@@ -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'
};
}
};
26 changes: 26 additions & 0 deletions package.json
@@ -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"
}
}

0 comments on commit 79c2e37

Please sign in to comment.