Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State: Remove subtree Makefiles in favor of single test runner #3773

Merged
merged 6 commits into from
Mar 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/lib/react-test-env-setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ module.exports = function( markup, features ) {
global.XMLHttpRequest = window.XMLHttpRequest;
}
};

module.exports.cleanup = function() {
delete global.document;
delete global.window;
delete global.navigator;
delete global.Element;
delete global.history;
delete global.localStorage;
delete global.XMLHttpRequest;
};
7 changes: 5 additions & 2 deletions client/state/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ BASE_DIR := $(NODE_BIN)/../..
NODE_PATH := $(BASE_DIR)/client

test:
@NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register,js:babel/register --reporter $(REPORTER)
@NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register,js:babel/register --reporter $(REPORTER) $(addprefix --grep ,$(GREP))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with this a bit too, and came up with:

REPORTER ?= spec
NODE_BIN := $(shell npm bin)
MOCHA ?= $(NODE_BIN)/mocha
BASE_DIR := $(NODE_BIN)/../..
NODE_PATH := $(BASE_DIR)/client
FILE = "./test"
test:
    @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register,js:babel/register --reporter $(REPORTER) $(FILE)

.PHONY: test

With single test usage:

make test FILE=/Users/kerryliu/checkouts/wp-calypso/client/state/test/initial-state.js

The only downside is we don't get the setup/cleanup from the index.js file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gwwar: I think we might be able to do something with package.json scripts, as npm will automatically traverse up to the closest package.json. The idea would be to specify the test as running Mocha with all of our environment variables. This could be in a package.json in client/state, or in the root package.json, so long as we detect whether the current working directory is outside the project root.

Then, running cd client/state/sites/plans && npm test would only run the site plans tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only downside is we don't get the setup/cleanup from the index.js file.

That seems like a big downside?

Maybe something to bake into a custom runner at the root? Only add files that match a glob, but always add the root, which has setup / teardown.


.PHONY: test
test-%:
@GREP="state $*" make test

.PHONY: test test-%
10 changes: 0 additions & 10 deletions client/state/application/Makefile

This file was deleted.

10 changes: 0 additions & 10 deletions client/state/comments/Makefile

This file was deleted.

11 changes: 1 addition & 10 deletions client/state/comments/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
import nock from 'nock';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import Chai, { expect } from 'chai';
import { expect } from 'chai';
import Immutable from 'immutable';

/**
Expand Down Expand Up @@ -34,8 +33,6 @@ import {
NUMBER_OF_COMMENTS_PER_FETCH
} from '../constants'

Chai.use( sinonChai );

const MANY_COMMENTS_POST = {
siteId: 91750058,
postId: 287
Expand All @@ -44,14 +41,8 @@ const MANY_COMMENTS_POST = {
const API_DOMAIN = 'https://public-api.wordpress.com:443';

describe( 'actions', () => {
before( () => {
// make sure all requests are mocked
nock.disableNetConnect();
} );

after( () => {
nock.cleanAll();
nock.enableNetConnect();
} );

describe( '#receivePost()', () => {
Expand Down
10 changes: 0 additions & 10 deletions client/state/current-user/Makefile

This file was deleted.

10 changes: 0 additions & 10 deletions client/state/notices/Makefile

This file was deleted.

10 changes: 0 additions & 10 deletions client/state/plugins/wporg/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions client/state/plugins/wporg/test/test-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe( 'WPorg Data Actions', function() {
} );

after( function() {
mockery.deregisterAll();
mockery.disable();
} );

Expand Down
10 changes: 0 additions & 10 deletions client/state/post-types/Makefile

This file was deleted.

13 changes: 2 additions & 11 deletions client/state/post-types/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
import nock from 'nock';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import Chai, { expect } from 'chai';
import { expect } from 'chai';

/**
* Internal dependencies
Expand All @@ -23,16 +22,12 @@ import {
describe( 'actions', () => {
const spy = sinon.spy();

before( () => {
Chai.use( sinonChai );
} );

beforeEach( () => {
spy.reset();
} );

after( () => {
nock.restore();
nock.cleanAll();
} );

describe( '#receivePostTypes()', () => {
Expand Down Expand Up @@ -68,10 +63,6 @@ describe( 'actions', () => {
} );
} );

after( () => {
nock.cleanAll();
} );

it( 'should dispatch fetch action when thunk triggered', () => {
requestPostTypes( 2916284 )( spy );

Expand Down
4 changes: 1 addition & 3 deletions client/state/post-types/test/reducer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* External dependencies
*/
import Chai, { expect } from 'chai';
import { expect } from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import deepFreeze from 'deep-freeze';

/**
Expand All @@ -21,7 +20,6 @@ import { requesting, items } from '../reducer';

describe( 'reducer', () => {
before( () => {
Chai.use( sinonChai );
sinon.stub( console, 'warn' );
} );

Expand Down
10 changes: 0 additions & 10 deletions client/state/posts/Makefile

This file was deleted.

21 changes: 2 additions & 19 deletions client/state/posts/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
import nock from 'nock';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import Chai, { expect } from 'chai';
import { expect } from 'chai';

/**
* Internal dependencies
Expand All @@ -31,16 +30,12 @@ import {
describe( 'actions', () => {
const spy = sinon.spy();

before( () => {
Chai.use( sinonChai );
} );

beforeEach( () => {
spy.reset();
} );

after( () => {
nock.restore();
nock.cleanAll();
} );

describe( '#receivePost()', () => {
Expand Down Expand Up @@ -92,10 +87,6 @@ describe( 'actions', () => {
} );
} );

after( () => {
nock.cleanAll();
} );

it( 'should dispatch fetch action when thunk triggered', () => {
requestSitePosts( 2916284 )( spy );

Expand Down Expand Up @@ -173,10 +164,6 @@ describe( 'actions', () => {
} );
} );

after( () => {
nock.cleanAll();
} );

it( 'should dispatch posts receive action when request completes', () => {
return requestPosts()( spy ).then( () => {
expect( spy ).to.have.been.calledWith( {
Expand All @@ -203,10 +190,6 @@ describe( 'actions', () => {
} );
} );

after( () => {
nock.cleanAll();
} );

it( 'should dispatch request action when thunk triggered', () => {
requestSitePost( 2916284, 413 )( spy );

Expand Down
10 changes: 0 additions & 10 deletions client/state/receipts/Makefile

This file was deleted.

10 changes: 0 additions & 10 deletions client/state/sharing/publicize/Makefile

This file was deleted.

10 changes: 2 additions & 8 deletions client/state/sharing/publicize/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
import nock from 'nock';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import Chai, { expect } from 'chai';
import { expect } from 'chai';

/**
* Internal dependencies
Expand All @@ -20,11 +19,6 @@ import {
failConnectionsRequest
} from '../actions';

/**
* Test setup
*/
Chai.use( sinonChai );

describe( '#fetchConnections()', () => {
const spy = sinon.spy();

Expand All @@ -49,7 +43,7 @@ describe( '#fetchConnections()', () => {
} );

after( () => {
nock.restore();
nock.cleanAll();
} );

it( 'should dispatch fetch action when thunk triggered', () => {
Expand Down
10 changes: 0 additions & 10 deletions client/state/site-settings/exporter/Makefile

This file was deleted.

10 changes: 2 additions & 8 deletions client/state/site-settings/exporter/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
import nock from 'nock';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import Chai, { expect } from 'chai';
import { expect } from 'chai';

/**
* Internal dependencies
Expand Down Expand Up @@ -32,11 +31,6 @@ import {
SAMPLE_EXPORT_FAILED_RESPONSE,
} from './sample-data';

/**
* Test setup
*/
Chai.use( sinonChai );

describe( 'actions', () => {
const spy = sinon.spy();
const getState = () => ( {
Expand All @@ -63,7 +57,7 @@ describe( 'actions', () => {
} );

after( () => {
nock.restore();
nock.cleanAll();
} );

describe( '#advancedSettingsFetch()', () => {
Expand Down
10 changes: 0 additions & 10 deletions client/state/sites/Makefile

This file was deleted.

10 changes: 0 additions & 10 deletions client/state/sites/plans/Makefile

This file was deleted.

10 changes: 0 additions & 10 deletions client/state/support/Makefile

This file was deleted.

Loading