diff --git a/package-lock.json b/package-lock.json index 3a6a86d..20d70b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3001,7 +3001,7 @@ "dev": true }, "furipota": { - "version": "github:origamitower/furipota#babefc35b82e527169aaaa0557f6d018933132ff", + "version": "github:origamitower/furipota#52c4d8d72a93101bc1db18979d96b9aae9dd0649", "dev": true, "requires": { "chalk": "1.1.3", diff --git a/test/source/specs/base/concurrency/task.js b/test/source/specs/base/concurrency/task.js index 33e65b4..6e8bbc1 100644 --- a/test/source/specs/base/concurrency/task.js +++ b/test/source/specs/base/concurrency/task.js @@ -25,7 +25,6 @@ const eq = function(that) { return this._state.equals(that._state); } - describe('Data.Task', () => { describe('Conversions', () => { @@ -168,7 +167,7 @@ describe('Data.Task', () => { $ASSERT(v1 == 1); await b.or(a).run().promise().catch(v => $ASSERT(v == 2)); - + const v2 = await a.or(c).run().promise(); $ASSERT(v2 == 1); @@ -335,8 +334,8 @@ describe('Data.Task', () => { r.cleanup(() => clearTimeout(timer)); }); const result = await Task.do(function *() { - const a = yield delay(10); - const b = yield delay(11); + const a = yield delay(10); + const b = yield delay(11); const c = yield Task.of(5); return Task.of(a + b + c + 4); }).run().promise(); @@ -352,7 +351,7 @@ describe('Data.Task', () => { $ASSERT(exception == 5); }) $ASSERT(exceptionThrown[0] == true); - + const resultCancel = await Task.do(function *() { const a = yield Task.task(r => r.cancel()); return Task.of(a); @@ -363,7 +362,7 @@ describe('Data.Task', () => { const multipleCallsResults = []; const multipleCallsTask = await Task.do(function *() { - const a = yield delay(10); + const a = yield delay(10); return Task.of(a); }); multipleCallsResults[0] = await multipleCallsTask.run().promise(); @@ -386,14 +385,14 @@ describe('Data.Task', () => { }); it('Always invokes cleanup after the task resolves', async () => { - let stack = []; + let stack = []; let d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(1); r.cleanup(() => { stack.push(2); - d.resolve(2) + d.resolve(2) }); r.resolve(1) }).run(); @@ -402,7 +401,7 @@ describe('Data.Task', () => { stack = []; d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(3); r.cleanup(() => { stack.push(4); @@ -415,7 +414,7 @@ describe('Data.Task', () => { stack = []; d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(5); r.cleanup(() => { stack.push(6); @@ -427,10 +426,10 @@ describe('Data.Task', () => { }); it('Invokes onCancelled callbacks if the task is cancelled', async () => { - let stack = []; + let stack = []; let d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(1); r.cleanup(() => { stack.push(2); @@ -447,7 +446,7 @@ describe('Data.Task', () => { stack = []; d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(3); r.cleanup(() => { stack.push(4); @@ -464,7 +463,7 @@ describe('Data.Task', () => { stack = []; d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(5); stack.push(r.isCancelled); r.cleanup(() => { @@ -539,6 +538,37 @@ describe('Data.Task', () => { ex.cancel(); return ex.promise().catch(v => $ASSERT(Cancelled.hasInstance(v))); }); + + it('Deals with exception', async () => { + let Result = undefined; + + try { + let ex = await Task.of('a') + .map((() => false ? Result.a : Result.b)) + .run() + .promise(); + // Should have thrown a TypeError by then + $ASSERT(false) + } catch (e) { + $ASSERT(e instanceof TypeError); + } + }); + + it('Deals with exception corner cases', async () => { + let Result = require('folktale').validation; + try { + let ex = await Task.of('a') + .map((() => false ? Result.a : Result.b)) + .run() + .promise(); + // Should have thrown a TypeError by then + $ASSERT(false) + // But throws an AssertionError instead + } catch (e) { + $ASSERT(e instanceof TypeError); + } + }); + }); describe('#future()', () => {