Skip to content

Commit

Permalink
Merge pull request #19 from alk-sdavid/sec
Browse files Browse the repository at this point in the history
security: upgrade dependencies
  • Loading branch information
sebdvd authored Apr 6, 2020
2 parents d603780 + c54b3bb commit e460d6c
Show file tree
Hide file tree
Showing 7 changed files with 3,774 additions and 2,061 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
env:
browser: true
es6: true
node: true
extends: 'eslint:recommended'
globals:
Atomics: readonly
SharedArrayBuffer: readonly
parserOptions:
ecmaVersion: 2018
sourceType: module
rules: {}
overrides:
- files:
- '*.spec.js'
env:
jest: true
4 changes: 2 additions & 2 deletions CancelablePromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class CancelablePromise {
then(success, error) {
const p = new CancelablePromise((resolve, reject) => {
this._promise.then(
r => {
(r) => {
if (this._canceled) {
p.cancel();
}
Expand All @@ -49,7 +49,7 @@ export default class CancelablePromise {
resolve(r);
}
},
r => {
(r) => {
if (this._canceled) {
p.cancel();
}
Expand Down
102 changes: 51 additions & 51 deletions CancelablePromise.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, expect } from 'chai';
import { expect } from 'chai';
import CancelablePromise from './CancelablePromise';

const createEnd = (done, total) => {
Expand All @@ -9,8 +9,8 @@ const createEnd = (done, total) => {
};
};

describe(__filename, () => {
it('should handle errors', done => {
describe('CancelablePromise', () => {
it('should handle errors', (done) => {
const end = createEnd(done, 2);
const promise = new CancelablePromise((resolve, reject) => {
reject('eagle');
Expand All @@ -19,107 +19,107 @@ describe(__filename, () => {
() => {
done(new Error('Success callback should not be executed'));
},
reason => {
(reason) => {
expect(reason).to.be.equal('eagle');
end();
return 'rabbit';
}
);

promise2.then(reason => {
promise2.then((reason) => {
expect(reason).to.be.equal('rabbit');
end();
});
});

it('should return new value to the next then', done => {
it('should return new value to the next then', (done) => {
const end = createEnd(done, 2);
const promise = new CancelablePromise((resolve, reject) => {
const promise = new CancelablePromise((resolve) => {
resolve(5);
});
promise
.then(value => {
.then((value) => {
expect(value).to.be.equal(5);
end();
return value + 10;
})
.then(value => {
.then((value) => {
expect(value).to.be.equal(15);
end();
});
});

it('should work like a tree', done => {
it('should work like a tree', (done) => {
const end = createEnd(done, 2);
const promise = new CancelablePromise((resolve, reject) => {
const promise = new CancelablePromise((resolve) => {
resolve('test123');
});

const promise2 = promise.then(value => {
const promise2 = promise.then(() => {
return 'duck';
});

const promise3 = promise.then(value => {
const promise3 = promise.then(() => {
return 'dog';
});

promise2.then(value => {
promise2.then((value) => {
expect(value).to.be.equal('duck');
end();
});

promise3.then(value => {
promise3.then((value) => {
expect(value).to.be.equal('dog');
end();
});
});

it('should work also when then is added in a then', done => {
it('should work also when then is added in a then', (done) => {
const end = createEnd(done, 2);
const promise = new CancelablePromise((resolve, reject) => {
const promise = new CancelablePromise((resolve) => {
resolve('test123');
});

const promise2 = promise
.then(value => {
.then((value) => {
expect(value).to.be.equal('test123');
promise2.then(v => {
promise2.then((v) => {
expect(v).to.be.equal('fox');
end();
});
return 'rabbit';
})
.then(value => {
.then((value) => {
expect(value).to.be.equal('rabbit');
end();
return 'fox';
});
});

it('should work when empty or partial then', done => {
it('should work when empty or partial then', (done) => {
const end = createEnd(done, 2);
const promise = new CancelablePromise((resolve, reject) => {
const promise = new CancelablePromise((resolve) => {
resolve('test123');
});

const promise2 = promise.then();
promise2
.then(value => {
.then((value) => {
console.log(value);
expect(value).to.be.equal('test123');
end();
return 'fox';
})
.then(value => {
.then((value) => {
console.log(value);
expect(value).to.be.equal('fox');
end();
});
});

it('should not execute callbacks if canceled', done => {
it('should not execute callbacks if canceled', (done) => {
let hasFailed = false;
const successfulPromise = new CancelablePromise((resolve, reject) => {
const successfulPromise = new CancelablePromise((resolve) => {
resolve('good');
});
successfulPromise.cancel();
Expand All @@ -128,7 +128,7 @@ describe(__filename, () => {
hasFailed = true;
done(new Error('Callback should not be executed'));
},
reason => {
() => {
hasFailed = true;
done(new Error('Callback should not be executed'));
}
Expand All @@ -144,7 +144,7 @@ describe(__filename, () => {
hasFailed = true;
done(new Error('Success callback should not be executed'));
},
reason => {
() => {
hasFailed = true;
done(new Error('Error callback should not be executed'));
}
Expand All @@ -158,7 +158,7 @@ describe(__filename, () => {
)
);
},
reason => {
() => {
hasFailed = true;
done(
new Error(
Expand All @@ -180,7 +180,7 @@ describe(__filename, () => {
hasFailed = true;
done(new Error('Success callback should not be executed'));
},
reason => {
() => {
hasFailed = true;
done(new Error('Error callback should not be executed'));
}
Expand All @@ -194,7 +194,7 @@ describe(__filename, () => {
)
);
},
reason => {
() => {
hasFailed = true;
done(
new Error(
Expand All @@ -205,7 +205,7 @@ describe(__filename, () => {
);

const allPromise = CancelablePromise.all([
new Promise((resolve, reject) => {
new Promise((resolve) => {
resolve('good all resolve');
}),
]);
Expand All @@ -216,7 +216,7 @@ describe(__filename, () => {
hasFailed = true;
done(new Error('Success callback should not be executed'));
},
reason => {
() => {
hasFailed = true;
done(new Error('Error callback should not be executed'));
}
Expand All @@ -230,7 +230,7 @@ describe(__filename, () => {
)
);
},
reason => {
() => {
hasFailed = true;
done(
new Error(
Expand All @@ -241,7 +241,7 @@ describe(__filename, () => {
);

const racedPromise = CancelablePromise.race([
new Promise((resolve, reject) => {
new Promise((resolve) => {
resolve('good raced resolve');
}),
]);
Expand All @@ -252,7 +252,7 @@ describe(__filename, () => {
hasFailed = true;
done(new Error('Success callback should not be executed'));
},
reason => {
() => {
hasFailed = true;
done(new Error('Error callback should not be executed'));
}
Expand All @@ -266,7 +266,7 @@ describe(__filename, () => {
)
);
},
reason => {
() => {
hasFailed = true;
done(
new Error(
Expand All @@ -277,7 +277,7 @@ describe(__filename, () => {
);

const staticRejectedPromise = CancelablePromise.reject(
new Promise((resolve, reject) => {
new Promise((resolve) => {
resolve('good static reject');
})
);
Expand All @@ -288,7 +288,7 @@ describe(__filename, () => {
hasFailed = true;
done(new Error('Success callback should not be executed'));
},
reason => {
() => {
hasFailed = true;
done(new Error('Error callback should not be executed'));
}
Expand All @@ -302,7 +302,7 @@ describe(__filename, () => {
)
);
},
reason => {
() => {
hasFailed = true;
done(
new Error(
Expand All @@ -318,17 +318,17 @@ describe(__filename, () => {
setTimeout(end, 0);
});

it('should reject the promise when the success callback throws an error', done => {
const promise = new CancelablePromise((resolve, reject) => {
it('should reject the promise when the success callback throws an error', (done) => {
const promise = new CancelablePromise((resolve) => {
resolve('test123');
});
let hasFailed = true;

promise
.then(value => {
.then(() => {
throw new Error('The callback threw an error');
})
.catch(error => {
.catch(() => {
hasFailed = false;
});

Expand All @@ -344,17 +344,17 @@ describe(__filename, () => {
setTimeout(end, 0);
});

it('should reject the promise when the error callback throws an error', done => {
it('should reject the promise when the error callback throws an error', (done) => {
const promise = new CancelablePromise((resolve, reject) => {
reject(new Error('test123'));
});
let hasFailed = true;

promise
.catch(error => {
.catch(() => {
throw new Error('The callback threw an error');
})
.catch(error => {
.catch(() => {
hasFailed = false;
});

Expand All @@ -370,18 +370,18 @@ describe(__filename, () => {
setTimeout(end, 0);
});

it('should call cancel function if rejected after a cancel', done => {
it('should call cancel function if rejected after a cancel', (done) => {
const promise = new CancelablePromise((resolve, reject) => {
reject(new Error('test456'));
});
let cancelCalled = false;
let catchCalled = false;

promise.cancel(err => {
promise.cancel(() => {
cancelCalled = true;
});

promise.catch(err => {
promise.catch(() => {
catchCalled = true;
});

Expand All @@ -393,7 +393,7 @@ describe(__filename, () => {
} else if (!cancelCalled) {
hasFailed = 'Promise should call cancel error callback on a rejection';
}
done(!!hasFailed ? new Error(hasFailed) : undefined);
done(hasFailed ? new Error(hasFailed) : undefined);
};
setTimeout(end, 0);
});
Expand Down
Loading

0 comments on commit e460d6c

Please sign in to comment.