Skip to content

Commit

Permalink
Add more tests from facebook#16271
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Aug 15, 2019
1 parent 3b70481 commit 22a1287
Showing 1 changed file with 51 additions and 1 deletion.
Expand Up @@ -362,6 +362,15 @@ describe('SchedulerBrowser', () => {
const enableMessageLoopImplementation = true;
beforeAndAfterHooks(enableMessageLoopImplementation);

it('task that finishes before deadline', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('Task');
});
runtime.assertLog(['Post Message']);
runtime.fireMessageEvent();
runtime.assertLog(['Message Event', 'Task']);
});

it('task with continutation', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('Task');
Expand All @@ -387,7 +396,48 @@ describe('SchedulerBrowser', () => {
runtime.assertLog(['Message Event', 'Continuation']);
});

it('task that throws', () => {
it('multiple tasks', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('A');
});
scheduleCallback(NormalPriority, () => {
runtime.log('B');
});
runtime.assertLog(['Post Message']);
runtime.fireMessageEvent();
runtime.assertLog(['Message Event', 'A', 'B']);
});

it('multiple tasks with a yield in between', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('A');
runtime.advanceTime(4999);
});
scheduleCallback(NormalPriority, () => {
runtime.log('B');
});
runtime.assertLog(['Post Message']);
runtime.fireMessageEvent();
runtime.assertLog([
'Message Event',
'A',
// Ran out of time. Post a continuation event.
'Post Message',
]);
runtime.fireMessageEvent();
runtime.assertLog(['Message Event', 'B']);
});

it('cancels tasks', () => {
const task = scheduleCallback(NormalPriority, () => {
runtime.log('Task');
});
runtime.assertLog(['Post Message']);
cancelCallback(task);
runtime.assertLog([]);
});

it('throws when a task errors then continues in a new event', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('Oops!');
throw Error('Oops!');
Expand Down

0 comments on commit 22a1287

Please sign in to comment.