Last active
October 9, 2016 13:58
-
-
Save stoikerty/a202280147910b63a20e167dc4778fb8 to your computer and use it in GitHub Desktop.
Setting up tests for `dev-toolkit` npm-package. [ https://github.com/stoikerty/dev-toolkit ]
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
src/**/*.spec.* utilities/**/*.spec.* --reporter spec | |
--slow 150 | |
--compilers js:babel-core/register,js:./node_modules/dev-toolkit/dist/webpack/config.js,js:./utilities/testHelpers/setupDOM.js,js:./utilities/testHelpers/setupTests.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
... | |
"scripts": { | |
"test": "better-npm-run test", | |
"// run tests for a single file, rebuild on save. Example: `npm run test-single myAwesomeTest` //" | |
"test-single": "better-npm-run test --watch-extensions js,jsx --watch --grep", | |
}, | |
... | |
"betterScripts": { | |
"test": { | |
"command": "mocha --opts .mocha.opts", | |
"env": { | |
"NODE_ENV": "test", | |
"NODE_PATH": "." | |
} | |
}, | |
... | |
"devDependencies": { | |
"// This example is specific to the toolkit v5 at the time of writing. //" | |
"dev-toolkit": "^latest-version", | |
... | |
"// for babel-core/register //" | |
"babel-cli": "^6.16.0", | |
"// for using env's easily //" | |
"better-npm-run": "0.0.11", | |
"// for the DOM setup //" | |
"jsdom": "^9.0.0", | |
"// the test-runner //" | |
"mocha": "^2.4.5", | |
"// + any additional packages you want such as chai, expect, expect-jsx, enzyme, etc //" | |
... | |
} |
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
// ----- utilities/testHelpers/setupDOM.js ----- | |
// Setup jsdom to be used all throughout mocha tests | |
// Using suggested version from: https://github.com/facebook/react/issues/5046 | |
import { jsdom } from 'jsdom'; | |
global.document = jsdom('<!doctype html><html><body id="mock-dom"></body></html>'); | |
global.window = document.defaultView; | |
global.navigator = global.window.navigator; |
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
// ----- utilities/testHelpers/setupTests.js ----- | |
// Setup `app`-object globally so it's same as on the client | |
import 'src/client/app'; | |
global.app = window.app; | |
// NOTE: Everything below is optional, it's an example of how to integrate plugins | |
// Additional tests-configuration | |
import chai from 'chai'; | |
import sinonChai from 'sinon-chai'; | |
import chaiImmutable from 'chai-immutable'; | |
import chaiAsPromised from 'chai-as-promised'; | |
import chaiEnzyme from 'chai-enzyme'; | |
chai.use(sinonChai); | |
chai.use(chaiImmutable); | |
chai.use(chaiAsPromised); | |
chai.use(chaiEnzyme()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment