Merge pull request #80 from netlify/jest
Switched to Jest testing framework.
This commit is contained in:
commit
3a15913014
@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack-dev-server --config webpack.dev.js",
|
"start": "webpack-dev-server --config webpack.dev.js",
|
||||||
"test": "NODE_ENV=test mocha --recursive --compilers js:babel-register --require ./test/setup.js",
|
"test": "NODE_ENV=test jest",
|
||||||
"test:watch": "npm test -- --watch",
|
"test:watch": "npm test -- --watch",
|
||||||
"build": "webpack --config webpack.config.js",
|
"build": "webpack --config webpack.config.js",
|
||||||
"storybook": "start-storybook -p 9001",
|
"storybook": "start-storybook -p 9001",
|
||||||
@ -39,7 +39,6 @@
|
|||||||
"babel-plugin-transform-object-rest-spread": "^6.5.0",
|
"babel-plugin-transform-object-rest-spread": "^6.5.0",
|
||||||
"babel-preset-es2015": "^6.5.0",
|
"babel-preset-es2015": "^6.5.0",
|
||||||
"babel-preset-react": "^6.5.0",
|
"babel-preset-react": "^6.5.0",
|
||||||
"babel-register": "^6.5.2",
|
|
||||||
"babel-runtime": "^6.5.0",
|
"babel-runtime": "^6.5.0",
|
||||||
"css-loader": "^0.23.1",
|
"css-loader": "^0.23.1",
|
||||||
"eslint": "^3.5.0",
|
"eslint": "^3.5.0",
|
||||||
@ -49,9 +48,9 @@
|
|||||||
"file-loader": "^0.8.5",
|
"file-loader": "^0.8.5",
|
||||||
"immutable": "^3.7.6",
|
"immutable": "^3.7.6",
|
||||||
"imports-loader": "^0.6.5",
|
"imports-loader": "^0.6.5",
|
||||||
|
"jest-cli": "^15.1.1",
|
||||||
"js-yaml": "^3.5.3",
|
"js-yaml": "^3.5.3",
|
||||||
"lint-staged": "^3.0.2",
|
"lint-staged": "^3.0.2",
|
||||||
"mocha": "^2.4.5",
|
|
||||||
"moment": "^2.11.2",
|
"moment": "^2.11.2",
|
||||||
"node-sass": "^3.10.0",
|
"node-sass": "^3.10.0",
|
||||||
"normalizr": "^2.0.0",
|
"normalizr": "^2.0.0",
|
||||||
|
@ -24,8 +24,9 @@ export const ENTRY_PERSIST_FAILURE = 'ENTRY_PERSIST_FAILURE';
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Simple Action Creators (Internal)
|
* Simple Action Creators (Internal)
|
||||||
|
* We still need to export them for tests
|
||||||
*/
|
*/
|
||||||
function entryLoading(collection, slug) {
|
export function entryLoading(collection, slug) {
|
||||||
return {
|
return {
|
||||||
type: ENTRY_REQUEST,
|
type: ENTRY_REQUEST,
|
||||||
payload: {
|
payload: {
|
||||||
@ -35,7 +36,7 @@ function entryLoading(collection, slug) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function entryLoaded(collection, entry) {
|
export function entryLoaded(collection, entry) {
|
||||||
return {
|
return {
|
||||||
type: ENTRY_SUCCESS,
|
type: ENTRY_SUCCESS,
|
||||||
payload: {
|
payload: {
|
||||||
@ -45,7 +46,7 @@ function entryLoaded(collection, entry) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function entriesLoading(collection) {
|
export function entriesLoading(collection) {
|
||||||
return {
|
return {
|
||||||
type: ENTRIES_REQUEST,
|
type: ENTRIES_REQUEST,
|
||||||
payload: {
|
payload: {
|
||||||
@ -54,7 +55,7 @@ function entriesLoading(collection) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function entriesLoaded(collection, entries, pagination) {
|
export function entriesLoaded(collection, entries, pagination) {
|
||||||
return {
|
return {
|
||||||
type: ENTRIES_SUCCESS,
|
type: ENTRIES_SUCCESS,
|
||||||
payload: {
|
payload: {
|
||||||
@ -65,7 +66,7 @@ function entriesLoaded(collection, entries, pagination) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function entriesFailed(collection, error) {
|
export function entriesFailed(collection, error) {
|
||||||
return {
|
return {
|
||||||
type: ENTRIES_FAILURE,
|
type: ENTRIES_FAILURE,
|
||||||
error: 'Failed to load entries',
|
error: 'Failed to load entries',
|
||||||
@ -74,7 +75,7 @@ function entriesFailed(collection, error) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function entryPersisting(collection, entry) {
|
export function entryPersisting(collection, entry) {
|
||||||
return {
|
return {
|
||||||
type: ENTRY_PERSIST_REQUEST,
|
type: ENTRY_PERSIST_REQUEST,
|
||||||
payload: {
|
payload: {
|
||||||
@ -84,7 +85,7 @@ function entryPersisting(collection, entry) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function entryPersisted(collection, entry) {
|
export function entryPersisted(collection, entry) {
|
||||||
return {
|
return {
|
||||||
type: ENTRY_PERSIST_SUCCESS,
|
type: ENTRY_PERSIST_SUCCESS,
|
||||||
payload: {
|
payload: {
|
||||||
@ -94,7 +95,7 @@ function entryPersisted(collection, entry) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function entryPersistFail(collection, entry, error) {
|
export function entryPersistFail(collection, entry, error) {
|
||||||
return {
|
return {
|
||||||
type: ENTRIES_FAILURE,
|
type: ENTRIES_FAILURE,
|
||||||
error: 'Failed to persist entry',
|
error: 'Failed to persist entry',
|
||||||
@ -102,7 +103,7 @@ function entryPersistFail(collection, entry, error) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function emmptyDraftCreated(entry) {
|
export function emmptyDraftCreated(entry) {
|
||||||
return {
|
return {
|
||||||
type: DRAFT_CREATE_EMPTY,
|
type: DRAFT_CREATE_EMPTY,
|
||||||
payload: entry
|
payload: entry
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import Immutable from 'immutable';
|
import Immutable from 'immutable';
|
||||||
import { authenticating, authenticate, authError } from '../../src/actions/auth';
|
import { authenticating, authenticate, authError } from '../../actions/auth';
|
||||||
import { auth } from '../../src/reducers/auth';
|
import auth from '../auth';
|
||||||
|
|
||||||
describe('auth', () => {
|
describe('auth', () => {
|
||||||
it('should handle an empty state', () => {
|
it('should handle an empty state', () => {
|
26
src/reducers/__tests__/collections.spec.js
Normal file
26
src/reducers/__tests__/collections.spec.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import expect from 'expect';
|
||||||
|
import { OrderedMap, fromJS } from 'immutable';
|
||||||
|
import { configLoaded } from '../../actions/config';
|
||||||
|
import collections from '../collections';
|
||||||
|
|
||||||
|
describe('collections', () => {
|
||||||
|
it('should handle an empty state', () => {
|
||||||
|
expect(
|
||||||
|
collections(undefined, {})
|
||||||
|
).toEqual(
|
||||||
|
null
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should load the collections from the config', () => {
|
||||||
|
expect(
|
||||||
|
collections(undefined, configLoaded({ collections: [
|
||||||
|
{ name: 'posts', folder: '_posts', fields: [{ name: 'title', widget: 'string' }] }
|
||||||
|
] }))
|
||||||
|
).toEqual(
|
||||||
|
OrderedMap({
|
||||||
|
posts: fromJS({ name: 'posts', folder: '_posts', fields: [{ name: 'title', widget: 'string' }] })
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@ -1,7 +1,7 @@
|
|||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import Immutable from 'immutable';
|
import Immutable from 'immutable';
|
||||||
import { configLoaded, configLoading, configFailed } from '../../src/actions/config';
|
import { configLoaded, configLoading, configFailed } from '../../actions/config';
|
||||||
import { config } from '../../src/reducers/config';
|
import config from '../config';
|
||||||
|
|
||||||
describe('config', () => {
|
describe('config', () => {
|
||||||
it('should handle an empty state', () => {
|
it('should handle an empty state', () => {
|
47
src/reducers/__tests__/entries.spec.js
Normal file
47
src/reducers/__tests__/entries.spec.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import expect from 'expect';
|
||||||
|
import { Map, OrderedMap, fromJS } from 'immutable';
|
||||||
|
import { entriesLoading, entriesLoaded } from '../../actions/entries';
|
||||||
|
import reducer from '../entries';
|
||||||
|
|
||||||
|
describe('entries', () => {
|
||||||
|
it('should mark entries as fetching', () => {
|
||||||
|
const state = OrderedMap({
|
||||||
|
'posts': Map({ name: 'posts' })
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
reducer(state, entriesLoading(Map({ name: 'posts' })))
|
||||||
|
).toEqual(
|
||||||
|
OrderedMap(fromJS({
|
||||||
|
'posts': { name: 'posts' },
|
||||||
|
'pages': {
|
||||||
|
'posts': { isFetching: true }
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle loaded entries', () => {
|
||||||
|
const state = OrderedMap({
|
||||||
|
'posts': Map({ name: 'posts' })
|
||||||
|
});
|
||||||
|
const entries = [{ slug: 'a', path: '' }, { slug: 'b', title: 'B' }];
|
||||||
|
expect(
|
||||||
|
reducer(state, entriesLoaded(Map({ name: 'posts' }), entries))
|
||||||
|
).toEqual(
|
||||||
|
OrderedMap(fromJS(
|
||||||
|
{
|
||||||
|
posts: { name: 'posts' },
|
||||||
|
entities: {
|
||||||
|
'posts.a': { slug: 'a', path: '', isFetching: false },
|
||||||
|
'posts.b': { slug: 'b', title: 'B', isFetching: false },
|
||||||
|
},
|
||||||
|
pages: {
|
||||||
|
posts: {
|
||||||
|
ids: ['a', 'b']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@ -1,54 +0,0 @@
|
|||||||
import expect from 'expect';
|
|
||||||
import { Map, OrderedMap, fromJS } from 'immutable';
|
|
||||||
import { configLoaded } from '../../src/actions/config';
|
|
||||||
import { entriesLoading, entriesLoaded } from '../../src/actions/entries';
|
|
||||||
import { collections } from '../../src/reducers/collections';
|
|
||||||
|
|
||||||
describe('collections', () => {
|
|
||||||
it('should handle an empty state', () => {
|
|
||||||
expect(
|
|
||||||
collections(undefined, {})
|
|
||||||
).toEqual(
|
|
||||||
null
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should load the collections from the config', () => {
|
|
||||||
expect(
|
|
||||||
collections(undefined, configLoaded({ collections: [
|
|
||||||
{ name: 'posts', folder: '_posts', fields: [{ name: 'title', widget: 'string' }] }
|
|
||||||
] }))
|
|
||||||
).toEqual(
|
|
||||||
OrderedMap({
|
|
||||||
posts: fromJS({ name: 'posts', folder: '_posts', fields: [{ name: 'title', widget: 'string' }] })
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should mark entries as loading', () => {
|
|
||||||
const state = OrderedMap({
|
|
||||||
'posts': Map({ name: 'posts' })
|
|
||||||
});
|
|
||||||
expect(
|
|
||||||
collections(state, entriesLoading(Map({ name: 'posts' })))
|
|
||||||
).toEqual(
|
|
||||||
OrderedMap({
|
|
||||||
'posts': Map({ name: 'posts', isFetching: true })
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle loaded entries', () => {
|
|
||||||
const state = OrderedMap({
|
|
||||||
'posts': Map({ name: 'posts' })
|
|
||||||
});
|
|
||||||
const entries = [{ slug: 'a', path: '' }, { slug: 'b', title: 'B' }];
|
|
||||||
expect(
|
|
||||||
collections(state, entriesLoaded(Map({ name: 'posts' }), entries))
|
|
||||||
).toEqual(
|
|
||||||
OrderedMap({
|
|
||||||
'posts': fromJS({ name: 'posts', entries: entries })
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
23
wallaby.config.js
Normal file
23
wallaby.config.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
process.env.BABEL_ENV = 'test';
|
||||||
|
|
||||||
|
module.exports = wallaby => ({
|
||||||
|
files: [
|
||||||
|
{ pattern: 'src/**/*.js' },
|
||||||
|
{ pattern: 'src/**/*.spec.js', ignore: true }
|
||||||
|
],
|
||||||
|
|
||||||
|
tests: [
|
||||||
|
{ pattern: 'src/**/*.spec.js' }
|
||||||
|
],
|
||||||
|
|
||||||
|
compilers: {
|
||||||
|
'src/**/*.js': wallaby.compilers.babel()
|
||||||
|
},
|
||||||
|
|
||||||
|
env: {
|
||||||
|
type: 'node',
|
||||||
|
runner: 'node'
|
||||||
|
},
|
||||||
|
|
||||||
|
testFramework: 'jest'
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user