#!/usr/bin/env bash
set -ex
git checkout ${PREVIOUS_VERSION} || echo 'testing'
npm install
# start
npm install --save-dev eslint-plugin-redux-saga
npx rollup-umd-scripts peer add redux-saga --singleton
# add lint sagas
cat > tmp.json << EOL
{
      "redux-saga/no-yield-in-race": 2,
      "redux-saga/yield-effects": 2
}
EOL
npx rollup-umd-scripts lint add tmp.json
rm tmp.json
npx rollup-umd-scripts lint plugin redux-saga
# add sagas
cat > src/components/sagas.js << EOL
import { put } from 'redux-saga/effects';

export function* increment() {
  yield put({ type: 'INCREMENT' });
}

EOL
# add sagas test
cat > src/components/tests/sagas.test.js << EOL
import { put } from 'redux-saga/effects';
import { increment } from '../sagas';

describe('increment Saga test', () => {
  it('should increment', () => {
    const generator = increment();
    // eslint-disable-next-line redux-saga/yield-effects
    expect(generator.next().value).toEqual(put({ type: 'INCREMENT' }));
    expect(generator.next()).toEqual({ done: true, value: undefined });
  });
});

EOL
