Skip to content

Commit

Permalink
feat(reporter): On no-single-run and failure, emit a debug URL (#235)
Browse files Browse the repository at this point in the history
* feat(reporter): On no-single-run and failure, emit a debug URL

* fix up lint
  • Loading branch information
johnjbarton committed Aug 13, 2019
1 parent a12024d commit 76f092a
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 18 deletions.
1 change: 1 addition & 0 deletions karma.conf.js
@@ -1,6 +1,7 @@
module.exports = function (config) {
config.set({
frameworks: ['jasmine'],
reporters: ['karma-jasmine'],

files: [
'src/*.js',
Expand Down
15 changes: 14 additions & 1 deletion lib/index.js
Expand Up @@ -13,6 +13,19 @@ var initJasmine = function (files) {

initJasmine.$inject = ['config.files']

function InjectKarmaJasmineReporter (singleRun) {
return {
onSpecComplete (browser, karmaResult) {
if (!singleRun && karmaResult.debug_url) {
console.log('Debug this test: ' + karmaResult.debug_url)
}
}
}
}

InjectKarmaJasmineReporter.$inject = ['config.singleRun']

module.exports = {
'framework:jasmine': ['factory', initJasmine]
'framework:jasmine': ['factory', initJasmine],
'reporter:karma-jasmine': ['factory', InjectKarmaJasmineReporter]
}
51 changes: 35 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"description": "A Karma plugin - adapter for Jasmine testing framework.",
"main": "lib/index.js",
"scripts": {
"test": "grunt"
"test": "jasmine; grunt"
},
"repository": {
"type": "git",
Expand All @@ -17,6 +17,7 @@
],
"author": "Vojta Jina <vojta.jina@gmail.com>",
"dependencies": {
"jasmine": "^3.4.0",

This comment has been minimized.

Copy link
@XhmikosR

XhmikosR Jan 7, 2020

Collaborator

@johnjbarton are you sure jasmine should be in dependencies and not in devDependencies? Also do note the test command you have here isn't cross-platform

This comment has been minimized.

Copy link
@johnjbarton

johnjbarton Jan 7, 2020

Author Contributor

Please review #244

This comment has been minimized.

Copy link
@johnjbarton

johnjbarton Jan 7, 2020

Author Contributor

The Travis test runs on Firefox but the key would be a test on windows/IE

This comment has been minimized.

Copy link
@XhmikosR

XhmikosR Jan 7, 2020

Collaborator

If it's supposed to run jasmine and grunt next, why not do npm run jasmine && grunt?

"jasmine-core": "^3.3"
},
"devDependencies": {
Expand Down
23 changes: 23 additions & 0 deletions spec/index_spec.js
@@ -0,0 +1,23 @@

const diInfo = require('../lib/index.js');

describe('reporter', () => {

it('is available via dependency injection', () => {
const diEntry = diInfo['reporter:karma-jasmine'];
expect(diEntry.length).toBe(2);
expect(typeof diEntry[1]).toBe('function');
});

it('logs debug_url', () => {
const logSpy = jasmine.createSpy('consoleLog', console.log);
const originalLog = console.log;
console.log = logSpy;
const InjectKarmaJasmineReporter = diInfo['reporter:karma-jasmine'][1];
const reporter = InjectKarmaJasmineReporter(false);
reporter.onSpecComplete(/** ignored */undefined, {debug_url: 'hiya'});
expect(logSpy).toHaveBeenCalledWith('Debug this test: hiya');
console.log = originalLog;
});

});
11 changes: 11 additions & 0 deletions spec/support/jasmine.json
@@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}

0 comments on commit 76f092a

Please sign in to comment.