Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
do not use the profile reporter by default and add it when specfiying…
Browse files Browse the repository at this point in the history
… profile: true instead, rely on to-reporters from jasmine-json-stream-reporter
  • Loading branch information
rdy committed Aug 25, 2016
1 parent 496c77a commit 8b6a1c5
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 111 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -59,7 +59,8 @@
"express": "^4.13.3",
"flat-map": "^0.1.0",
"jasmine-core": "^2.4.1",
"jasmine-json-stream-reporter": "^0.0.7",
"jasmine-json-stream-reporter": "^0.0.8",
"jasmine-profile-reporter": "^0.0.2",
"jasmine-terminal-reporter": "^1.0.2",
"lazypipe": "^1.0.1",
"lodash.once": "^4.0.0",
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/spec_runner_spec.js
Expand Up @@ -76,10 +76,10 @@ describe('SpecRunner', () => {
});

describe('when profile is true', () => {
let specProfileReporterJs;
let profileReporterJs;

beforeEach(() => {
specProfileReporterJs = fs.readFileSync(path.resolve(__dirname, '..', '..', 'dist', 'lib', 'reporters', 'profile_reporter.js'), 'utf8');
profileReporterJs = fs.readFileSync(require.resolve('jasmine-profile-reporter/browser.js'), 'utf8');
subject = new SpecRunner({profile: true});
});

Expand All @@ -90,7 +90,7 @@ describe('SpecRunner', () => {
expect($tags.length).toBe(7);

expect($tags.eq(4).is('script')).toBe(true);
expect($tags.eq(4).html()).toBe(specProfileReporterJs);
expect($tags.eq(4).html()).toBe(profileReporterJs);
});
});
});
Expand Down Expand Up @@ -173,11 +173,11 @@ describe('SpecRunner', () => {
});

describe('when profile is true', () => {
let addProfileReporterJs, specProfileReporterJs;
let addProfileReporterJs, profileReporterJs;

beforeEach(() => {
addProfileReporterJs = fs.readFileSync(path.resolve(__dirname, '..', '..', 'dist', 'lib', 'reporters', 'add_profile_reporter.js'), 'utf8');
specProfileReporterJs = fs.readFileSync(path.resolve(__dirname, '..', '..', 'dist', 'lib', 'reporters', 'profile_reporter.js'), 'utf8');
profileReporterJs = fs.readFileSync(require.resolve('jasmine-profile-reporter/browser.js'), 'utf8');
subject = new SpecRunner({profile: true});
});

Expand All @@ -200,7 +200,7 @@ describe('SpecRunner', () => {
expect($tags.eq(3).html()).toBe(jsFiles[2]);

expect($tags.eq(4).is('script')).toBe(true);
expect($tags.eq(4).html()).toBe(specProfileReporterJs);
expect($tags.eq(4).html()).toBe(profileReporterJs);

expect($tags.eq(5).is('script')).toBe(true);
expect($tags.eq(5).html()).toBe(bootFiles[0]);
Expand Down
12 changes: 1 addition & 11 deletions src/lib/boot.js
Expand Up @@ -43,18 +43,8 @@

extend(window, jasmineInterface);

var jsonStreamReporter;

if (jasmineRequire.profile) {
jasmineRequire.profile(jasmineRequire, jasmine);
var profileReporter = new jasmine.ProfileReporter({
print: function(message) { jsonStreamReporter && jsonStreamReporter.message(message) }
});
env.addReporter(profileReporter);
}

if (window.JasmineJsonStreamReporter) {
jsonStreamReporter = new JasmineJsonStreamReporter({
var jsonStreamReporter = new JasmineJsonStreamReporter({
print: function(message) {
callPhantom({message: message});
},
Expand Down
9 changes: 7 additions & 2 deletions src/lib/headless.js
Expand Up @@ -8,6 +8,7 @@ const {spawn} = require('child_process');
const thenify = require('thenify');
const {obj: through} = require('through2');
const {obj: reduce} = require('through2-reduce');
const ProfileReporter = require('jasmine-profile-reporter');
const TerminalReporter = require('jasmine-terminal-reporter');
const toReporter = require('jasmine-json-stream-reporter/to-reporter');
const split = require('split2');
Expand Down Expand Up @@ -39,8 +40,12 @@ function getServer(files, options = {}) {
return listen(port, files, options);
}

function defaultReporters(options, profile) {
return [new TerminalReporter(options), profile && new ProfileReporter(options)].filter(Boolean);
}

function createServer(options) {
const {driver = 'phantomjs', random, throwFailures, spec, seed, reporter, ...opts} = options;
const {driver = 'phantomjs', random, throwFailures, spec, seed, reporter, profile, ...opts} = options;
const query = qs.stringify({catch: options.catch, random, throwFailures, spec, seed});
const {command, runner, output} = drivers[driver in drivers ? driver : '_default']();
const stream = lazypipe()
Expand All @@ -53,7 +58,7 @@ function createServer(options) {
['SIGINT', 'SIGTERM'].forEach(e => process.once(e, () => phantomProcess && phantomProcess.kill()));
next(null, phantomProcess[output].pipe(split(null, JSON.parse, {objectMode: true})));
}))
.pipe(() => toReporter(reporter || new TerminalReporter(opts), {onError}));
.pipe(() => toReporter(reporter || defaultReporters(opts, profile), {onError}));
return stream();
}

Expand Down
6 changes: 2 additions & 4 deletions src/lib/reporters/add_profile_reporter.js
@@ -1,8 +1,6 @@
(function() {
if (jasmineRequire.profile) {
window.jasmine = window.jasmine || jasmineRequire.core(jasmineRequire);
jasmineRequire.profile(jasmineRequire, jasmine);
var profileReporter = new jasmine.ProfileReporter({
if (window.JasmineProfileReporter) {
var profileReporter = new JasmineProfileReporter({
print: function(message) { console.log(message); }
});
jasmine.getEnv().addReporter(profileReporter);
Expand Down
86 changes: 0 additions & 86 deletions src/lib/reporters/profile_reporter.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/spec_runner.js
Expand Up @@ -31,7 +31,7 @@ class SpecRunner extends File {
...resolveJasmineFiles('path', 'cssFiles'),
useSourcemappedStacktrace && 'stylesheets/sourcemapped_stacktrace_reporter.css',
...resolveJasmineFiles('path', 'jsFiles'),
profile && 'reporters/profile_reporter.js',
profile && require.resolve('jasmine-profile-reporter/browser.js'),
...(console ? [require.resolve('jasmine-json-stream-reporter/browser.js'), 'boot.js'] : resolveJasmineFiles('bootDir', 'bootFiles')),
profile && !console && 'reporters/add_profile_reporter.js',
useSourcemappedStacktrace && require.resolve('sourcemapped-stacktrace/dist/sourcemapped-stacktrace.js'),
Expand Down

0 comments on commit 8b6a1c5

Please sign in to comment.