-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Standard code style and cleanup
- Loading branch information
1 parent
2418163
commit c884155
Showing
7 changed files
with
149 additions
and
111 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "standard" | ||
} |
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,19 @@ | ||
language: node_js | ||
node_js: | ||
- "iojs" | ||
- "0.12" | ||
- "0.10" | ||
- "0.8" | ||
|
||
# Make sure we have new NPM. | ||
before_install: | ||
- export DISPLAY=:99.0 | ||
- sh -e /etc/init.d/xvfb start | ||
- npm install -g npm | ||
- npm config set loglevel warn | ||
|
||
before_script: | ||
- npm install -g grunt-cli | ||
|
||
script: | ||
- grunt |
This file was deleted.
Oops, something went wrong.
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,38 @@ | ||
module.exports = function (grunt) { | ||
grunt.initConfig({ | ||
pkgFile: 'package.json', | ||
'npm-contributors': { | ||
options: { | ||
commitMessage: 'chore: update contributors' | ||
} | ||
}, | ||
bump: { | ||
options: { | ||
commitMessage: 'chore: release v%VERSION%', | ||
pushTo: 'upstream', | ||
commitFiles: [ | ||
'package.json' | ||
] | ||
} | ||
}, | ||
eslint: { | ||
target: [ | ||
'index.js', | ||
'gruntfile.js' | ||
] | ||
} | ||
}) | ||
|
||
require('load-grunt-tasks')(grunt) | ||
|
||
grunt.registerTask('default', ['eslint']) | ||
|
||
grunt.registerTask('release', 'Bump the version and publish to NPM.', function (type) { | ||
grunt.task.run([ | ||
'npm-contributors', | ||
'bump-only:' + (type || 'patch'), | ||
'bump-commit', | ||
'npm-publish' | ||
]) | ||
}) | ||
} |
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,134 +1,133 @@ | ||
var os = require('os'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var builder = require('xmlbuilder'); | ||
var os = require('os') | ||
var path = require('path') | ||
var fs = require('fs') | ||
var builder = require('xmlbuilder') | ||
|
||
|
||
var JUnitReporter = function(baseReporterDecorator, config, logger, helper, formatError) { | ||
var log = logger.create('reporter.junit'); | ||
var reporterConfig = config.junitReporter || {}; | ||
var pkgName = reporterConfig.suite || ''; | ||
var JUnitReporter = function (baseReporterDecorator, config, logger, helper, formatError) { | ||
var log = logger.create('reporter.junit') | ||
var reporterConfig = config.junitReporter || {} | ||
var pkgName = reporterConfig.suite || '' | ||
|
||
if (!reporterConfig.outputDir) { | ||
throw new Error('You must set an output directory for JUnitReporter via the outputDir config property'); | ||
throw new Error('You must set an output directory for JUnitReporter via the outputDir config property') | ||
} | ||
|
||
var outputDir = helper.normalizeWinPath(path.resolve(config.basePath, reporterConfig.outputDir)) + path.sep; | ||
var suites; | ||
var pendingFileWritings = 0; | ||
var fileWritingFinished = function() {}; | ||
var allMessages = []; | ||
var outputDir = helper.normalizeWinPath(path.resolve(config.basePath, reporterConfig.outputDir)) + path.sep | ||
var suites | ||
var pendingFileWritings = 0 | ||
var fileWritingFinished = function () {} | ||
var allMessages = [] | ||
|
||
baseReporterDecorator(this); | ||
baseReporterDecorator(this) | ||
|
||
this.adapters = [function(msg) { | ||
allMessages.push(msg); | ||
}]; | ||
this.adapters = [function (msg) { | ||
allMessages.push(msg) | ||
}] | ||
|
||
var initliazeXmlForBrowser = function(browser) { | ||
var timestamp = (new Date()).toISOString().substr(0, 19); | ||
var suite = suites[browser.id] = builder.create('testsuite'); | ||
var initliazeXmlForBrowser = function (browser) { | ||
var timestamp = (new Date()).toISOString().substr(0, 19) | ||
var suite = suites[browser.id] = builder.create('testsuite') | ||
suite.att('name', browser.name) | ||
.att('package', pkgName) | ||
.att('timestamp', timestamp) | ||
.att('id', 0) | ||
.att('hostname', os.hostname()); | ||
.att('package', pkgName) | ||
.att('timestamp', timestamp) | ||
.att('id', 0) | ||
.att('hostname', os.hostname()) | ||
suite.ele('properties') | ||
.ele('property', {name: 'browser.fullName', value: browser.fullName}); | ||
}; | ||
.ele('property', {name: 'browser.fullName', value: browser.fullName}) | ||
} | ||
|
||
var writeXmlForBrowser = function(browser) { | ||
var outputFile = outputDir + browser.name.replace(/ /g, '_') + '.xml'; | ||
var xmlToOutput = suites[browser.id]; | ||
var writeXmlForBrowser = function (browser) { | ||
var outputFile = outputDir + browser.name.replace(/ /g, '_') + '.xml' | ||
var xmlToOutput = suites[browser.id] | ||
|
||
pendingFileWritings++; | ||
helper.mkdirIfNotExists(outputDir, function() { | ||
fs.writeFile(outputFile, xmlToOutput.end({pretty: true}), function(err) { | ||
pendingFileWritings++ | ||
helper.mkdirIfNotExists(outputDir, function () { | ||
fs.writeFile(outputFile, xmlToOutput.end({pretty: true}), function (err) { | ||
if (err) { | ||
log.warn('Cannot write JUnit xml\n\t' + err.message); | ||
log.warn('Cannot write JUnit xml\n\t' + err.message) | ||
} else { | ||
log.debug('JUnit results written to "%s".', outputFile); | ||
log.debug('JUnit results written to "%s".', outputFile) | ||
} | ||
|
||
if (!--pendingFileWritings) { | ||
fileWritingFinished(); | ||
fileWritingFinished() | ||
} | ||
}); | ||
}); | ||
}; | ||
}) | ||
}) | ||
} | ||
|
||
this.onRunStart = function(browsers) { | ||
suites = Object.create(null); | ||
this.onRunStart = function (browsers) { | ||
suites = Object.create(null) | ||
|
||
// TODO(vojta): remove once we don't care about Karma 0.10 | ||
browsers.forEach(initliazeXmlForBrowser); | ||
}; | ||
browsers.forEach(initliazeXmlForBrowser) | ||
} | ||
|
||
this.onBrowserStart = function(browser) { | ||
initliazeXmlForBrowser(browser); | ||
}; | ||
this.onBrowserStart = function (browser) { | ||
initliazeXmlForBrowser(browser) | ||
} | ||
|
||
this.onBrowserComplete = function(browser) { | ||
var suite = suites[browser.id]; | ||
this.onBrowserComplete = function (browser) { | ||
var suite = suites[browser.id] | ||
|
||
if (!suite) { | ||
// This browser did not signal `onBrowserStart`. That happens | ||
// if the browser timed out during the start phase. | ||
return; | ||
return | ||
} | ||
|
||
var result = browser.lastResult; | ||
var result = browser.lastResult | ||
|
||
suite.att('tests', result.total); | ||
suite.att('errors', result.disconnected || result.error ? 1 : 0); | ||
suite.att('failures', result.failed); | ||
suite.att('time', (result.netTime || 0) / 1000); | ||
suite.att('tests', result.total) | ||
suite.att('errors', result.disconnected || result.error ? 1 : 0) | ||
suite.att('failures', result.failed) | ||
suite.att('time', (result.netTime || 0) / 1000) | ||
|
||
if (result.disconnected) { | ||
suite.ele('error').att('message', 'Browser disconnected'); | ||
suite.ele('error').att('message', 'Browser disconnected') | ||
} | ||
|
||
suite.ele('system-out').dat(allMessages.join() + '\n'); | ||
suite.ele('system-err'); | ||
suite.ele('system-out').dat(allMessages.join() + '\n') | ||
suite.ele('system-err') | ||
|
||
writeXmlForBrowser(browser); | ||
}; | ||
writeXmlForBrowser(browser) | ||
} | ||
|
||
this.onRunComplete = function() { | ||
suites = null; | ||
allMessages.length = 0; | ||
}; | ||
this.onRunComplete = function () { | ||
suites = null | ||
allMessages.length = 0 | ||
} | ||
|
||
this.specSuccess = this.specSkipped = this.specFailure = function(browser, result) { | ||
this.specSuccess = this.specSkipped = this.specFailure = function (browser, result) { | ||
var spec = suites[browser.id].ele('testcase', { | ||
name: result.description, time: ((result.time || 0) / 1000), | ||
classname: (pkgName ? pkgName + ' ' : '') + result.suite.join(' ').replace(/\./g, '_') | ||
}); | ||
}) | ||
|
||
if (result.skipped) { | ||
spec.ele('skipped'); | ||
spec.ele('skipped') | ||
} | ||
|
||
if (!result.success) { | ||
result.log.forEach(function(err) { | ||
spec.ele('failure', {type: ''}, formatError(err)); | ||
}); | ||
result.log.forEach(function (err) { | ||
spec.ele('failure', {type: ''}, formatError(err)) | ||
}) | ||
} | ||
}; | ||
} | ||
|
||
// wait for writing all the xml files, before exiting | ||
this.onExit = function(done) { | ||
this.onExit = function (done) { | ||
if (pendingFileWritings) { | ||
fileWritingFinished = done; | ||
fileWritingFinished = done | ||
} else { | ||
done(); | ||
done() | ||
} | ||
}; | ||
}; | ||
} | ||
} | ||
|
||
JUnitReporter.$inject = ['baseReporterDecorator', 'config', 'logger', 'helper', 'formatError']; | ||
JUnitReporter.$inject = ['baseReporterDecorator', 'config', 'logger', 'helper', 'formatError'] | ||
|
||
// PUBLISH DI MODULE | ||
module.exports = { | ||
'reporter:junit': ['type', JUnitReporter] | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -24,10 +24,13 @@ | |
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"grunt": "~0.4.1", | ||
"grunt-npm": "~0.0.2", | ||
"grunt-bump": "~0.0.7", | ||
"grunt-auto-release": "~0.0.2" | ||
"eslint": "^0.24.0", | ||
"eslint-config-standard": "^3.4.1", | ||
"grunt": "^0.4.1", | ||
"grunt-bump": "^0.3.1", | ||
"grunt-eslint": "^16.0.0", | ||
"grunt-npm": "^0.0.2", | ||
"load-grunt-tasks": "^3.2.0" | ||
}, | ||
"contributors": [ | ||
"Friedel Ziegelmayer <[email protected]>", | ||
|