Skip to content

Commit

Permalink
test: make tests pass on legacy phantomjs
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n committed Dec 16, 2018
1 parent 926bb1e commit 8da89f8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 51 deletions.
8 changes: 0 additions & 8 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"presets": [
[
"@babel/preset-env",
{
"forceAllTransforms": true
}
]
],
"env": {
"commonjs": {
"presets": [
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
"babel-plugin-istanbul": "=5.1.0",
"better-npm-run": "0.1.1",
"chai": "=4.1.2",
"chai-as-promised": "=7.1.1",
"codecov": "3.1.0",
"conventional-changelog-cli": "2.0.7",
"docdash": "git+https://github.com/char0n/docdash.git#bf4b4eebfdaf042c0ea9038419bc26813f243c94",
Expand All @@ -169,7 +168,6 @@
"mocha-multi-reporters": "1.1.7",
"monet": "0.9.0",
"nyc": "13.0.0",
"phantomjs-prebuilt": "=2.1.16",
"prettier": "1.15.3",
"ramda": "=0.26.1",
"rimraf": "=2.6.2",
Expand Down
44 changes: 32 additions & 12 deletions test/allP.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,37 @@ describe('allP', function() {
});
});

it('should resolve list of thenable values', function(done) {
it('should resolve list of thenable values', async function() {
const p1 = RA.resolveP(1);
const p2 = RA.resolveP(2);
const actual = await RA.allP([p1, p2]);

assert.eventually.deepEqual(RA.allP([p1, p2]), [1, 2]).notify(done);
assert.deepEqual(actual, [1, 2]);
});

it('should resolve list of mixed thenable and non-thenable values', function(done) {
it('should resolve list of mixed thenable and non-thenable values', async function() {
const p1 = RA.resolveP(1);
const p2 = 2;
const actual = await RA.allP([p1, p2]);

assert.eventually.deepEqual(RA.allP([p1, p2]), [1, 2]).notify(done);
assert.deepEqual(actual, [1, 2]);
});

it('should resolve list of rejected thenable values', function(done) {
it('should resolve list of rejected thenable values', async function(done) {
const p1 = RA.resolveP(1);
const p2 = RA.rejectP(2);

assert.isRejected(RA.allP([p1, p2]), 2).notify(done);
try {
await RA.allP([p1, p2]);
done('resolving should fail');
} catch (e) {
assert.strictEqual(e, 2);
done();
}
});

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all#Promise.all_fail-fast_behaviour
it('should have fail-fast behavior', function(done) {
it('should have fail-fast behavior', async function(done) {
const p1 = new Promise(resolve => {
setTimeout(resolve, 10, 'one');
});
Expand All @@ -49,22 +57,34 @@ describe('allP', function() {
reject(new Error());
});

assert.isRejected(RA.allP([p1, p2, p3, p4, p5]), Error).notify(done);
try {
await RA.allP([p1, p2, p3, p4, p5]);
done('resolving should fail');
} catch (e) {
assert.instanceOf(e, Error);
done();
}
});

context('given there are two rejections', function() {
specify('should reject with the first one', function(done) {
specify('should reject with the first one', async function(done) {
const p1 = RA.resolveP(1);
const p2 = RA.rejectP(1);
const p3 = RA.rejectP(2);

assert.isRejected(RA.allP([p1, p2, p3]), 1).notify(done);
try {
await RA.allP([p1, p2, p3]);
done('resolving should fail');
} catch (e) {
assert.strictEqual(e, 1);
done();
}
});
});

it('should support placeholder to specify "gaps"', function(done) {
it('should support placeholder to specify "gaps"', async function() {
const allP = RA.allP(R.__);

assert.eventually.deepEqual(allP([1, 2, 3]), [1, 2, 3]).notify(done);
assert.deepEqual(await allP([1, 2, 3]), [1, 2, 3]);
});
});
5 changes: 0 additions & 5 deletions test/mocha-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@
require('@babel/register')({
// ignore: [/node_modules\/(?!(chai-as-promised))/],
});

const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);
45 changes: 24 additions & 21 deletions test/thenP.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ import * as RA from '../src/index';

describe('thenP', function() {
context('given applied on Promise', function() {
specify('should call then method with onFulfilled function', function() {
const promise = RA.resolveP(1);
const expected = RA.thenP(R.add(1), promise);

assert.eventually.strictEqual(expected, 2);
});
specify(
'should call then method with onFulfilled function',
async function() {
const promise = RA.resolveP(1);
const expected = await RA.thenP(R.add(1), promise);

assert.strictEqual(expected, 2);
}
);
});

context('given applied on Thenable', function() {
specify('should call then method with onFulfilled function', function() {
const thenable = { then: fn => RA.resolveP(fn(1)) };
const expected = RA.thenP(R.add(1), thenable);

assert.eventually.strictEqual(expected, 2);
});
specify(
'should call then method with onFulfilled function',
async function() {
const thenable = { then: fn => RA.resolveP(fn(1)) };
const expected = await RA.thenP(R.add(1), thenable);

assert.strictEqual(expected, 2);
}
);
});

context('given applied on non-thenable', function() {
Expand All @@ -29,23 +35,20 @@ describe('thenP', function() {
});
});

it('should call `then` method on thenable', function(done) {
it('should call `then` method on thenable', async function() {
const then = sinon.stub().returns(RA.resolveP(1));
const thenable = { then };
const expected = RA.thenP(R.identity, thenable);

expected.then(() => {
assert.isTrue(then.calledOnce);
done();
});
await RA.thenP(R.identity, thenable);
assert.isTrue(then.calledOnce);
});

it('should have arity of 2', function() {
assert.strictEqual(RA.thenP.length, 2);
});

it('should be curried', function() {
assert.eventually.strictEqual(RA.thenP(R.identity, RA.resolveP(1)), 1);
assert.eventually.strictEqual(RA.thenP(R.identity)(RA.resolveP(1)), 1);
it('should be curried', async function() {
assert.strictEqual(await RA.thenP(R.identity, RA.resolveP(1)), 1);
assert.strictEqual(await RA.thenP(R.identity)(RA.resolveP(1)), 1);
});
});
5 changes: 2 additions & 3 deletions webpack.config-test.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module.exports = {
mode: 'production',
target: 'web',
entry: [
require.resolve('@babel/polyfill'),
'@babel/polyfill',
...glob.sync('./test/*.js', {
ignore: './test/typescript.js',
ignore: ['./test/typescript.js', './test/mocha-bootstrap.js'],
}),
],
output: {
Expand All @@ -20,7 +20,6 @@ module.exports = {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules\/(?!(chai-as-promised|sinon))/,
loader: 'babel-loader',
options: {
presets: [
Expand Down

0 comments on commit 8da89f8

Please sign in to comment.