Skip to content

Commit

Permalink
chore(prettier): baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
killtheliterate committed Nov 4, 2024
1 parent d7cc71c commit 60e7bd3
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 164 deletions.
6 changes: 1 addition & 5 deletions prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export default {
semi: false,
singleQuote: true,
trailingComma: 'es5',
}
export default {};
118 changes: 59 additions & 59 deletions src/__tests__/catch.test.ts
Original file line number Diff line number Diff line change
@@ -1,133 +1,133 @@
import { AnyAction } from 'redux'
import { call, CallEffect } from 'redux-saga/effects'
import { AnyAction } from "redux";
import { call, CallEffect } from "redux-saga/effects";

import { deferredAction, standardAction } from '../index'
import { deferredAction, standardAction } from "../index";

describe('standardAction()', () => {
const IO = { stdout: jest.fn() }
describe("standardAction()", () => {
const IO = { stdout: jest.fn() };

it('yields to the passed generator', () => {
it("yields to the passed generator", () => {
function* aSaga(io: typeof IO, action: { type: string }) {
yield call(io.stdout, action.type)
yield call(io.stdout, action.type);
}

const iterator = standardAction(aSaga, IO)({ type: 'AN_ACTION' })
const iterator = standardAction(aSaga, IO)({ type: "AN_ACTION" });

expect(iterator.next().value).toEqual(
call(aSaga, IO, { type: 'AN_ACTION' })
)
})
call(aSaga, IO, { type: "AN_ACTION" })
);
});

it('catches if the delegate saga throws', () => {
it("catches if the delegate saga throws", () => {
// eslint-disable-next-line require-yield
function* aSaga(_io: typeof IO, _action: AnyAction) {
throw new Error('oops')
throw new Error("oops");
}

const iterator = standardAction(aSaga, IO)({ type: 'AN_ACTION' })
const { done: doneA, value: valueA } = iterator.next()
const iterator = standardAction(aSaga, IO)({ type: "AN_ACTION" });
const { done: doneA, value: valueA } = iterator.next();

expect(doneA).toEqual(false)
expect(doneA).toEqual(false);

expect(valueA).toEqual(call(aSaga, IO, { type: 'AN_ACTION' }))
expect(valueA).toEqual(call(aSaga, IO, { type: "AN_ACTION" }));

const { value: valueB } = iterator.throw(Error('oops'))
const { value: valueB } = iterator.throw(Error("oops"));

expect(valueB).toEqual(call(IO.stdout, 'aSaga', Error('oops')))
})
})
expect(valueB).toEqual(call(IO.stdout, "aSaga", Error("oops")));
});
});

describe('deferredAction()', () => {
describe("deferredAction()", () => {
const IO = {
echo: <T>(msg: T) => msg,
sayNum: (num: number) => num,
sayStr: (str: string) => str,
stdout: jest.fn(),
}
};

it('yields to the passed generator', () => {
it("yields to the passed generator", () => {
const action = {
type: 'AN_ACTION',
type: "AN_ACTION",
meta: {
deferred: {
success: jest.fn(),
failure: jest.fn(),
},
},
}
};

function* aSaga(io: typeof IO, _action: AnyAction) {
yield call(io.sayNum, 123)
yield call(io.sayStr, 'hello')
yield call(io.sayNum, 123);
yield call(io.sayStr, "hello");
}

// This generator is *not* "aSaga", but instead the wrapper saga
const iterator = deferredAction(aSaga, IO)(action)
const iterator = deferredAction(aSaga, IO)(action);

expect(iterator.next().value).toEqual(call(aSaga, IO, action))
expect(iterator.next().value).toEqual(call(aSaga, IO, action));

expect(iterator.next('yielded').value).toEqual(
call(action.meta.deferred.success, 'yielded')
)
})
expect(iterator.next("yielded").value).toEqual(
call(action.meta.deferred.success, "yielded")
);
});

it('catches if the delegate saga throws', () => {
it("catches if the delegate saga throws", () => {
const action = {
type: 'AN_ACTION',
type: "AN_ACTION",
meta: {
deferred: {
success: jest.fn(),
failure: jest.fn(),
},
},
}
};

// eslint-disable-next-line require-yield
function* aSaga(_io: typeof IO, _action: AnyAction) {
throw new Error('welp...')
throw new Error("welp...");
}

const iterator = deferredAction(aSaga, IO)(action)
const iterator = deferredAction(aSaga, IO)(action);

expect(iterator.next().value).toEqual(call(aSaga, IO, action))
expect(iterator.next().value).toEqual(call(aSaga, IO, action));

expect(iterator.throw(Error('welp...')).value).toEqual(
call(IO.stdout, 'aSaga', Error('welp...'))
)
expect(iterator.throw(Error("welp...")).value).toEqual(
call(IO.stdout, "aSaga", Error("welp..."))
);

expect(iterator.next().value).toEqual(
call(action.meta.deferred.failure, Error('welp...'))
)
})
call(action.meta.deferred.failure, Error("welp..."))
);
});

it('passes the rest of meta', () => {
it("passes the rest of meta", () => {
const action = {
type: 'AN_ACTION',
type: "AN_ACTION",
meta: {
foobat: 'hey',
foobat: "hey",
deferred: {
success: jest.fn(),
failure: jest.fn(),
},
},
}
};

function* aSaga(
io: typeof IO,
_action: AnyAction
): Generator<CallEffect<unknown>> {
const result = yield call(io.echo, 'A message')
const result = yield call(io.echo, "A message");

Check warning on line 119 in src/__tests__/catch.test.ts

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Unsafe assignment of an `any` value

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return result
return result;
}

const iterator = deferredAction(aSaga, IO)(action)
const iterator = deferredAction(aSaga, IO)(action);

expect(iterator.next().value).toEqual(call(aSaga, IO, action))
expect(iterator.next().value).toEqual(call(aSaga, IO, action));

expect(iterator.next('A message').value).toEqual(
call(action.meta.deferred.success, 'A message')
)
})
})
expect(iterator.next("A message").value).toEqual(
call(action.meta.deferred.success, "A message")
);
});
});
100 changes: 50 additions & 50 deletions src/__tests__/typed-catch.test.ts
Original file line number Diff line number Diff line change
@@ -1,113 +1,113 @@
import { AnyAction } from 'redux'
import { call as tCall } from 'typed-redux-saga'
import { call } from 'redux-saga/effects'
import { AnyAction } from "redux";
import { call as tCall } from "typed-redux-saga";
import { call } from "redux-saga/effects";

import {
typedStandardAction as standardAction,
typedDeferredAction as deferredAction,
} from '../index'
} from "../index";

describe('typedStandardAction()', () => {
it('yields to the passed generator', () => {
const IO = { stdout: jest.fn() }
describe("typedStandardAction()", () => {
it("yields to the passed generator", () => {
const IO = { stdout: jest.fn() };

function* aSaga(io: typeof IO, action: AnyAction) {
yield call(io.stdout, action.type)
yield call(io.stdout, action.type);
}

const iterator = standardAction(aSaga, IO)({ type: 'AN_ACTION' })
const iterator = standardAction(aSaga, IO)({ type: "AN_ACTION" });

expect(iterator.next().value).toEqual(
call(aSaga, IO, { type: 'AN_ACTION' })
)
})
call(aSaga, IO, { type: "AN_ACTION" })
);
});

it('catches if the delegate saga throws', () => {
const IO = { stdout: jest.fn() }
it("catches if the delegate saga throws", () => {
const IO = { stdout: jest.fn() };

// eslint-disable-next-line require-yield
function* aSaga(_io: typeof IO, _action: AnyAction) {
throw new Error('oops')
throw new Error("oops");
}

const iterator = standardAction(aSaga, IO)({ type: 'AN_ACTION' })
const iterator = standardAction(aSaga, IO)({ type: "AN_ACTION" });

const { done: doneA, value: valueA } = iterator.next()
const { done: doneA, value: valueA } = iterator.next();

expect(doneA).toEqual(false)
expect(doneA).toEqual(false);

expect(valueA).toEqual(call(aSaga, IO, { type: 'AN_ACTION' }))
expect(valueA).toEqual(call(aSaga, IO, { type: "AN_ACTION" }));

const { value: valueB } = iterator.throw(Error('oops'))
const { value: valueB } = iterator.throw(Error("oops"));

expect(valueB).toEqual(call(IO.stdout, 'aSaga', Error('oops')))
})
})
expect(valueB).toEqual(call(IO.stdout, "aSaga", Error("oops")));
});
});

describe('typedDeferredAction()', () => {
it('yields to the passed generator', () => {
describe("typedDeferredAction()", () => {
it("yields to the passed generator", () => {
const IO = {
echo: <T>(msg: T) => msg,
sayNum: (num: number) => num,
stdout: jest.fn(),
}
};

const action = {
type: 'AN_ACTION',
type: "AN_ACTION",
meta: {
deferred: {
success: jest.fn(),
failure: jest.fn(),
},
},
}
};

function* aSaga(io: typeof IO, _action: typeof action) {
const aNumber = yield* tCall(io.sayNum, 1)
const aNumber = yield* tCall(io.sayNum, 1);

return aNumber
return aNumber;
}

const iterator = deferredAction(aSaga, IO)(action)
const iterator = deferredAction(aSaga, IO)(action);

expect(iterator.next().value).toEqual(call(aSaga, IO, action))
expect(iterator.next().value).toEqual(call(aSaga, IO, action));

expect(iterator.next('A message').value).toEqual(
call(action.meta.deferred.success, 'A message')
)
})
expect(iterator.next("A message").value).toEqual(
call(action.meta.deferred.success, "A message")
);
});

it('catches if the delegate saga throws', () => {
it("catches if the delegate saga throws", () => {
const IO = {
stdout: jest.fn(),
echo: (msg: unknown) => msg,
}
};

const action = {
type: 'AN_ACTION',
type: "AN_ACTION",
meta: {
deferred: {
success: jest.fn(),
failure: jest.fn(),
},
},
}
};

// eslint-disable-next-line require-yield
function* aSaga(_io: typeof IO, _action: typeof action) {
throw new Error('welp...')
throw new Error("welp...");
}

const iterator = deferredAction(aSaga, IO)(action)
const iterator = deferredAction(aSaga, IO)(action);

expect(iterator.next().value).toEqual(call(aSaga, IO, action))
expect(iterator.next().value).toEqual(call(aSaga, IO, action));

expect(iterator.throw(Error('welp...')).value).toEqual(
call(IO.stdout, 'aSaga', Error('welp...'))
)
expect(iterator.throw(Error("welp...")).value).toEqual(
call(IO.stdout, "aSaga", Error("welp..."))
);

expect(iterator.next().value).toEqual(
call(action.meta.deferred.failure, Error('welp...'))
)
})
})
call(action.meta.deferred.failure, Error("welp..."))
);
});
});
Loading

0 comments on commit 60e7bd3

Please sign in to comment.