forked from swimlane/ngx-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup test infrastructure (swimlane#5)
- Loading branch information
Showing
10 changed files
with
474 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* taken from angular2-webpack-starter | ||
*/ | ||
var path = require('path'); | ||
|
||
// Helper functions | ||
var ROOT = path.resolve(__dirname, '..'); | ||
|
||
function hasProcessFlag(flag) { | ||
return process.argv.join('').indexOf(flag) > -1; | ||
} | ||
|
||
function isWebpackDevServer() { | ||
return process.argv[1] && !! (/webpack-dev-server$/.exec(process.argv[1])); | ||
} | ||
|
||
function root(args) { | ||
args = Array.prototype.slice.call(arguments, 0); | ||
return path.join.apply(path, [ROOT].concat(args)); | ||
} | ||
|
||
function checkNodeImport(context, request, cb) { | ||
if (!path.isAbsolute(request) && request.charAt(0) !== '.') { | ||
cb(null, 'commonjs ' + request); return; | ||
} | ||
cb(); | ||
} | ||
|
||
exports.hasProcessFlag = hasProcessFlag; | ||
exports.isWebpackDevServer = isWebpackDevServer; | ||
exports.root = root; | ||
exports.checkNodeImport = checkNodeImport; |
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,70 @@ | ||
module.exports = function(config) { | ||
var testWebpackConfig = require('./webpack.test.js'); | ||
|
||
var configuration = { | ||
basePath: '', | ||
|
||
frameworks: ['jasmine'], | ||
|
||
// list of files to exclude | ||
exclude: [ ], | ||
|
||
/* | ||
* list of files / patterns to load in the browser | ||
* | ||
* we are building the test environment in ./spec-bundle.js | ||
*/ | ||
files: [ { pattern: './config/spec-bundle.js', watched: false } ], | ||
|
||
preprocessors: { './config/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] }, | ||
|
||
// Webpack Config at ./webpack.test.js | ||
webpack: testWebpackConfig, | ||
|
||
coverageReporter: { | ||
dir : 'coverage/', | ||
reporters: [ | ||
{ type: 'text-summary' }, | ||
{ type: 'json' }, | ||
{ type: 'html' } | ||
] | ||
}, | ||
|
||
// Webpack please don't spam the console when running in karma! | ||
webpackServer: { noInfo: true }, | ||
|
||
reporters: [ 'mocha', 'coverage' ], | ||
|
||
// web server port | ||
port: 9876, | ||
|
||
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, | ||
|
||
autoWatch: false, | ||
|
||
browsers: [ | ||
'Chrome' | ||
], | ||
|
||
customLaunchers: { | ||
Chrome_travis_ci: { | ||
base: 'Chrome', | ||
flags: ['--no-sandbox'] | ||
} | ||
}, | ||
|
||
singleRun: true | ||
}; | ||
|
||
if(process.env.TRAVIS){ | ||
configuration.browsers = ['Chrome_travis_ci']; | ||
} | ||
|
||
config.set(configuration); | ||
}; |
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,54 @@ | ||
/** | ||
* Adapted from the angular2-webpack-starter kit. | ||
* | ||
* This file creates a bundle for testing, since tests are also | ||
* written in ES6/Typescript. It's the entry point loaded by webpack.test.js | ||
*/ | ||
|
||
Error.stackTraceLimit = Infinity; | ||
|
||
require('core-js/es6'); | ||
require('core-js/es7/reflect'); | ||
|
||
// Typescript emit helpers polyfill | ||
require('ts-helpers'); | ||
|
||
require('zone.js/dist/zone'); | ||
require('zone.js/dist/long-stack-trace-zone'); | ||
require('zone.js/dist/jasmine-patch'); | ||
require('zone.js/dist/async-test'); | ||
require('zone.js/dist/fake-async-test'); | ||
require('zone.js/dist/sync-test'); | ||
|
||
// RxJS | ||
require('rxjs/Rx'); | ||
|
||
var testing = require('@angular/core/testing'); | ||
var browser = require('@angular/platform-browser-dynamic/testing'); | ||
|
||
testing.TestBed.initTestEnvironment( | ||
browser.BrowserDynamicTestingModule, | ||
browser.platformBrowserDynamicTesting()); | ||
|
||
/* | ||
* Ok, this is kinda crazy. We can use the the context method on | ||
* require that webpack created in order to tell webpack | ||
* what files we actually want to require or import. | ||
* Below, context will be an function/object with file names as keys. | ||
* using that regex we are saying look in ./src/app and ./test then find | ||
* any file that ends with spec.js and get its path. By passing in true | ||
* we say do this recursively | ||
*/ | ||
var testContext = require.context('../src', true, /\.spec\.ts/); | ||
|
||
/* | ||
* get all the files, for each file, call the context function | ||
* that will require the file and load it up here. Context will | ||
* loop and require those spec files here | ||
*/ | ||
function requireAll(requireContext) { | ||
return requireContext.keys().map(requireContext); | ||
} | ||
|
||
// requires and returns all modules that match | ||
var modules = requireAll(testContext); |
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,108 @@ | ||
/** | ||
* Adapted from angular2-webpack-starter | ||
*/ | ||
|
||
const helpers = require('./helpers'); | ||
|
||
/** | ||
* Webpack Plugins | ||
*/ | ||
const ProvidePlugin = require('webpack/lib/ProvidePlugin'); | ||
const DefinePlugin = require('webpack/lib/DefinePlugin'); | ||
|
||
const ENV = process.env.ENV = process.env.NODE_ENV = 'test'; | ||
|
||
module.exports = { | ||
|
||
/** | ||
* Source map for Karma from the help of karma-sourcemap-loader & karma-webpack | ||
* | ||
* Do not change, leave as is or it wont work. | ||
* See: https://github.com/webpack/karma-webpack#source-maps | ||
*/ | ||
devtool: 'inline-source-map', | ||
|
||
|
||
resolve: { | ||
extensions: ['', '.ts', '.js'], | ||
root: helpers.root('src') | ||
}, | ||
|
||
module: { | ||
|
||
preLoaders: [ | ||
{ | ||
test: /\.ts$/, | ||
loader: 'tslint-loader', | ||
exclude: [helpers.root('node_modules')] | ||
}, | ||
{ | ||
test: /\.js$/, | ||
loader: 'source-map-loader', | ||
exclude: [ | ||
// these packages have problems with their sourcemaps | ||
helpers.root('node_modules/rxjs'), | ||
helpers.root('node_modules/@angular') | ||
] | ||
} | ||
], | ||
|
||
loaders: [ | ||
{ | ||
test: /\.ts$/, | ||
loader: 'awesome-typescript-loader', | ||
query: { | ||
compilerOptions: { | ||
|
||
// Remove TypeScript helpers to be injected | ||
// below by DefinePlugin | ||
removeComments: true | ||
} | ||
}, | ||
exclude: [/\.e2e\.ts$/] | ||
}, | ||
|
||
{ | ||
test: /\.scss$/, | ||
loaders: ['style', 'css?sourceMap', 'postcss?sourceMap', 'sass?sourceMap'] | ||
} | ||
], | ||
|
||
postLoaders: [ | ||
{ | ||
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader', | ||
include: helpers.root('src'), | ||
exclude: [ | ||
/\.(e2e|spec)\.ts$/, | ||
/node_modules/ | ||
] | ||
} | ||
] | ||
}, | ||
|
||
plugins: [ | ||
new DefinePlugin({ | ||
'ENV': JSON.stringify(ENV), | ||
'process.env': { | ||
'ENV': JSON.stringify(ENV) | ||
} | ||
}) | ||
], | ||
|
||
tslint: { | ||
emitErrors: false, | ||
failOnHint: false, | ||
resourcePath: 'src' | ||
}, | ||
|
||
|
||
node: { | ||
global: 'window', | ||
process: false, | ||
crypto: 'empty', | ||
module: false, | ||
clearImmediate: false, | ||
setImmediate: false | ||
} | ||
|
||
}; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Look in ./config for karma.conf.js | ||
module.exports = require('./config/karma.conf.js'); |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/// <reference path="../node_modules/@types/jasmine/index.d.ts" /> | ||
|
||
import { A2D3Module } from './A2D3Module'; | ||
|
||
/* | ||
This file is to import the main module. By importing it into this | ||
spec file, all the attached components get traversed and recognized | ||
in the code coverage stats. | ||
*/ | ||
|
||
describe('A2D3 Module', () => { | ||
|
||
it('should load', () => { | ||
expect(A2D3Module).toBeDefined(); | ||
}); | ||
|
||
}); |
Oops, something went wrong.