Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Added --no-coverage flag to skyux watch #157

Merged
merged 6 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cli/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* Spawns the karam start command.
* @name test
*/
function test(command) {

function test(command, argv) {
const path = require('path');
const spawn = require('cross-spawn');

Expand All @@ -25,6 +24,12 @@ function test(command) {
command
];

if (argv && argv.coverage === false) {
flags.push('--no-coverage');
} else {
flags.push('--coverage');
}

const options = {
stdio: 'inherit'
};
Expand Down
2 changes: 1 addition & 1 deletion config/karma/shared.karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getConfig(config) {
'../../utils/spec-styles.js': ['webpack'],
'../../utils/spec-bundle.js': ['coverage', 'webpack', 'sourcemap']
},
webpack: testWebpackConfig.getWebpackConfig(skyPagesConfig),
webpack: testWebpackConfig.getWebpackConfig(skyPagesConfig, argv),
coverageReporter: {
dir: path.join(process.cwd(), 'coverage'),
reporters: [
Expand Down
59 changes: 33 additions & 26 deletions config/webpack/test.webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*jslint node: true */
'use strict';

function getWebpackConfig(skyPagesConfig) {
function getWebpackConfig(skyPagesConfig, argv) {

function spaPath() {
return skyPagesConfigUtil.spaPath.apply(skyPagesConfigUtil, arguments);
}
Expand All @@ -19,6 +20,7 @@ function getWebpackConfig(skyPagesConfig) {
const skyPagesConfigUtil = require('../sky-pages/sky-pages.config');
const aliasBuilder = require('./alias-builder');

const runCoverage = (!argv || argv.coverage !== false);
skyPagesConfig.runtime.includeRouteModule = false;

const ENV = process.env.ENV = process.env.NODE_ENV = 'test';
Expand All @@ -38,7 +40,7 @@ function getWebpackConfig(skyPagesConfig) {

let alias = aliasBuilder.buildAliasList(skyPagesConfig);

return {
let config = {
devtool: 'inline-source-map',

resolveLoader: {
Expand Down Expand Up @@ -119,30 +121,6 @@ function getWebpackConfig(skyPagesConfig) {
'raw-loader',
'sass-loader'
]
},
{
enforce: 'post',
test: /\.(js|ts)$/,
use: [
{
loader: 'istanbul-instrumenter-loader',
options: {
esModules: true
}
},
{
loader: 'source-map-inline-loader'
}
],
include: srcPath,
exclude: [
/\.(e2e|spec)\.ts$/,
/node_modules/,
/index\.ts/,
/fixtures/,
/testing/,
/src(\\|\/)app(\\|\/)lib/
]
}
]
},
Expand Down Expand Up @@ -185,6 +163,35 @@ function getWebpackConfig(skyPagesConfig) {
processExitCode
]
};

if (runCoverage) {
config.module.rules.push({
enforce: 'post',
test: /\.(js|ts)$/,
use: [
{
loader: 'istanbul-instrumenter-loader',
options: {
esModules: true
}
},
{
loader: 'source-map-inline-loader'
}
],
include: srcPath,
exclude: [
/\.(e2e|spec)\.ts$/,
/node_modules/,
/index\.ts/,
/fixtures/,
/testing/,
/src(\\|\/)app(\\|\/)lib/
]
});
}

return config;
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
break;
case 'test':
case 'watch':
require('./cli/test')(command);
require('./cli/test')(command, argv);
break;
case 'version':
require('./cli/version')();
Expand Down
32 changes: 32 additions & 0 deletions test/cli-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ describe('cli test', () => {

});

it('should pass the --coverage flag to karma by default', () => {
const cmd = 'CUSTOM_CMD';
let found = false;

mock('cross-spawn', (node, flags) => {
found = flags.includes('--coverage');
return {
on: () => {}
};
});

require('../cli/test')(cmd);
expect(found).toEqual(true);
mock.stop('cross-spawn');
});

it('should pass the --no-coverage flag to karma', () => {
const cmd = 'CUSTOM_CMD';
let found = false;

mock('cross-spawn', (node, flags) => {
found = flags.includes('--no-coverage');
return {
on: () => {}
};
});

require('../cli/test')(cmd, { coverage: false });
expect(found).toEqual(true);
mock.stop('cross-spawn');
});

it('should pass the exitCode', (done) => {
const EXIT_CODE = 1337;

Expand Down
43 changes: 37 additions & 6 deletions test/config-webpack-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,50 @@
const runtimeUtils = require('../utils/runtime-test-utils');

describe('config webpack common', () => {
let argv;
let skyPagesConfig;

beforeEach(() => {
argv = {};
skyPagesConfig = {
skyux: {
mode: 'advanced'
},
runtime: runtimeUtils.getDefaultRuntime()
};
});

it('should expose a getWebpackConfig method', () => {
const lib = require('../config/webpack/test.webpack.config');
expect(typeof lib.getWebpackConfig).toEqual('function');
});

it('should return a config object', () => {
const lib = require('../config/webpack/test.webpack.config');
const config = lib.getWebpackConfig({
skyux: {
mode: 'advanced'
},
runtime: runtimeUtils.getDefaultRuntime()
});
const config = lib.getWebpackConfig(skyPagesConfig);
expect(config).toEqual(jasmine.any(Object));
});

it('should run coverage by default', () => {
const lib = require('../config/webpack/test.webpack.config');
const config = lib.getWebpackConfig(skyPagesConfig);

let instrumentLoader = config.module.rules.filter(rule => {
return (rule.use && rule.use[0].loader === 'istanbul-instrumenter-loader');
})[0];

expect(instrumentLoader).toBeDefined();
});

it('should not run coverage if argv.coverage is false', () => {
argv.coverage = false;
const lib = require('../config/webpack/test.webpack.config');
const config = lib.getWebpackConfig(skyPagesConfig, argv);

let instrumentLoader = config.module.rules.filter(rule => {
return (rule.use && rule.use[0].loader === 'istanbul-instrumenter-loader');
})[0];

expect(instrumentLoader).not.toBeDefined();
});
});