From 803b114a3c9abe1d38c784c9dbfd1bb65c7e2562 Mon Sep 17 00:00:00 2001 From: Nate Piche Date: Mon, 18 Jan 2016 14:21:31 -0500 Subject: [PATCH 1/3] adds .skip and .only functionality to describeWithDOM --- src/__tests__/ReactWrapper-spec.js | 2 +- src/__tests__/Utils-spec.js | 4 ++- src/__tests__/describeWithDOM-spec.js | 21 ++++++++++++ src/describeWithDOM.js | 47 +++++++++++++++++++++++++++ src/index.js | 20 ------------ 5 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 src/__tests__/describeWithDOM-spec.js create mode 100644 src/describeWithDOM.js diff --git a/src/__tests__/ReactWrapper-spec.js b/src/__tests__/ReactWrapper-spec.js index 10efa5d2b..168957a05 100644 --- a/src/__tests__/ReactWrapper-spec.js +++ b/src/__tests__/ReactWrapper-spec.js @@ -5,8 +5,8 @@ import { mount, render, ReactWrapper, - describeWithDOM, } from '../'; +import { describeWithDOM } from '../describeWithDOM'; import { describeIf } from './_helpers'; import { REACT013 } from '../version'; diff --git a/src/__tests__/Utils-spec.js b/src/__tests__/Utils-spec.js index 49a9513b8..fddec7ac3 100644 --- a/src/__tests__/Utils-spec.js +++ b/src/__tests__/Utils-spec.js @@ -13,9 +13,11 @@ import { mapNativeEventNames, } from '../Utils'; import { - describeWithDOM, mount, } from '../'; +import { + describeWithDOM, +} from '../describeWithDOM'; describe('Utils', () => { diff --git a/src/__tests__/describeWithDOM-spec.js b/src/__tests__/describeWithDOM-spec.js new file mode 100644 index 000000000..168552bf7 --- /dev/null +++ b/src/__tests__/describeWithDOM-spec.js @@ -0,0 +1,21 @@ +import React from 'react'; +import { expect } from 'chai'; +import { mount } from '../'; +import { describeWithDOM } from '../describeWithDOM'; + +describe('describeWithDOM', () => { + describe('.skip()', () => { + describeWithDOM.skip('will skip tests called with skip', () => { + it('will not run this test', () => { + // purposefully failing test that won't be called + expect(true).to.equal(false); + }); + }); + + describeWithDOM('will still call describeWithDOM without .skip', () => { + it('will run this test', () => { + expect(true).to.equal(true); + }); + }); + }); +}); diff --git a/src/describeWithDOM.js b/src/describeWithDOM.js new file mode 100644 index 000000000..b9a8c19da --- /dev/null +++ b/src/describeWithDOM.js @@ -0,0 +1,47 @@ +let jsdom; + +try { + require('jsdom'); // could throw + jsdom = require('mocha-jsdom'); +} catch (e) { + // jsdom is not supported... +} + +export function describeWithDOM(a, b) { + describe('(uses jsdom)', () => { + if (typeof jsdom === 'function') { + jsdom(); + describe(a, b); + } else { + // if jsdom isn't available, skip every test in this describe context + describe.skip(a, b); + } + }); +} + +function only(a, b) { + describe('(uses jsdom)', () => { + if (typeof jsdom === 'function') { + jsdom(); + describe.only(a, b); + } else { + // if jsdom isn't available, skip every test in this describe context + describe.skip(a, b); + } + }); +} + +function skip(a, b) { + describe('(uses jsdom)', () => { + if (typeof jsdom === 'function') { + jsdom(); + describe.skip(a, b); + } else { + // if jsdom isn't available, skip every test in this describe context + describe.skip(a, b); + } + }); +} + +describeWithDOM.only = only; +describeWithDOM.skip = skip; diff --git a/src/index.js b/src/index.js index 934725bac..3e0c5c68f 100644 --- a/src/index.js +++ b/src/index.js @@ -9,28 +9,8 @@ import { renderToStaticMarkup } from './react-compat'; * @class Enzyme */ -let jsdom; -try { - require('jsdom'); // could throw - jsdom = require('mocha-jsdom'); -} catch (e) { - // jsdom is not supported... -} - export let sinon = Sinon.sandbox.create(); -export function describeWithDOM(a, b) { - describe('(uses jsdom)', () => { - if (typeof jsdom === 'function') { - jsdom(); - describe(a, b); - } else { - // if jsdom isn't available, skip every test in this describe context - describe.skip(a, b); - } - }); -} - export function useSetStateHack() { let cleanup = false; before(() => { From f73d3e7acac06237416d3a15e4aa7cfb5a11eaf5 Mon Sep 17 00:00:00 2001 From: Nate Piche Date: Mon, 18 Jan 2016 19:09:57 -0500 Subject: [PATCH 2/3] adds .only tests and modified package.json test runs --- .gitignore | 3 +++ package.json | 4 +++- src/__tests__/describeWithDOM-spec.js | 21 ------------------- .../describeWithDOMOnly-spec.js | 19 +++++++++++++++++ .../describeWithDOMSkip-spec.js | 19 +++++++++++++++++ src/describeWithDOM.js | 8 +++---- 6 files changed, 48 insertions(+), 26 deletions(-) delete mode 100644 src/__tests__/describeWithDOM-spec.js create mode 100644 src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js create mode 100644 src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js diff --git a/.gitignore b/.gitignore index 84884bb93..c8b1692f2 100644 --- a/.gitignore +++ b/.gitignore @@ -29,5 +29,8 @@ node_modules # Jetbrains IDEs .idea +# vim swp files +*.swp + /build _book diff --git a/package.json b/package.json index 58dc4ee25..d6bedafe1 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,9 @@ "check": "npm run lint && npm run test:all", "build": "babel src --out-dir build", "test:watch": "mocha --compilers js:babel/register --recursive src/**/__tests__/*.js --watch", - "test:all": "npm run react:13 && npm test && npm run react:14 && npm test", + "test:describeWithDOMOnly": "mocha --compilers js:babel/register --recursive src/**/__tests__/describeWithDOM/describeWithDOMOnly-spec.js", + "test:describeWithDOMSkip": "mocha --compilers js:babel/register --recursive src/**/__tests__/describeWithDOM/describeWithDOMSkip-spec.js", + "test:all": "npm run react:13 && npm test && npm run test:describeWithDOMOnly && npm run test:describeWithDOMSkip && npm run react:14 && npm test && npm run test:describeWithDOMOnly && npm run test:describeWithDOMSkip", "react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils", "react:13": "npm run react:clean && npm i react@0.13", "react:14": "npm run react:clean && npm i react@0.14 react-dom@0.14 react-addons-test-utils@0.14", diff --git a/src/__tests__/describeWithDOM-spec.js b/src/__tests__/describeWithDOM-spec.js deleted file mode 100644 index 168552bf7..000000000 --- a/src/__tests__/describeWithDOM-spec.js +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react'; -import { expect } from 'chai'; -import { mount } from '../'; -import { describeWithDOM } from '../describeWithDOM'; - -describe('describeWithDOM', () => { - describe('.skip()', () => { - describeWithDOM.skip('will skip tests called with skip', () => { - it('will not run this test', () => { - // purposefully failing test that won't be called - expect(true).to.equal(false); - }); - }); - - describeWithDOM('will still call describeWithDOM without .skip', () => { - it('will run this test', () => { - expect(true).to.equal(true); - }); - }); - }); -}); diff --git a/src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js b/src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js new file mode 100644 index 000000000..b54e0b83e --- /dev/null +++ b/src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js @@ -0,0 +1,19 @@ +import { expect } from 'chai'; +import { describeWithDOM } from '../../describeWithDOM'; + +describe('describeWithDOM', () => { + describe('.only()', () => { + describeWithDOM.only('will skip all tests not called with only', () => { + it('will run only this test', () => { + expect(true).to.equal(true); + }); + }); + + describeWithDOM('will not call other tests', () => { + it('will not run this test', () => { + // purposefully failing test that won't be called + expect(true).to.equal(false); + }); + }); + }); +}); diff --git a/src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js b/src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js new file mode 100644 index 000000000..7c348700f --- /dev/null +++ b/src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js @@ -0,0 +1,19 @@ +import { expect } from 'chai'; +import { describeWithDOM } from '../../describeWithDOM'; + +describe('describeWithDOM', () => { + describe('.skip()', () => { + describeWithDOM.skip('will skip tests called with skip', () => { + it('will not run this test', () => { + // purposefully failing test that won't be run + expect(true).to.equal(false); + }); + }); + + describeWithDOM('will still call describeWithDOM tests without .skip', () => { + it('will run this test', () => { + expect(true).to.equal(true); + }); + }); + }); +}); diff --git a/src/describeWithDOM.js b/src/describeWithDOM.js index b9a8c19da..217032ad7 100644 --- a/src/describeWithDOM.js +++ b/src/describeWithDOM.js @@ -1,15 +1,15 @@ let jsdom; try { - require('jsdom'); // could throw - jsdom = require('mocha-jsdom'); + require('jsdom'); // could throw + jsdom = require('mocha-jsdom'); } catch (e) { - // jsdom is not supported... + // jsdom is not supported... } export function describeWithDOM(a, b) { describe('(uses jsdom)', () => { - if (typeof jsdom === 'function') { + if (typeof jsdom === 'function') { jsdom(); describe(a, b); } else { From 975160ad38bdc41ed254fdf10d0839546f92d666 Mon Sep 17 00:00:00 2001 From: Nate Piche Date: Mon, 18 Jan 2016 20:57:58 -0500 Subject: [PATCH 3/3] address review feedback --- .gitignore | 3 --- package.json | 4 ++-- src/__tests__/ReactWrapper-spec.js | 2 +- src/__tests__/Utils-spec.js | 4 +--- src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js | 2 +- src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js | 4 ++-- src/index.js | 2 ++ 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index c8b1692f2..84884bb93 100644 --- a/.gitignore +++ b/.gitignore @@ -29,8 +29,5 @@ node_modules # Jetbrains IDEs .idea -# vim swp files -*.swp - /build _book diff --git a/package.json b/package.json index d6bedafe1..5c30361ae 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "check": "npm run lint && npm run test:all", "build": "babel src --out-dir build", "test:watch": "mocha --compilers js:babel/register --recursive src/**/__tests__/*.js --watch", - "test:describeWithDOMOnly": "mocha --compilers js:babel/register --recursive src/**/__tests__/describeWithDOM/describeWithDOMOnly-spec.js", - "test:describeWithDOMSkip": "mocha --compilers js:babel/register --recursive src/**/__tests__/describeWithDOM/describeWithDOMSkip-spec.js", + "test:describeWithDOMOnly": "mocha --compilers js:babel/register --recursive src/**/__tests__/describeWithDOM/describeWithDOMOnly-spec.js", + "test:describeWithDOMSkip": "mocha --compilers js:babel/register --recursive src/**/__tests__/describeWithDOM/describeWithDOMSkip-spec.js", "test:all": "npm run react:13 && npm test && npm run test:describeWithDOMOnly && npm run test:describeWithDOMSkip && npm run react:14 && npm test && npm run test:describeWithDOMOnly && npm run test:describeWithDOMSkip", "react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils", "react:13": "npm run react:clean && npm i react@0.13", diff --git a/src/__tests__/ReactWrapper-spec.js b/src/__tests__/ReactWrapper-spec.js index 168957a05..10efa5d2b 100644 --- a/src/__tests__/ReactWrapper-spec.js +++ b/src/__tests__/ReactWrapper-spec.js @@ -5,8 +5,8 @@ import { mount, render, ReactWrapper, + describeWithDOM, } from '../'; -import { describeWithDOM } from '../describeWithDOM'; import { describeIf } from './_helpers'; import { REACT013 } from '../version'; diff --git a/src/__tests__/Utils-spec.js b/src/__tests__/Utils-spec.js index fddec7ac3..49a9513b8 100644 --- a/src/__tests__/Utils-spec.js +++ b/src/__tests__/Utils-spec.js @@ -13,11 +13,9 @@ import { mapNativeEventNames, } from '../Utils'; import { + describeWithDOM, mount, } from '../'; -import { - describeWithDOM, -} from '../describeWithDOM'; describe('Utils', () => { diff --git a/src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js b/src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js index b54e0b83e..10a375bf2 100644 --- a/src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js +++ b/src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { describeWithDOM } from '../../describeWithDOM'; +import { describeWithDOM } from '../..'; describe('describeWithDOM', () => { describe('.only()', () => { diff --git a/src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js b/src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js index 7c348700f..6c4738fdc 100644 --- a/src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js +++ b/src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js @@ -1,11 +1,11 @@ import { expect } from 'chai'; -import { describeWithDOM } from '../../describeWithDOM'; +import { describeWithDOM } from '../..'; describe('describeWithDOM', () => { describe('.skip()', () => { describeWithDOM.skip('will skip tests called with skip', () => { it('will not run this test', () => { - // purposefully failing test that won't be run + // purposefully failing test that won't be run expect(true).to.equal(false); }); }); diff --git a/src/index.js b/src/index.js index 3e0c5c68f..8e9e261d5 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import cheerio from 'cheerio'; import Sinon from 'sinon'; import ReactWrapper from './ReactWrapper'; import ShallowWrapper from './ShallowWrapper'; +import { describeWithDOM } from './describeWithDOM'; import { onPrototype } from './Utils'; import { renderToStaticMarkup } from './react-compat'; @@ -86,3 +87,4 @@ export function render(node) { export { ShallowWrapper as ShallowWrapper }; export { ReactWrapper as ReactWrapper }; +export { describeWithDOM as describeWithDOM };