Repository: hustcc/jest-canvas-mock (js)

Issue:
Running tests in node environment
I have `jest-canvas-mock` configured in my package.json:
```
"jest": {
  "setupFiles": [
    "jest-canvas-mock"
  ]
}
```

This is working great for my tests 🎉 

However, I'm running some new tests in the [node test environment](https://facebook.github.io/jest/docs/en/configuration.html#testenvironment-string) by using the docblock at the top of the file. In this case `jest-canvas-mock` is throwing an error that window is not defined (which is expected I guess)

Is there any way that the canvas mock can be disabled for jest test files that are run in the node environment?

Pull request description:
fix(ssr): allow mocking to fail silently in node env
Fixes #6

Allows `jest-canvas-mock` to run normally in jsdom environments.

Allows the mocking to fail silently in node environments, which is needed to test components that are rendered both on the client and on the server.

Patch:
diff --git a/lib/index.js b/lib/index.js
index ee1f36d..5a778e0 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -7,7 +7,9 @@ var _window2 = _interopRequireDefault(_window);
 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
 // mock global window
-global.window = (0, _window2.default)(window); /**
-                                                * Created by hustcc 17/12/25.
-                                                * Contract: i@hust.cc
-                                                */
\ No newline at end of file
+if (typeof window !== 'undefined') {
+  global.window = (0, _window2.default)(window);
+} /**
+   * Created by hustcc 17/12/25.
+   * Contract: i@hust.cc
+   */
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index b68d6e5..3308e73 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,4 +6,6 @@
 import mockWindow  from './window';
 
 // mock global window
-global.window = mockWindow(window);
+if (typeof window !== 'undefined') {
+  global.window = mockWindow(window);
+}


Test patch:
diff --git a/__tests__/server-side.js b/__tests__/server-side.js
new file mode 100644
index 0000000..f6df8ee
--- /dev/null
+++ b/__tests__/server-side.js
@@ -0,0 +1,15 @@
+/**
+ * @jest-environment node
+ */
+
+/**
+ * test canvas mock in a node environment
+ */
+
+import createCanvas from '../src/canvas';
+
+describe('canvas', () => {
+  test('running in node environment fails silently', () => {
+    expect(createCanvas).toBeDefined();
+  })
+});
\ No newline at end of file