Merge pull request #590 from weaveworks/jest

Migrate JS testing to Jest
This commit is contained in:
David
2015-10-27 10:20:54 +00:00
11 changed files with 49 additions and 115 deletions

View File

@@ -65,13 +65,13 @@ static: client/build/app.js
esc -o app/static.go -prefix client/build client/build
ifeq ($(BUILD_IN_CONTAINER),true)
client/build/app.js: client/app/scripts/*
client/build/app.js: $(shell find client/app/scripts -type f)
mkdir -p client/build
$(SUDO) docker run -ti $(RM) -v $(shell pwd)/client/app:/home/weave/app \
-v $(shell pwd)/client/build:/home/weave/build \
$(SCOPE_UI_BUILD_IMAGE) npm run build
client-test: client/test/*
client-test: $(shell find client/app/scripts -type f)
$(SUDO) docker run -ti $(RM) -v $(shell pwd)/client/app:/home/weave/app \
-v $(shell pwd)/client/test:/home/weave/test \
$(SCOPE_UI_BUILD_IMAGE) npm test

1
client/.gitignore vendored
View File

@@ -1,3 +1,4 @@
node_modules
build/app.js
build/*[woff2?|ttf|eot|svg]
coverage/

View File

@@ -1,5 +1,6 @@
FROM node:0.10
WORKDIR /home/weave
COPY package.json /home/weave/
RUN npm install
# Dont install optional developer tools
RUN npm install --no-optional
COPY webpack.local.config.js webpack.production.config.js server.js .eslintrc /home/weave/

View File

@@ -1,3 +1,7 @@
jest.dontMock('../node-details.js');
jest.dontMock('../../mixins/node-color-mixin');
jest.dontMock('../../utils/title-utils');
describe('NodeDetails', () => {
let NodeDetails;
let nodes;
@@ -28,4 +32,4 @@ describe('NodeDetails', () => {
expect(title.getDOMNode().textContent).toBe('Node 1');
});
});
});

View File

@@ -1,7 +1,11 @@
jest.dontMock('../../constants/action-types');
jest.dontMock('../app-store');
// Appstore test suite using Jasmine matchers
describe('AppStore', function() {
const ActionTypes = require('../../constants/action-types');
let AppDispatcher;
let AppStore;
let registeredCallback;
@@ -121,10 +125,9 @@ describe('AppStore', function() {
};
beforeEach(function() {
// clear AppStore singleton
delete require.cache[require.resolve('../app-store')];
AppDispatcher = require('../../dispatcher/app-dispatcher');
AppStore = require('../app-store');
registeredCallback = AppStore.registeredCallback;
registeredCallback = AppDispatcher.register.mock.calls[0][0];
});
// topology tests
@@ -309,4 +312,4 @@ describe('AppStore', function() {
expect(AppStore.getAdjacentNodes().size).toEqual(0);
});
});
});

View File

@@ -19,10 +19,9 @@
"materialize-css": "^0.96.1",
"object-assign": "^2.0.0",
"page": "^1.6.3",
"react": "^0.13.3",
"react": "0.13.3",
"react-motion": "^0.2.7",
"react-tap-event-plugin": "^0.1.7",
"react-tween-state": "0.0.5",
"reqwest": "~1.1.5",
"timely": "^0.1.0"
},
@@ -30,47 +29,61 @@
"autoprefixer-core": "^5.2.0",
"babel-core": "^5.4.7",
"babel-eslint": "^3.1.9",
"babel-jest": "^5.3.0",
"babel-loader": "^5.1.3",
"css-loader": "^0.14.4",
"eslint": "^0.21.2",
"eslint-loader": "^0.11.2",
"eslint-plugin-jasmine": "^1.0.0",
"eslint-plugin-react": "^2.3.0",
"express": "^4.13.3",
"express-http-proxy": "^0.6.0",
"file-loader": "^0.8.4",
"istanbul-instrumenter-loader": "^0.1.3",
"jasmine-core": "^2.3.4",
"jest-cli": "0.4.19",
"json-loader": "^0.5.2",
"karma": "^0.13.3",
"karma-cli": "0.0.4",
"karma-coverage": "^0.4.2",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.1.4",
"karma-webpack": "^1.7.0",
"less": "^2.5.1",
"less-loader": "^2.2.0",
"phantomjs": "^1.9.18",
"postcss-loader": "^0.4.3",
"proxy-middleware": "^0.13.1",
"react-hot-loader": "^1.2.8",
"react-tools": "^0.13.3",
"style-loader": "^0.12.3",
"url": "^0.10.3",
"url-loader": "^0.5.6",
"webpack": "^1.9.10",
"webpack": "^1.9.10"
},
"optionalDependencies": {
"express": "^4.13.3",
"express-http-proxy": "^0.6.0",
"proxy-middleware": "^0.13.1",
"react-hot-loader": "^1.2.8",
"webpack-dev-server": "^1.10.1"
},
"scripts": {
"postinstall": "npm run build",
"build": "webpack -p --config webpack.production.config.js",
"start": "node server.js",
"start-production": "NODE_ENV=production node server.js",
"test": "karma start test/karma.conf.js --single-run",
"test": "jest --coverage",
"coveralls": "cat coverage/lcov.info | coveralls",
"lint": "eslint app",
"clean": "rm build/app.js"
},
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"testFileExtensions": [
"es6",
"js"
],
"moduleFileExtensions": [
"js",
"json",
"es6"
],
"unmockedModulePathPatterns": [
"react",
"immutable",
"d3",
"keymirror",
"object-assign",
"lodash",
"debug"
]
},
"engines": {
"node": ">=0.10.0"
}

View File

@@ -1,9 +0,0 @@
# Testing
Scope unit testing is done unsing Karma/Jasmine. (Jest was too big and slow.)
To run tests, do `npm test` in the toplevel directory.
The tests are placed in `__tests__` directories, relative to what they are testing.
For more info see [Testing Flux Apps with Karma](http://kentor.me/posts/testing-react-and-flux-applications-with-karma-and-webpack/)

View File

@@ -1,49 +0,0 @@
module.exports = function(config) {
config.set({
browsers: [
'PhantomJS'
],
files: [
'./polyfill.js',
{
pattern: 'tests.webpack.js',
watched: false
}
],
frameworks: [
'jasmine'
],
preprocessors: {
'tests.webpack.js': ['webpack']
},
reporters: [
'dots',
'coverage'
],
coverageReporter: {
type: 'text-summary'
},
webpack: {
module: {
loaders: [
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
],
postLoaders: [
{
test: /\.js$/,
exclude: /(test|node_modules|bower_components)\//,
loader: 'istanbul-instrumenter'
}
]
},
watch: true
},
webpackServer: {
noInfo: true
}
});
};

View File

@@ -1,21 +0,0 @@
/**
* Function.prototype.bind polyfill used by PhantomJS
*/
if (typeof Function.prototype.bind != 'function') {
Function.prototype.bind = function bind(obj) {
var args = Array.prototype.slice.call(arguments, 1),
self = this,
nop = function() {
},
bound = function() {
return self.apply(
this instanceof nop ? this : (obj || {}), args.concat(
Array.prototype.slice.call(arguments)
)
);
};
nop.prototype = this.prototype || {};
bound.prototype = new nop();
return bound;
};
}

View File

@@ -1,7 +0,0 @@
var ReactTools = require('react-tools');
module.exports = {
process: function(src) {
return ReactTools.transform(src);
}
};

View File

@@ -1,2 +0,0 @@
var context = require.context('../app/scripts', true, /-test\.js$/);
context.keys().forEach(context);