Skip to content

Commit

Permalink
Gate tests to source
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Nov 9, 2020
1 parent 5ea434b commit ea4c5b1
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions packages/scheduler/src/__tests__/SchedulerPostTaskOnly-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,28 @@ let NormalPriority;

describe('SchedulerPostTaskOnly', () => {
beforeEach(() => {
jest.resetModules();

// Un-mock scheduler
jest.mock('scheduler', () =>
require.requireActual('scheduler/unstable_post_task_only'),
);

runtime = installMockBrowserRuntime();
performance = window.performance;
Scheduler = require('scheduler');
cancelCallback = Scheduler.unstable_cancelCallback;
scheduleCallback = Scheduler.unstable_scheduleCallback;
NormalPriority = Scheduler.unstable_NormalPriority;
if (process.env.IS_BUILD === false) {
jest.resetModules();

// Un-mock scheduler
jest.mock('scheduler', () =>
require.requireActual('scheduler/unstable_post_task_only'),
);

runtime = installMockBrowserRuntime();
performance = window.performance;
Scheduler = require('scheduler');
cancelCallback = Scheduler.unstable_cancelCallback;
scheduleCallback = Scheduler.unstable_scheduleCallback;
NormalPriority = Scheduler.unstable_NormalPriority;
}
});

afterEach(() => {
if (!runtime.isLogEmpty()) {
throw Error('Test exited without clearing log.');
if (process.env.IS_BUILD === false) {
if (!runtime.isLogEmpty()) {
throw Error('Test exited without clearing log.');
}
}
});

Expand Down Expand Up @@ -138,6 +142,7 @@ describe('SchedulerPostTaskOnly', () => {
};
}

// @gate source
it('task that finishes before deadline', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('Task');
Expand All @@ -147,6 +152,7 @@ describe('SchedulerPostTaskOnly', () => {
runtime.assertLog(['Task Event', 'Task']);
});

// @gate source
it('task with continuation', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('Task');
Expand All @@ -167,6 +173,7 @@ describe('SchedulerPostTaskOnly', () => {
runtime.assertLog(['Task Event', 'Continuation']);
});

// @gate source
it('multiple tasks', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('A');
Expand All @@ -179,6 +186,7 @@ describe('SchedulerPostTaskOnly', () => {
runtime.assertLog(['Task Event', 'A', 'B']);
});

// @gate source
it('multiple tasks with a yield in between', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('A');
Expand All @@ -199,6 +207,7 @@ describe('SchedulerPostTaskOnly', () => {
runtime.assertLog(['Task Event', 'B']);
});

// @gate source
it('cancels tasks', () => {
const task = scheduleCallback(NormalPriority, () => {
runtime.log('Task');
Expand All @@ -208,6 +217,7 @@ describe('SchedulerPostTaskOnly', () => {
runtime.assertLog([]);
});

// @gate source
it('throws when a task errors then continues in a new event', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('Oops!');
Expand All @@ -225,6 +235,7 @@ describe('SchedulerPostTaskOnly', () => {
runtime.assertLog(['Task Event', 'Yay']);
});

// @gate source
it('schedule new task after queue has emptied', () => {
scheduleCallback(NormalPriority, () => {
runtime.log('A');
Expand All @@ -242,6 +253,7 @@ describe('SchedulerPostTaskOnly', () => {
runtime.assertLog(['Task Event', 'B']);
});

// @gate source
it('schedule new task after a cancellation', () => {
const handle = scheduleCallback(NormalPriority, () => {
runtime.log('A');
Expand Down

0 comments on commit ea4c5b1

Please sign in to comment.