Skip to content

Commit

Permalink
build: update to Karma v6 and fix security advisories
Browse files Browse the repository at this point in the history
- use new Karma APIs
- remove `socket.io` resolution to fix
  `Can not resolve circular dependency! (Resolving: socketServer -> socketServer)`
- from: found 79 vulnerabilities (7 low, 59 moderate, 12 high, 1 critical)
- to: found 20 vulnerabilities (7 low, 5 moderate, 8 high)

Closes angular#12097. Closes angular#12101. Closes angular#12102.
  • Loading branch information
Splaktar committed Jun 4, 2021
1 parent 139a381 commit 4d75a8c
Show file tree
Hide file tree
Showing 6 changed files with 897 additions and 3,297 deletions.
72 changes: 26 additions & 46 deletions gulp/tasks/karma-fast.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,46 @@
const gutil = require('gulp-util');
const util = require('../util');
const ROOT = require('../const').ROOT;
const Server = require('karma').Server;
const karmaConfig = {
const karma = require('karma');
const parseConfig = karma.config.parseConfig;
const Server = karma.Server;
const karmaOptions = {
logLevel: 'warn',
singleRun: true,
autoWatch: false,
configFile: ROOT + '/config/karma.conf.js'
autoWatch: false
};

const args = util.args;

// NOTE: `karma-fast` does NOT pre-make a full build of JS and CSS
// exports.dependencies = ['build'];

exports.task = function (done) {
let errorCount = 0;

/**
* NOTE: `karma-fast` does NOT pre-make a full build of JS and CSS
*/
exports.task = function(done) {
// NOTE: `karma-fast` does NOT test Firefox by default.
if (args.browsers) {
karmaConfig.browsers = args.browsers.trim().split(',');
karmaOptions.browsers = args.browsers.trim().split(',');
}
// NOTE: `karma-fast` does NOT test Firefox by default.

if (args.reporters) {
karmaConfig.reporters = args.reporters.trim().split(',');
karmaOptions.reporters = args.reporters.trim().split(',');
}


gutil.log('Running unit tests on unminified source.');

const karma = new Server(karmaConfig, captureError(clearEnv,clearEnv));
karma.start();


function clearEnv() {
process.env.KARMA_TEST_COMPRESSED = undefined;
process.env.KARMA_TEST_JQUERY = undefined;

// eslint-disable-next-line no-process-exit
if (errorCount > 0) { process.exit(errorCount); }
done();
}

/**
* For each version of testings (unminified, minified, minified w/ jQuery)
* capture the exitCode and update the error count...
*
* When all versions are done, report any errors that may manifest
* [e.g. perhaps in the minified tests]
*
* NOTE: All versions must pass before the CI server will announce 'success'
*/
function captureError(next,done) {
return function(exitCode) {
parseConfig(ROOT + '/config/karma.conf.js', karmaOptions, {
promiseConfig: true,
throwErrors: true
}).then(parsedKarmaConfig => {
const server = new Server(parsedKarmaConfig, function(exitCode) {
if (exitCode !== 0) {
gutil.log(gutil.colors.red("Karma exited with the following exit code: " + exitCode));
errorCount++;
gutil.log(gutil.colors.red('Karma exited with the following exit code: ' + exitCode));
}
// Do not process next set of tests if current set had >0 errors.
(errorCount > 0) && done() || next();
};
}


process.env.KARMA_TEST_COMPRESSED = undefined;
process.env.KARMA_TEST_JQUERY = undefined;
// eslint-disable-next-line no-process-exit
process.exit(exitCode);
});
gutil.log('Starting Karma Server...');
server.start();
});
};
24 changes: 18 additions & 6 deletions gulp/tasks/karma-sauce.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
const Server = require('karma').Server;
const ROOT = require('../const').ROOT;
const karma = require('karma');
const parseConfig = karma.config.parseConfig;
const Server = karma.Server;
const karmaOptions = {
logLevel: 'warn'
};

exports.task = function(done) {
const srv = new Server({
logLevel: 'warn',
configFile: ROOT + '/config/karma-sauce.conf.js'
}, done);
srv.start();
parseConfig(ROOT + '/config/karma-sauce.conf.js', karmaOptions, {
promiseConfig: true,
throwErrors: true
}).then(parsedKarmaConfig => {
const server = new Server(parsedKarmaConfig, function(exitCode) {
// Immediately exit the process if Karma reported errors, because due to
// potential still running tunnel-browsers gulp won't exit properly.
// eslint-disable-next-line no-process-exit
exitCode === 0 ? done() : process.exit(exitCode);
});
server.start();
});
};
30 changes: 21 additions & 9 deletions gulp/tasks/karma-watch.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
const ROOT = require('../const').ROOT;
const args = require('../util').args;
const Server = require('karma').Server;
const config = {
singleRun: false,
autoWatch: true,
configFile: ROOT + '/config/karma.conf.js',
browsers : args.browsers ? args.browsers.trim().split(',') : ['Chrome']
};
const karma = require('karma');
const parseConfig = karma.config.parseConfig;
const Server = karma.Server;
const karmaOptions = {
singleRun: false,
autoWatch: true,
browsers: args.browsers ? args.browsers.trim().split(',') : ['Chrome']
};

// Make full build of JS and CSS
exports.dependencies = ['build'];

exports.task = function(done) {
const server = new Server(config, done);
server.start();
let karmaConfigPath = ROOT + '/config/karma.conf.js';
if (args.config)
karmaConfigPath = ROOT + '/' + args.config.trim();
parseConfig(karmaConfigPath, karmaOptions, {promiseConfig: true, throwErrors: true})
.then(parsedKarmaConfig => {
const server = new Server(parsedKarmaConfig, function(exitCode) {
// Immediately exit the process if Karma reported errors, because due to
// potential still running tunnel-browsers gulp won't exit properly.
// eslint-disable-next-line no-process-exit
exitCode === 0 ? done() : process.exit(exitCode);
});
server.start();
});
};
38 changes: 23 additions & 15 deletions gulp/tasks/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,36 @@ const gutil = require('gulp-util');
const util = require('../util');
const ROOT = require('../const').ROOT;
const args = util.args;
const Server = require('karma').Server;
const karma = require('karma');
const parseConfig = karma.config.parseConfig;
const Server = karma.Server;

const karmaConfig = {
logLevel: 'warn',
configFile: ROOT + '/config/karma.conf.js'
const karmaOptions = {
logLevel: 'warn'
};

// Make full build of JS and CSS
exports.dependencies = ['build'];

exports.task = function (done) {
if (args.browsers) karmaConfig.browsers = args.browsers.trim().split(',');
if (args.reporters) karmaConfig.reporters = args.reporters.trim().split(',');
if (args.config) karmaConfig.configFile = ROOT + '/' + args.config.trim();
exports.task = function(done) {
let karmaConfigPath = ROOT + '/config/karma.conf.js';
if (args.browsers)
karmaOptions.browsers = args.browsers.trim().split(',');
if (args.reporters)
karmaOptions.reporters = args.reporters.trim().split(',');
if (args.config)
karmaConfigPath = ROOT + '/' + args.config.trim();

gutil.log(gutil.colors.blue('Running unit tests on unminified source.'));

const karma = new Server(karmaConfig, function(exitCode){
// Immediately exit the process if Karma reported errors, because due to
// potential still running tunnel-browsers gulp won't exit properly.
// eslint-disable-next-line no-process-exit
exitCode === 0 ? done() : process.exit(exitCode);
});
karma.start();
parseConfig(karmaConfigPath, karmaOptions, {promiseConfig: true, throwErrors: true})
.then(parsedKarmaConfig => {
const server = new Server(parsedKarmaConfig, function(exitCode) {
// Immediately exit the process if Karma reported errors, because due to
// potential still running tunnel-browsers gulp won't exit properly.
// eslint-disable-next-line no-process-exit
exitCode === 0 ? done() : process.exit(exitCode);
});
server.start();
});
};
Loading

0 comments on commit 4d75a8c

Please sign in to comment.