<commit_before>import {
  call,
  cancel,
  cancelled,
  fork,
  put,
  race,
  spawn,
  take,
} from 'redux-saga/effects';

import { expectSaga } from '../../src';
import { delay } from '../../src/utils/async';

function* regularBackgroundSaga() {
  yield put({ type: 'DONE' });
}

const createRegularSaga = effectCreator => function* saga() {
  const task = yield effectCreator(regularBackgroundSaga);
  return task.name;
};

const createParallelSaga = effectCreator => function* saga() {
  const [task] = yield [effectCreator(regularBackgroundSaga)];
  return task.name;
};

const createRaceSaga = effectCreator => function* saga() {
  const { saga: task } = yield race({ saga: effectCreator(regularBackgroundSaga) });
  return task.name;
};

function* cancelledBackgroundSaga() {
  try {
    yield take('WAIT');
  } finally {
    if (yield cancelled()) {
      yield put({ type: 'DONE', payload: 'cancelled' });
    } else {
      yield put({ type: 'DONE', payload: 'not cancelled' });
    }
  }
}

const createCancelSaga = effectCreator => function* saga() {
  const task = yield effectCreator(cancelledBackgroundSaga);
  yield call(delay, 50);
  yield cancel(task);
};

const createCancelParallelSaga = effectCreator => function* saga() {
  const [task] = yield [effectCreator(cancelledBackgroundSaga)];
  yield call(delay, 50);
  yield cancel(task);
};

const createCancelRaceSaga = effectCreator => function* saga() {
  const { saga: task } = yield race({ saga: effectCreator(cancelledBackgroundSaga) });
  yield call(delay, 50);
  yield cancel(task);
};

test('wrapped sagas return a task with a name referring to the forked saga', () => {
  const saga = createRegularSaga(fork);

  return expectSaga(saga)
    .returns('regularBackgroundSaga')
    .run();
});

test('wrapped sagas return a task with a name referring to the spawned saga', () => {
  const saga = createRegularSaga(spawn);

  return expectSaga(saga)
    .returns('regularBackgroundSaga')
    .run();
});

test('providers receive task with name referring to forked saga', () => {
  const saga = createRegularSaga(fork);

  return expectSaga(saga)
    .provide({
      cancel(task, next) {
        expect(task.name).toBe('foo');
        return next();
      },
    })
    .returns('regularBackgroundSaga')
    .run();
});

test('wrapped sagas return a task with a name referring to the parallel forked saga', () => {
  const saga = createParallelSaga(fork);

  return expectSaga(saga)
    .returns('regularBackgroundSaga')
    .run();
});

test('wrapped sagas return a task with a name referring to the parallel spawned saga', () => {
  const saga = createParallelSaga(spawn);

  return expectSaga(saga)
    .returns('regularBackgroundSaga')
    .run();
});

test('wrapped sagas return a task with a name referring to the race forked saga', () => {
  const saga = createRaceSaga(fork);
<commit_msg>Remove unnecessary test<commit_after>import {
  call,
  cancel,
  cancelled,
  fork,
  put,
  race,
  spawn,
  take,
} from 'redux-saga/effects';

import { expectSaga } from '../../src';
import { delay } from '../../src/utils/async';

function* regularBackgroundSaga() {
  yield put({ type: 'DONE' });
}

const createRegularSaga = effectCreator => function* saga() {
  const task = yield effectCreator(regularBackgroundSaga);
  return task.name;
};

const createParallelSaga = effectCreator => function* saga() {
  const [task] = yield [effectCreator(regularBackgroundSaga)];
  return task.name;
};

const createRaceSaga = effectCreator => function* saga() {
  const { saga: task } = yield race({ saga: effectCreator(regularBackgroundSaga) });
  return task.name;
};

function* cancelledBackgroundSaga() {
  try {
    yield take('WAIT');
  } finally {
    if (yield cancelled()) {
      yield put({ type: 'DONE', payload: 'cancelled' });
    } else {
      yield put({ type: 'DONE', payload: 'not cancelled' });
    }
  }
}

const createCancelSaga = effectCreator => function* saga() {
  const task = yield effectCreator(cancelledBackgroundSaga);
  yield call(delay, 50);
  yield cancel(task);
};

const createCancelParallelSaga = effectCreator => function* saga() {
  const [task] = yield [effectCreator(cancelledBackgroundSaga)];
  yield call(delay, 50);
  yield cancel(task);
};

const createCancelRaceSaga = effectCreator => function* saga() {
  const { saga: task } = yield race({ saga: effectCreator(cancelledBackgroundSaga) });
  yield call(delay, 50);
  yield cancel(task);
};

test('wrapped sagas return a task with a name referring to the forked saga', () => {
  const saga = createRegularSaga(fork);

  return expectSaga(saga)
    .returns('regularBackgroundSaga')
    .run();
});

test('wrapped sagas return a task with a name referring to the spawned saga', () => {
  const saga = createRegularSaga(spawn);

  return expectSaga(saga)
    .returns('regularBackgroundSaga')
    .run();
});

test('wrapped sagas return a task with a name referring to the parallel forked saga', () => {
  const saga = createParallelSaga(fork);

  return expectSaga(saga)
    .returns('regularBackgroundSaga')
    .run();
});

test('wrapped sagas return a task with a name referring to the parallel spawned saga', () => {
  const saga = createParallelSaga(spawn);

  return expectSaga(saga)
    .returns('regularBackgroundSaga')
    .run();
});

test('wrapped sagas return a task with a name referring to the race forked saga', () => {
  const saga = createRaceSaga(fork);

{'fraction_non_alphanumeric': 0.13833701250919794, 'fraction_numerical': 0.002207505518763797, 'mean_word_length': 4.129245283018868, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2546269', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1693, 'n_words': 480}