Skip to content

Commit

Permalink
lint and flow happy, more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Aug 15, 2017
1 parent c398fc1 commit 9280702
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 37 deletions.
12 changes: 9 additions & 3 deletions integration_tests/__tests__/jasmine_async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,20 @@ describe('async jasmine', () => {
const json = result.json;
const message = json.testResults[0].message;

expect(json.numTotalTests).toBe(9);
expect(json.numPassedTests).toBe(5);
expect(json.numFailedTests).toBe(4);
expect(json.numTotalTests).toBe(16);
expect(json.numPassedTests).toBe(6);
expect(json.numFailedTests).toBe(9);

expect(message).toMatch('fails if promise is rejected');
expect(message).toMatch('works with done.fail');
expect(message).toMatch('works with done(error)');
expect(message).toMatch('fails if failed expectation with done');
expect(message).toMatch('fails if failed expectation with done - async');
expect(message).toMatch('fails with thrown error with done - sync');
expect(message).toMatch('fails with thrown error with done - async');
expect(message).toMatch('fails a sync test');
expect(message).toMatch('fails if a custom timeout is exceeded');

});

it('works with concurrent', () => {
Expand Down
22 changes: 11 additions & 11 deletions integration_tests/jasmine_async/__tests__/promise_it.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,39 @@ describe('promise it', () => {

it('works with done(error)', done => {
done(new Error('done was called with error'));
})
});

it('fails if failed expectation with done', done => {
expect(true).toEqual(false);
done();
})
});

it('fails if failed expectation with done - async', done => {
setTimeout(() => {
expect(true).toEqual(false)
done()
}, 1)
})
expect(true).toEqual(false);
done();
}, 1);
});

it('fails with thrown error with done - sync', done => {
throw new Error('sync fail');
done();
})
done(); // eslint-disable-line
});

it('fails with thrown error with done - async', done => {
setTimeout(() => {
throw new Error('async fail');
done();
done(); // eslint-disable-line
}, 1);
})
});

// I wish it was possible to catch this but I do not see a way.
// Currently both jest and mocha will pass this test.
it.skip('fails with thrown error - async', () => {
setTimeout(() => {
throw new Error('async fail - no done');
}, 1);
})
});

it('fails a sync test', () => {
expect('sync').toBe('failed');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snapshot works with plain objects and the title has \`escape\` characters 1`] = `
Object {
"a": 1,
"b": "2",
"c": "three\`",
"d": "vier",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snapshot is not influenced by previous counter 1`] = `
Object {
"a": 43,
"b": "43",
"c": "fourtythree",
}
`;

exports[`snapshot works with \\r\\n 1`] = `
"<div>
</div>"
`;

exports[`snapshot works with plain objects and the title has \`escape\` characters 1`] = `
Object {
"a": 1,
"b": "2",
"c": "three\`",
}
`;

exports[`snapshot works with plain objects and the title has \`escape\` characters 2`] = `
Object {
"a": 1,
"b": "2",
"c": "three\`",
"d": "4",
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snapshot is not influenced by previous counter 1`] = `
Object {
"a": 43,
"b": "43",
"c": "fourtythree",
}
`;

exports[`snapshot works with \\r\\n 1`] = `
"<div>
</div>"
`;

exports[`snapshot works with plain objects and the title has \`escape\` characters 1`] = `
Object {
"a": 1,
"b": "2",
"c": "three\`",
}
`;

exports[`snapshot works with plain objects and the title has \`escape\` characters 2`] = `
Object {
"a": 1,
"b": "2",
"c": "three\`",
"d": "4",
}
`;
43 changes: 43 additions & 0 deletions integration_tests/snapshot/__tests__/snapshot.test_copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/
'use strict';

describe('snapshot', () => {
it('works with plain objects and the title has `escape` characters', () => {
const test = {
a: 1,
b: '2',
c: 'three`',
};
expect(test).not.toBe(undefined);
test.d = '4';
expect(test).toMatchSnapshot();
});

it('is not influenced by previous counter', () => {
const test = {
a: 43,
b: '43',
c: 'fourtythree',
};
expect(test).toMatchSnapshot();
});

it('cannot be used with .not', () => {
expect(() => expect('').not.toMatchSnapshot()).toThrow(
'Jest: `.not` cannot be used with `.toMatchSnapshot()`.'
);
});

// Issue reported here: https://github.com/facebook/jest/issues/2969
it('works with \\r\\n', () => {
expect('<div>\r\n</div>').toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/__tests__/queue_runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('queueRunner', () => {
});

it('calls `fail` when done(error) is invoked', async () => {
const error = new Error('I am an error')
const error = new Error('I am an error');
const fail = jest.fn();
const fnOne = jest.fn(next => next(error));
const fnTwo = jest.fn(next => next());
Expand Down
13 changes: 5 additions & 8 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ module.exports = function(j$) {
}
}

const uncaught = (err) => {

const uncaught = err => {
let name;
let current;
if (currentSpec) {
Expand All @@ -201,14 +200,12 @@ module.exports = function(j$) {
// TODO: Handle top level failures
}
// console.error('caught in ' + name);
}
};

process.on('uncaughtException', uncaught);
process.on('unhandledRejection', uncaught);

reporter.jasmineStarted({
totalSpecsDefined,
});
reporter.jasmineStarted({totalSpecsDefined});

currentlyExecutingSuites.push(topSuite);

Expand All @@ -235,8 +232,8 @@ module.exports = function(j$) {
failedExpectations: topSuite.result.failedExpectations,
});

process.removeListener('uncaughtException', uncaught)
process.removeListener('unhandledRejection', uncaught)
process.removeListener('uncaughtException', uncaught);
process.removeListener('unhandledRejection', uncaught);
};

this.addReporter = function(reporterToAdd) {
Expand Down
29 changes: 15 additions & 14 deletions packages/jest-jasmine2/src/queue_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ type QueueableFn = {
timeout?: () => number,
};

function createCancelToken () {
let res
const token = new Promise(resolve => {
res = resolve
})
function createCancelToken() {
let cancel;
const promise = new Promise(resolve => {
cancel = resolve;
});

token.cancel = res
return token
return {
cancel,
promise,
};
}

function queueRunner(options: Options) {
Expand All @@ -58,10 +60,7 @@ function queueRunner(options: Options) {
}
});

promise = Promise.race([
promise,
token,
]);
promise = Promise.race([promise, token.promise]);

if (!timeout) {
return promise;
Expand All @@ -86,9 +85,11 @@ function queueRunner(options: Options) {
Promise.resolve(),
);

returnPromise.cancel = token.cancel;

return returnPromise;
return {
cancel: token.cancel,
catch: returnPromise.catch.bind(returnPromise),
then: returnPromise.then.bind(returnPromise),
};
}

module.exports = queueRunner;

0 comments on commit 9280702

Please sign in to comment.