Skip to content

Commit 18e220b

Browse files
committed
cleanup/fix tests
1 parent 721b335 commit 18e220b

File tree

3 files changed

+3
-147
lines changed

3 files changed

+3
-147
lines changed

packages/scheduler/src/__tests__/Scheduler-test.js

Lines changed: 1 addition & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,6 @@ describe('SchedulerBrowser', () => {
101101
this.port2 = port2;
102102
};
103103

104-
const scheduling = {
105-
isInputPending(options) {
106-
if (this !== scheduling) {
107-
throw new Error(
108-
'isInputPending called with incorrect `this` context',
109-
);
110-
}
111-
112-
return (
113-
hasPendingDiscreteEvent ||
114-
(options && options.includeContinuous && hasPendingContinuousEvent)
115-
);
116-
},
117-
};
118-
119-
global.navigator = {scheduling};
120-
121104
function ensureLogIsEmpty() {
122105
if (eventLog.length !== 0) {
123106
throw Error('Log is not empty. Call assertLog before continuing.');
@@ -218,7 +201,7 @@ describe('SchedulerBrowser', () => {
218201
runtime.assertLog([
219202
'Message Event',
220203
'Task',
221-
'Yield at 5ms',
204+
gate(flags => (flags.www ? 'Yield at 10ms' : 'Yield at 5ms')),
222205
'Post Message',
223206
]);
224207

@@ -320,132 +303,6 @@ describe('SchedulerBrowser', () => {
320303
runtime.assertLog(['Message Event', 'B']);
321304
});
322305

323-
it('when isInputPending is available, we can wait longer before yielding', () => {
324-
function blockUntilSchedulerAsksToYield() {
325-
while (!Scheduler.unstable_shouldYield()) {
326-
runtime.advanceTime(1);
327-
}
328-
runtime.log(`Yield at ${performance.now()}ms`);
329-
}
330-
331-
// First show what happens when we don't request a paint
332-
scheduleCallback(NormalPriority, () => {
333-
runtime.log('Task with no pending input');
334-
blockUntilSchedulerAsksToYield();
335-
});
336-
runtime.assertLog(['Post Message']);
337-
338-
runtime.fireMessageEvent();
339-
runtime.assertLog([
340-
'Message Event',
341-
'Task with no pending input',
342-
'Yield at 5ms',
343-
]);
344-
345-
runtime.resetTime();
346-
347-
// Now do the same thing, but while the task is running, simulate an
348-
// input event.
349-
scheduleCallback(NormalPriority, () => {
350-
runtime.log('Task with pending input');
351-
runtime.scheduleDiscreteEvent();
352-
blockUntilSchedulerAsksToYield();
353-
});
354-
runtime.assertLog(['Post Message']);
355-
356-
runtime.fireMessageEvent();
357-
runtime.assertLog([
358-
'Message Event',
359-
'Task with pending input',
360-
// This time we yielded quickly to unblock the discrete event.
361-
'Yield at 5ms',
362-
'Discrete Event',
363-
]);
364-
});
365-
366-
it(
367-
'isInputPending will also check for continuous inputs, but after a ' +
368-
'slightly larger threshold',
369-
() => {
370-
function blockUntilSchedulerAsksToYield() {
371-
while (!Scheduler.unstable_shouldYield()) {
372-
runtime.advanceTime(1);
373-
}
374-
runtime.log(`Yield at ${performance.now()}ms`);
375-
}
376-
377-
// First show what happens when we don't request a paint
378-
scheduleCallback(NormalPriority, () => {
379-
runtime.log('Task with no pending input');
380-
blockUntilSchedulerAsksToYield();
381-
});
382-
runtime.assertLog(['Post Message']);
383-
384-
runtime.fireMessageEvent();
385-
runtime.assertLog([
386-
'Message Event',
387-
'Task with no pending input',
388-
'Yield at 5ms',
389-
]);
390-
391-
runtime.resetTime();
392-
393-
// Now do the same thing, but while the task is running, simulate a
394-
// continuous input event.
395-
scheduleCallback(NormalPriority, () => {
396-
runtime.log('Task with continuous input');
397-
runtime.scheduleContinuousEvent();
398-
blockUntilSchedulerAsksToYield();
399-
});
400-
runtime.assertLog(['Post Message']);
401-
402-
runtime.fireMessageEvent();
403-
runtime.assertLog([
404-
'Message Event',
405-
'Task with continuous input',
406-
'Yield at 5ms',
407-
'Continuous Event',
408-
]);
409-
},
410-
);
411-
412-
it('requestPaint forces a yield at the end of the next frame interval', () => {
413-
function blockUntilSchedulerAsksToYield() {
414-
while (!Scheduler.unstable_shouldYield()) {
415-
runtime.advanceTime(1);
416-
}
417-
runtime.log(`Yield at ${performance.now()}ms`);
418-
}
419-
420-
// First show what happens when we don't request a paint
421-
scheduleCallback(NormalPriority, () => {
422-
runtime.log('Task with no paint');
423-
blockUntilSchedulerAsksToYield();
424-
});
425-
runtime.assertLog(['Post Message']);
426-
427-
runtime.fireMessageEvent();
428-
runtime.assertLog(['Message Event', 'Task with no paint', 'Yield at 5ms']);
429-
430-
runtime.resetTime();
431-
432-
// Now do the same thing, but call requestPaint inside the task
433-
scheduleCallback(NormalPriority, () => {
434-
runtime.log('Task with paint');
435-
requestPaint();
436-
blockUntilSchedulerAsksToYield();
437-
});
438-
runtime.assertLog(['Post Message']);
439-
440-
runtime.fireMessageEvent();
441-
runtime.assertLog([
442-
'Message Event',
443-
'Task with paint',
444-
// This time we yielded quickly (5ms) because we requested a paint.
445-
'Yield at 5ms',
446-
]);
447-
});
448-
449306
it('yielding continues in a new task regardless of how much time is remaining', () => {
450307
scheduleCallback(NormalPriority, () => {
451308
runtime.log('Original Task');

packages/scheduler/src/__tests__/SchedulerSetImmediate-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('SchedulerDOMSetImmediate', () => {
173173
runtime.assertLog([
174174
'setImmediate Callback',
175175
'Task',
176-
'Yield at 5ms',
176+
gate(flags => (flags.www ? 'Yield at 10ms' : 'Yield at 5ms')),
177177
'Set Immediate',
178178
]);
179179

packages/scheduler/src/forks/SchedulerPostTask.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ let deadline = 0;
5757

5858
let currentPriorityLevel_DEPRECATED = NormalPriority;
5959

60-
// `isInputPending` is not available. Since we have no way of knowing if
61-
// there's pending input, always yield at the end of the frame.
60+
// Always yield at the end of the frame.
6261
export function unstable_shouldYield(): boolean {
6362
return getCurrentTime() >= deadline;
6463
}

0 commit comments

Comments
 (0)