Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 4d75a8c

Browse files
committed
build: update to Karma v6 and fix security advisories
- 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 #12097. Closes #12101. Closes #12102.
1 parent 139a381 commit 4d75a8c

File tree

6 files changed

+897
-3297
lines changed

6 files changed

+897
-3297
lines changed

gulp/tasks/karma-fast.js

+26-46
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,46 @@
11
const gutil = require('gulp-util');
22
const util = require('../util');
33
const ROOT = require('../const').ROOT;
4-
const Server = require('karma').Server;
5-
const karmaConfig = {
4+
const karma = require('karma');
5+
const parseConfig = karma.config.parseConfig;
6+
const Server = karma.Server;
7+
const karmaOptions = {
68
logLevel: 'warn',
79
singleRun: true,
8-
autoWatch: false,
9-
configFile: ROOT + '/config/karma.conf.js'
10+
autoWatch: false
1011
};
1112

1213
const args = util.args;
1314

14-
// NOTE: `karma-fast` does NOT pre-make a full build of JS and CSS
15-
// exports.dependencies = ['build'];
16-
17-
exports.task = function (done) {
18-
let errorCount = 0;
19-
15+
/**
16+
* NOTE: `karma-fast` does NOT pre-make a full build of JS and CSS
17+
*/
18+
exports.task = function(done) {
19+
// NOTE: `karma-fast` does NOT test Firefox by default.
2020
if (args.browsers) {
21-
karmaConfig.browsers = args.browsers.trim().split(',');
21+
karmaOptions.browsers = args.browsers.trim().split(',');
2222
}
23-
// NOTE: `karma-fast` does NOT test Firefox by default.
2423

2524
if (args.reporters) {
26-
karmaConfig.reporters = args.reporters.trim().split(',');
25+
karmaOptions.reporters = args.reporters.trim().split(',');
2726
}
2827

29-
3028
gutil.log('Running unit tests on unminified source.');
3129

32-
const karma = new Server(karmaConfig, captureError(clearEnv,clearEnv));
33-
karma.start();
34-
35-
36-
function clearEnv() {
37-
process.env.KARMA_TEST_COMPRESSED = undefined;
38-
process.env.KARMA_TEST_JQUERY = undefined;
39-
40-
// eslint-disable-next-line no-process-exit
41-
if (errorCount > 0) { process.exit(errorCount); }
42-
done();
43-
}
44-
45-
/**
46-
* For each version of testings (unminified, minified, minified w/ jQuery)
47-
* capture the exitCode and update the error count...
48-
*
49-
* When all versions are done, report any errors that may manifest
50-
* [e.g. perhaps in the minified tests]
51-
*
52-
* NOTE: All versions must pass before the CI server will announce 'success'
53-
*/
54-
function captureError(next,done) {
55-
return function(exitCode) {
30+
parseConfig(ROOT + '/config/karma.conf.js', karmaOptions, {
31+
promiseConfig: true,
32+
throwErrors: true
33+
}).then(parsedKarmaConfig => {
34+
const server = new Server(parsedKarmaConfig, function(exitCode) {
5635
if (exitCode !== 0) {
57-
gutil.log(gutil.colors.red("Karma exited with the following exit code: " + exitCode));
58-
errorCount++;
36+
gutil.log(gutil.colors.red('Karma exited with the following exit code: ' + exitCode));
5937
}
60-
// Do not process next set of tests if current set had >0 errors.
61-
(errorCount > 0) && done() || next();
62-
};
63-
}
64-
65-
38+
process.env.KARMA_TEST_COMPRESSED = undefined;
39+
process.env.KARMA_TEST_JQUERY = undefined;
40+
// eslint-disable-next-line no-process-exit
41+
process.exit(exitCode);
42+
});
43+
gutil.log('Starting Karma Server...');
44+
server.start();
45+
});
6646
};

gulp/tasks/karma-sauce.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
const Server = require('karma').Server;
21
const ROOT = require('../const').ROOT;
2+
const karma = require('karma');
3+
const parseConfig = karma.config.parseConfig;
4+
const Server = karma.Server;
5+
const karmaOptions = {
6+
logLevel: 'warn'
7+
};
38

49
exports.task = function(done) {
5-
const srv = new Server({
6-
logLevel: 'warn',
7-
configFile: ROOT + '/config/karma-sauce.conf.js'
8-
}, done);
9-
srv.start();
10+
parseConfig(ROOT + '/config/karma-sauce.conf.js', karmaOptions, {
11+
promiseConfig: true,
12+
throwErrors: true
13+
}).then(parsedKarmaConfig => {
14+
const server = new Server(parsedKarmaConfig, function(exitCode) {
15+
// Immediately exit the process if Karma reported errors, because due to
16+
// potential still running tunnel-browsers gulp won't exit properly.
17+
// eslint-disable-next-line no-process-exit
18+
exitCode === 0 ? done() : process.exit(exitCode);
19+
});
20+
server.start();
21+
});
1022
};

gulp/tasks/karma-watch.js

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
const ROOT = require('../const').ROOT;
22
const args = require('../util').args;
3-
const Server = require('karma').Server;
4-
const config = {
5-
singleRun: false,
6-
autoWatch: true,
7-
configFile: ROOT + '/config/karma.conf.js',
8-
browsers : args.browsers ? args.browsers.trim().split(',') : ['Chrome']
9-
};
3+
const karma = require('karma');
4+
const parseConfig = karma.config.parseConfig;
5+
const Server = karma.Server;
6+
const karmaOptions = {
7+
singleRun: false,
8+
autoWatch: true,
9+
browsers: args.browsers ? args.browsers.trim().split(',') : ['Chrome']
10+
};
1011

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

1415
exports.task = function(done) {
15-
const server = new Server(config, done);
16-
server.start();
16+
let karmaConfigPath = ROOT + '/config/karma.conf.js';
17+
if (args.config)
18+
karmaConfigPath = ROOT + '/' + args.config.trim();
19+
parseConfig(karmaConfigPath, karmaOptions, {promiseConfig: true, throwErrors: true})
20+
.then(parsedKarmaConfig => {
21+
const server = new Server(parsedKarmaConfig, function(exitCode) {
22+
// Immediately exit the process if Karma reported errors, because due to
23+
// potential still running tunnel-browsers gulp won't exit properly.
24+
// eslint-disable-next-line no-process-exit
25+
exitCode === 0 ? done() : process.exit(exitCode);
26+
});
27+
server.start();
28+
});
1729
};

gulp/tasks/karma.js

+23-15
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,36 @@ const gutil = require('gulp-util');
22
const util = require('../util');
33
const ROOT = require('../const').ROOT;
44
const args = util.args;
5-
const Server = require('karma').Server;
5+
const karma = require('karma');
6+
const parseConfig = karma.config.parseConfig;
7+
const Server = karma.Server;
68

7-
const karmaConfig = {
8-
logLevel: 'warn',
9-
configFile: ROOT + '/config/karma.conf.js'
9+
const karmaOptions = {
10+
logLevel: 'warn'
1011
};
1112

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

15-
exports.task = function (done) {
16-
if (args.browsers) karmaConfig.browsers = args.browsers.trim().split(',');
17-
if (args.reporters) karmaConfig.reporters = args.reporters.trim().split(',');
18-
if (args.config) karmaConfig.configFile = ROOT + '/' + args.config.trim();
16+
exports.task = function(done) {
17+
let karmaConfigPath = ROOT + '/config/karma.conf.js';
18+
if (args.browsers)
19+
karmaOptions.browsers = args.browsers.trim().split(',');
20+
if (args.reporters)
21+
karmaOptions.reporters = args.reporters.trim().split(',');
22+
if (args.config)
23+
karmaConfigPath = ROOT + '/' + args.config.trim();
1924

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

22-
const karma = new Server(karmaConfig, function(exitCode){
23-
// Immediately exit the process if Karma reported errors, because due to
24-
// potential still running tunnel-browsers gulp won't exit properly.
25-
// eslint-disable-next-line no-process-exit
26-
exitCode === 0 ? done() : process.exit(exitCode);
27-
});
28-
karma.start();
27+
parseConfig(karmaConfigPath, karmaOptions, {promiseConfig: true, throwErrors: true})
28+
.then(parsedKarmaConfig => {
29+
const server = new Server(parsedKarmaConfig, function(exitCode) {
30+
// Immediately exit the process if Karma reported errors, because due to
31+
// potential still running tunnel-browsers gulp won't exit properly.
32+
// eslint-disable-next-line no-process-exit
33+
exitCode === 0 ? done() : process.exit(exitCode);
34+
});
35+
server.start();
36+
});
2937
};

0 commit comments

Comments
 (0)