Skip to content

Instantly share code, notes, and snippets.

@pcothenet
Last active January 14, 2017 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcothenet/106472745f45ec0a515f171070ab5eb5 to your computer and use it in GitHub Desktop.
Save pcothenet/106472745f45ec0a515f171070ab5eb5 to your computer and use it in GitHub Desktop.
madkudu.js tests
File % Stmts % Branch % Funcs % Lines Uncovered Lines
lib/ 71.52 50.94 60.36 73.89
cookie.js 94.87 90 100 94.59 80,115
entity.js 100 92.5 100 100
form.js 23.57 6.06 2.86 24.44 ... 271,277,278
group.js 100 100 100 100
index.js 69.23 66.67 100 75 38,39,40
madkudu.js 87.3 65.88 96.43 93.57 ... 251,417,418
memory.js 100 100 100 100
pageDefaults.js 84.21 40 100 88.24 38,39
store.js 88 75 100 100
user.js 61.33 30.56 35.71 61.97 ... 192,193,195
lib/predictions/ 50 100 0 50
default.js 50 100 0 50 3,7
------------------ ---------- ---------- ---------- ---------- ----------------
All files 71.38 50.94 59.82 73.72
------------------ ---------- ---------- ---------- ---------- ----------------
'use strict';
const CI = process.env.CI;
const DEV = process.env.DEV;
const webpack = require('webpack');
const _ = require('lodash');
const DEFAULT_WEBPACK_CONFIG = require('./webpack.config');
const test_type = process.env.TESTS || 'unit';
console.log(test_type);
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// list of files / patterns to load in the browser
files: (function () {
if (test_type === 'compiled') {
return [
{ pattern: 'test/support/setup.js', watched: true },
{ pattern: 'dist/3354/madkudu.js', watched: true },
{ pattern: 'test/support/teardown.js', watched: true },
{ pattern: 'test/compiled/*.js', watched: true }
];
} else {
return [
{ pattern: 'test/support/setup.js', watched: true },
{ pattern: 'test/unit/*.js', watched: true },
{ pattern: 'test/support/teardown.js', watched: true }
];
}
})(),
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha'],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/**/*.js': ['webpack', 'sourcemap'],
'test/**/support/*.js': ['webpack'],
},
webpack: (function () {
const webpack_conf = _.cloneDeep(DEFAULT_WEBPACK_CONFIG);
webpack_conf.output = {
libraryTarget: 'var'
};
webpack_conf.plugins.push(
new webpack.DefinePlugin({
__3313__: JSON.stringify(false),
__CAMPAIGNS__: JSON.stringify(false),
__SETTINGS__: JSON.stringify({})
})
);
return webpack_conf;
})(),
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'coverage'],
// 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: DEV === 'true',
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: (function () {
if (CI === 'true') {
return ['Chrome', 'Firefox'];
} else if (DEV === 'true') {
return ['Chrome'];
} else {
return ['Chrome', 'Firefox', 'Safari'];
}
})(),
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: !(DEV === 'true'),
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
client: {
mocha: {
grep: process.env.GREP,
reporter: 'html',
timeout: 10000
}
},
coverageReporter: {
dir: 'dist/coverage/' + test_type,
reporters: [
{ type: 'text' },
{ type: 'html' },
{ type: 'json' }
]
}
});
};
'use strict';
var chai = require('chai');
var expect = chai.expect;
const _ = require('lodash');
describe('window', function () {
it('should change only the madkudu property',function () {
const modified_properties = _.keys(_.omit(window.mk_window_changes,['_', 'onerror']));
/* _ and onerror are artefacts of the test runner */
expect(modified_properties).to.have.members(['madkudu']);
it('should not modify window.addEventListener', function () {
expect(window.addEventListener.toString()).to.not.equal(window.madkudu.addEventListener.toString());
});
});
});
describe('window.madkudu', function () {
it('should have loaded madkudu into window.madkudu', function () {
expect(window.madkudu).to.be.an('object');
});
it('should instantiate options and settings', function () {
var madkudu = window.madkudu;
expect(madkudu.VERSION).to.be.a('string');
// Objects
expect(madkudu.options).to.be.an('object');
expect(madkudu.settings).to.be.an('object');
expect(madkudu.settings.api_key).to.be.an('string');
// Array
expect(madkudu.forms).to.be.an('array');
});
});
describe('settings', function () {
var madkudu = window.madkudu;
it('should instantiate the settings on load', function () {
expect(madkudu.settings).to.be.an('object');
});
it('should have properties', function () {
expect(madkudu.settings.api_key).to.be.a('string');
expect(madkudu.settings.form).to.be.an('object');
expect(madkudu.settings.tenant).to.be.a('number');
expect(madkudu.settings.form.active).to.be.a('boolean');
expect(madkudu.settings.form.campaigns).to.be.an('array');
expect(madkudu.settings.form.has_campaigns).to.be.an('boolean');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment