Skip to content

Commit

Permalink
feat(adapter.jasmine): remove only last failed specs anti-feature
Browse files Browse the repository at this point in the history
This really seems to be anti-feature, as it only causes troubles.

Closes #148
  • Loading branch information
vojtajina committed Feb 21, 2013
1 parent f108799 commit 435bf72
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 132 deletions.
23 changes: 0 additions & 23 deletions adapter/jasmine.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ var indexOf = function(collection, item) {
*/
var TestacularReporter = function(tc) {

var failedIds = [];

this.reportRunnerStarting = function(runner) {
tc.info({total: runner.specs().length});
};

this.reportRunnerResults = function(runner) {
tc.store('jasmine.lastFailedIds', failedIds);
tc.complete({
coverage: window.__coverage__
});
Expand Down Expand Up @@ -84,8 +81,6 @@ var TestacularReporter = function(tc) {
result.log.push(formatFailedStep(steps[i]));
}
}

failedIds.push(result.id);
}

tc.result(result);
Expand All @@ -105,24 +100,6 @@ var createStartFn = function(tc, jasmineEnvPassedIn) {
// we pass jasmineEnv during testing
// in production we ask for it lazily, so that adapter can be loaded even before jasmine
var jasmineEnv = jasmineEnvPassedIn || window.jasmine.getEnv();
var currentSpecsCount = jasmineEnv.nextSpecId_;
var lastCount = tc.store('jasmine.lastCount');
var lastFailedIds = tc.store('jasmine.lastFailedIds');

tc.store('jasmine.lastCount', currentSpecsCount);
tc.store('jasmine.lastFailedIds', []);

// filter only last failed specs
if (lastCount === currentSpecsCount && // still same number of specs
lastFailedIds.length > 0 && // at least one fail last run
!jasmineEnv.exclusive_) { // no exclusive mode (iit, ddesc)

jasmineEnv.specFilter = function(spec) {
return indexOf(lastFailedIds, spec.id) !== -1;
};
}



jasmineEnv.addReporter(new TestacularReporter(tc));
jasmineEnv.execute();
Expand Down
109 changes: 0 additions & 109 deletions test/client/jasmine.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,6 @@ describe('jasmine adapter', function() {
});


it('should report failed ids', function() {
var specs = [ // id
spec, // 0
new jasmine.Spec(env, suite, 'should test'), // 1
new jasmine.Spec(env, suite, 'should test'), // 2
new jasmine.Spec(env, suite, 'should test') // 3
];

specs[1].fail(new Error('Some error'));
specs[2].fail(new Error('Another error'));

while(specs.length) {
reporter.reportSpecResults(specs.shift());
}
reporter.reportRunnerResults();

expect(testacular.store('jasmine.lastFailedIds')).toEqual([1, 2]);
});


it('should remove jasmine-specific frames from the exception stack traces', function() {
var error = new Error("Expected 'function' to be 'fxunction'");
error.stack = "Error: Expected 'function' to be 'fxunction'.\n" +
Expand Down Expand Up @@ -154,8 +134,6 @@ describe('jasmine adapter', function() {

beforeEach(function() {
tc = new Testacular(new MockSocket(), {});
tc.store('jasmine.lastFailedIds', [1, 3, 5]);
tc.store('jasmine.lastCount', 10);

spyOn(tc, 'info');
spyOn(tc, 'complete');
Expand All @@ -164,93 +142,6 @@ describe('jasmine adapter', function() {
jasmineEnv = new jasmine.Env();
start = createStartFn(tc, jasmineEnv);
});


it('should reset last results', function() {
start();
expect(tc.store('jasmine.lastCount')).toBe(0);
expect(tc.store('jasmine.lastFailedIds')).toEqual([]);
});


it('should store failed ids', function() {
jasmineEnv.describe('fake', function() {
jasmineEnv.it('should pass', function() {});
jasmineEnv.it('should fail', function() {throw new Error('FAIL');});
});

start();

waitsFor(function() {
return tc.store('jasmine.lastFailedIds').length === 1;
}, 'execution finish', 50);

runs(function() {
expect(tc.store('jasmine.lastFailedIds')).toEqual([1]);
});
});


describe('specFilter', function() {
var originalSpecFilter = 'ORIGINAL SPEC FILTER';

beforeEach(function() {
jasmineEnv.specFilter = originalSpecFilter;
});


it('should filter only last failed', function() {
tc.store('jasmine.lastFailedIds', [1, 3, 5]);
tc.store('jasmine.lastCount', 5);
jasmineEnv.nextSpecId_ = 5;

start();
expect(jasmineEnv.specFilter({id: 1})).toBe(true);
expect(jasmineEnv.specFilter({id: 2})).toBe(false);
expect(jasmineEnv.specFilter({id: 3})).toBe(true);
expect(jasmineEnv.specFilter({id: 4})).toBe(false);
expect(jasmineEnv.specFilter({id: 5})).toBe(true);
});


it('should not filter if first run', function() {
tc.store('jasmine.lastFailedIds', null);
tc.store('jasmine.lastCount', null);

start();
expect(jasmineEnv.specFilter).toBe(originalSpecFilter);
});


it('should not filter if number of specs changed', function() {
tc.store('jasmine.lastCount', 10);
jasmineEnv.nextSpecId_ = 5;

start();
expect(jasmineEnv.specFilter).toBe(originalSpecFilter);
});


it('should not filter if all specs passed last time', function() {
tc.store('jasmine.lastFailedIds', []);
tc.store('jasmine.lastCount', 5);
jasmineEnv.nextSpecId_ = 5;

start();
expect(jasmineEnv.specFilter).toBe(originalSpecFilter);
});


it('should not filter if exclusive mode', function() {
tc.store('jasmine.lastFailedIds', [1, 3, 5]);
tc.store('jasmine.lastCount', 5);
jasmineEnv.nextSpecId_ = 5;
jasmineEnv.exclusive_ = 1;

start();
expect(jasmineEnv.specFilter).toBe(originalSpecFilter);
});
});
});


Expand Down

0 comments on commit 435bf72

Please sign in to comment.