-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from DomoApps/feat/DAS-4146-test-framework-rest…
…ructuring Feat/das 4146 test framework restructuring
- Loading branch information
Showing
5 changed files
with
50 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,46 @@ | ||
const path = require('path'); | ||
module.exports = config => { | ||
// load external cdn dependencies | ||
const pkg = require('../package.json'); | ||
const cdns = Object.values(pkg.cdnDependencies); | ||
|
||
// load webpack config here for for webpack preprocessor | ||
const webpackConfig = require('../webpack.config'); | ||
delete webpackConfig.devtool; | ||
webpackConfig.cache = true; | ||
// entry file that bundles all the test files | ||
const testEntryFile = './other/tests.js'; | ||
|
||
let file; | ||
const webpackConfig = require('../webpack.config'); | ||
const webpackLoaders = webpackConfig.module.loaders; | ||
|
||
const cdns = Object.values(require('../package.json').cdnDependencies); | ||
|
||
const entry = [ | ||
...cdns, | ||
'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.3/angular-mocks.js', | ||
]; | ||
const preprocessors = {}; | ||
for (const chunk in webpackConfig.entry) { | ||
if ({}.hasOwnProperty.call(webpackConfig.entry, chunk)) { | ||
file = path.resolve(webpackConfig.context, webpackConfig.entry[chunk]); | ||
entry.push(file); | ||
preprocessors[file] = ['webpack']; | ||
} | ||
} | ||
|
||
module.exports = (config) => { | ||
config.set({ | ||
basePath: './', | ||
frameworks: ['mocha', 'chai', 'sinon'], | ||
files: entry, | ||
webpack: webpackConfig, | ||
|
||
files: [ | ||
...cdns, | ||
testEntryFile | ||
], | ||
preprocessors: { | ||
[testEntryFile]: ['webpack', 'sourcemap'] | ||
}, | ||
webpack: { | ||
module: { | ||
loaders: webpackLoaders | ||
}, | ||
devtool: 'inline-source-map' | ||
}, | ||
webpackMiddleware: { | ||
noInfo: true | ||
}, | ||
|
||
// list of files to exclude | ||
exclude: [ | ||
'src/switcher.js' | ||
], | ||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: preprocessors, | ||
|
||
// how the test success/failure status is reported: | ||
reporters: ['dots'], | ||
port: 9876, | ||
colors: true, | ||
autoWatch: true, | ||
logLevel: config.LOG_ERROR, | ||
browsers: ['PhantomJS', 'Chrome', 'Firefox', 'Safari'], | ||
plugins: [ | ||
require('karma-webpack'), | ||
'karma-coverage', | ||
'karma-phantomjs-launcher', | ||
'karma-sourcemap-loader', | ||
'karma-chrome-launcher', | ||
'karma-firefox-launcher', | ||
'karma-safari-launcher', | ||
'karma-mocha', | ||
'karma-chai', | ||
'karma-sinon', | ||
], | ||
logLevel: config.LOG_ERROR | ||
'karma-webpack' | ||
] | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require('angular-mocks/ngMock'); | ||
const testFiles = require.context('../src', true, /\.spec\.js$/); | ||
const ngModule = angular.module('da.test', []); | ||
testFiles.keys().forEach(key => { testFiles(key)(ngModule); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
/** | ||
* Here you can write tests for you service | ||
* @param {Angular Module} ngModule The module with the service | ||
*/ | ||
module.exports = ngModule => { | ||
const factory = require('./da-events.factory.js'); | ||
|
||
//console.log(ngModule.name); | ||
factory(ngModule); | ||
|
||
describe('factory:daEvents', () => { | ||
let daEvents; | ||
let callbackSpy; | ||
|
||
beforeEach(window.module(ngModule.name)); | ||
|
||
beforeEach(inject(_daEvents_ => { | ||
daEvents = _daEvents_; | ||
})); | ||
beforeEach(() => { | ||
callbackSpy = sinon.spy(); | ||
}); | ||
|
||
it('should exist emit registered events', () => { | ||
const spy = sinon.spy(); | ||
daEvents.on('app:loaded', spy); | ||
it('should emit registered events', () => { | ||
callbackSpy = sinon.spy(); | ||
daEvents.on('app:loaded', callbackSpy); | ||
daEvents.trigger('app:loaded'); | ||
expect(spy.calledOnce).to.equal(true); | ||
expect(callbackSpy.calledOnce).to.equal(true); | ||
}); | ||
|
||
it('should not allow a listener to be setup for event that is not in registry', () => { | ||
const spy = sinon.spy(); | ||
daEvents.on('not:in:registry', spy); | ||
daEvents.trigger('not:in:registry'); | ||
expect(spy.calledOnce).to.equal(false); | ||
callbackSpy = sinon.spy(); | ||
expect(daEvents.on('not:in:registry', callbackSpy)).to.equal(null); | ||
expect(daEvents.trigger('not:in:registry')).to.equal(null); | ||
expect(callbackSpy.calledOnce).to.equal(false); | ||
}); | ||
}); | ||
}; |