unit testing environment

This commit is contained in:
Eist 2017-08-25 08:42:53 +02:00
parent 41182abb6e
commit fbb10cc2c0
6 changed files with 138 additions and 1 deletions

View File

@ -0,0 +1,30 @@
import VNClientWebAccess from './web-access.js';
describe('some component', () => {
let instance;
var $scope;
var $http;
var vnApp = {showError: jasmine.createSpy('showError')};
beforeEach(() => {
instance = new VNClientWebAccess($scope, $http, vnApp);
});
it('should throw an error when password is empty', () => {
instance.newPassword = '';
instance.onPassChange('ACCEPT');
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords can't be empty`);
});
it('should throw an error when password repeat doesnt match', () => {
instance.newPassword = 'test';
instance.repeatPassword = 'notTheSame';
instance.onPassChange('ACCEPT');
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`);
});
it('', () => {
instance.newPassword = 'test';
instance.repeatPassword = 'notTheSame';
instance.onPassChange('ACCEPT');
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`);
});
});

5
client/test_index.js Normal file
View File

@ -0,0 +1,5 @@
// require all modules ending in ".spec" from the
// current directory and all subdirectories
var testsContext = require.context('./', true, /\.spec\.js$/);
testsContext.keys().forEach(testsContext);

9
jasmine.js Normal file
View File

@ -0,0 +1,9 @@
const Jasmine = require('jasmine');
const jasmine = new Jasmine();
jasmine.loadConfig({
spec_dir: '',
spec_files: ['*[Ss]pec.js']
});
jasmine.execute();

83
karma.conf.js Normal file
View File

@ -0,0 +1,83 @@
var webpackConfig = require('./webpack.config.js');
delete webpackConfig.entry;
delete webpackConfig.output;
webpackConfig.devtool = 'inline-source-map';
webpackConfig.plugins = [];
// Karma configuration
// Generated on Tue Aug 22 2017 13:37:43 GMT+0200 (CEST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
{pattern: 'client/test_index.js', watched: false}
],
// list of files to exclude
exclude: [],
webpack: webpackConfig,
webpackMiddleware: {
stats: 'errors-only'
},
webpackServer: {
noInfo: true
},
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'./client/test_index.js': ['webpack', 'sourcemap']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
plugins: [
'karma-jasmine',
'karma-webpack',
'karma-requirejs',
'karma-chrome-launcher',
'karma-browserify',
'karma-sourcemap-loader'
]
});
};

View File

@ -22,6 +22,7 @@
"validator": "^6.2.1" "validator": "^6.2.1"
}, },
"devDependencies": { "devDependencies": {
"angular-mocks": "^1.6.6",
"babel": "^6.5.2", "babel": "^6.5.2",
"babel-core": "^6.22.1", "babel-core": "^6.22.1",
"babel-loader": "^6.4.1", "babel-loader": "^6.4.1",
@ -42,10 +43,19 @@
"gulp-wrap": "^0.13.0", "gulp-wrap": "^0.13.0",
"gulp-yaml": "^1.0.1", "gulp-yaml": "^1.0.1",
"html-loader": "^0.4.4", "html-loader": "^0.4.4",
"jasmine": "^2.7.0",
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.1.0",
"karma-requirejs": "^1.1.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.4",
"merge-stream": "^1.0.1", "merge-stream": "^1.0.1",
"node-sass": "^3.11.0", "node-sass": "^3.11.0",
"pre-commit": "^1.1.3", "pre-commit": "^1.1.3",
"raw-loader": "*", "raw-loader": "*",
"requirejs": "^2.3.5",
"sass-loader": "^4.0.2", "sass-loader": "^4.0.2",
"style-loader": "^0.13.1", "style-loader": "^0.13.1",
"webpack": "^2.2.0", "webpack": "^2.2.0",

View File

@ -54,7 +54,7 @@ var config = {
}, },
plugins: [ plugins: [
new webpack.optimize.CommonsChunkPlugin({ new webpack.optimize.CommonsChunkPlugin({
names: ['bundle.vendor', 'bundle.manifest'] names: ['bundle.vendor', 'bundle.manifest'],
}) })
], ],
devtool: 'source-map' devtool: 'source-map'