forked from angular/material
-
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.
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 angular#12097. Closes angular#12101. Closes angular#12102.
- Loading branch information
Showing
6 changed files
with
897 additions
and
3,297 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,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(); | ||
}); | ||
}; |
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,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(); | ||
}); | ||
}; |
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,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(); | ||
}); | ||
}; |
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
Oops, something went wrong.