Skip to content

Commit

Permalink
ci(build): ensure dist folder is build with proper exports
Browse files Browse the repository at this point in the history
  • Loading branch information
iamogbz committed Sep 17, 2020
1 parent bd761af commit 59545b4
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/nodejs.yml
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Build
run: |
npm run build
- name: Integration
run: |
npm run e2e
- name: Deploy
if: matrix.node-version == '12.x' && github.ref == 'refs/heads/master'
env:
Expand Down
12 changes: 12 additions & 0 deletions jest.e2e.config.json
@@ -0,0 +1,12 @@
{
"preset": "ts-jest",
"moduleDirectories": ["./node_modules", "<rootDir>/node_modules", "."],
"moduleNameMapper": {
"src(.*)": "<rootDir>/dist$1"
},
"testPathIgnorePatterns": [
"./artifacts/",
"./dist/",
"./node_modules/"
]
}
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -34,6 +34,7 @@
"clean": "rm -rf ./dist",
"commit": "git-cz",
"dedupe": "npm dedupe",
"e2e": "jest -c ./jest.e2e.config.json tests/index",
"lint": "eslint . --max-warnings=0 --ext .js,.jsx,.ts,.tsx",
"release": "semantic-release",
"test": "jest",
Expand All @@ -57,7 +58,8 @@
"coverageDirectory": "./artifacts/coverage",
"coveragePathIgnorePatterns": [
"<rootDir>/node_modules",
"<rootDir>/tests"
"<rootDir>/tests",
"<rootDir>/e2e"
],
"testPathIgnorePatterns": [
"./artifacts/",
Expand Down
2 changes: 1 addition & 1 deletion src/createAction.ts
Expand Up @@ -2,7 +2,7 @@ export function createAction<T extends string, P, S>(
type: T,
prepare = (payload?: P): Partial<Action<T, P>> => ({ payload }),
): ActionCreator<T, P, S> {
return function createAction(payload): Action<T, P> {
return function createAction(payload) {
const partialAction = prepare(payload);
return { ...partialAction, type };
};
Expand Down
2 changes: 1 addition & 1 deletion src/createContext.ts
Expand Up @@ -5,7 +5,7 @@ import { setGlobalContext } from "./components/Context";
function createUnimplemented(objectName?: string): (m: string) => () => never {
const prefix = objectName ? `${objectName}.` : "";
return function createUnimplemented(methodName) {
return function unimplemented(): never {
return function unimplemented() {
throw new Error(`Unimplemented method: ${prefix}${methodName}`);
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/createReducer.ts
Expand Up @@ -11,7 +11,7 @@ export function createReducer<
a !== undefined &&
Object.prototype.hasOwnProperty.call(actionTypeToReducer, a.type);

return function actionReducer(state = initialState, action?): S {
return function actionReducer(state = initialState, action?) {
if (!isReducerActionType(action)) {
return defaultReducer?.(state, action) ?? state;
}
Expand Down
5 changes: 2 additions & 3 deletions src/utils/actionTypes.ts
@@ -1,6 +1,5 @@
const randomString = (): string => Math.random().toString(36).substring(7);
const ns = (s: TemplateStringsArray): string =>
`@@context/${s}/${randomString()}`;
const randomString = () => Math.random().toString(36).substring(7);
const ns = (s: TemplateStringsArray) => `@@context/${s}/${randomString()}`;

export const ActionTypes = {
INIT: ns`INIT`,
Expand Down
4 changes: 1 addition & 3 deletions src/utils/applyMiddleware.ts
Expand Up @@ -4,9 +4,7 @@ import { compose } from "./compose";
export function applyMiddleware<S, T extends string, P>(
...middlewares: Middleware<S, T, P>[]
): ContextEnhance<S, T, P> {
return function enhancer(
context: ContextValue<S, T, P>,
): ContextValue<S, T, P> {
return function enhancer(context: ContextValue<S, T, P>) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function dispatchStub(...args: unknown[]): never {
throw new Error(
Expand Down
5 changes: 1 addition & 4 deletions src/utils/combineReducers.ts
Expand Up @@ -5,10 +5,7 @@ export function combineReducers<S, N extends string, T extends string, P>(
reducerMapping: DuckReducerMapping<S, N, T, P>,
): Reducer<Record<N, S>, T, P> {
const reducers = getEntries(reducerMapping);
return function (
state: Record<N, S> = initialState,
action,
): Record<string, S> {
return function (state: Record<N, S> = initialState, action) {
return reducers.reduce(function reduce(acc, [name, reducer]) {
acc[name] = reducer(state[name], action);
return acc;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/combineSelectors.ts
Expand Up @@ -12,7 +12,7 @@ export function combineSelectors<
if (!selectors) return;
const duckSelectors = {} as SelectorMapping<S, R, T, P, Q>;
for (const s of Object.keys(selectors) as Q[]) {
duckSelectors[s] = (state: S): R =>
duckSelectors[s] = (state) =>
selectors[s](((state as unknown) as Record<string, S>)[duckName]);
}
return duckSelectors;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/polyfillSymbol.ts
@@ -1,4 +1,4 @@
function polyfillSymbol(name: string): void {
function polyfillSymbol(name: string) {
if (!Symbol[name]) {
Object.defineProperty(Symbol, name, { value: Symbol(name) });
}
Expand Down
4 changes: 2 additions & 2 deletions tests/hooks.test.ts
Expand Up @@ -5,8 +5,8 @@ import { useObservable } from "src/hooks/useObservable";

describe("useDispatch", () => {
const mockValue = {
dispatch: async (a: Action<string, string>): Promise<typeof a> => a,
reducer: (): null => null,
dispatch: async (a: Action<string, string>) => a,
reducer: () => null,
state: null,
subscribe: () => ({ closed: true, unsubscribe: () => undefined }),
};
Expand Down
18 changes: 9 additions & 9 deletions tests/index.mock.tsx
Expand Up @@ -16,12 +16,12 @@ export function createMocks() {
Record<string, unknown>,
string,
unknown
> = () => (next) => (action): Promise<typeof action> => next(action);
> = () => (next) => (action) => next(action);

const DECREMENT = "decrement";
const INCREMENT = "increment";
const decrement = (state: number): number => state - 1;
const increment = jest.fn((state): number => state + 1);
const decrement = (state: number) => state - 1;
const increment = jest.fn((state: number) => state + 1);
const counterReducer: (s: number, a?: Action<string>) => number = (
state,
action,
Expand All @@ -39,17 +39,17 @@ export function createMocks() {
initialState: 0,
name: "counter",
reducers: { [DECREMENT]: counterReducer, [INCREMENT]: counterReducer },
selectors: { get: (state): number => state },
selectors: { get: (state) => state },
});

const INIT = "init";
const init = jest.fn((): boolean => true);
const init = jest.fn(() => true);
const initDuck = createDuck({
actionMapping: { [ActionTypes.INIT]: INIT },
initialState: false,
name: "init",
reducers: { [INIT]: init },
selectors: { get: (state): boolean => state },
selectors: { get: (state) => state },
});

const dummyDuck = createDuck({
Expand All @@ -70,7 +70,7 @@ export function createMocks() {

const RootProvider = createRootProvider(Context);

function Example(): React.ReactElement {
function Example() {
const increment = useDispatch(counterDuck.actions.increment);
const init = useSelector(rootDuck.selectors.init?.get);
const count = useSelector(rootDuck.selectors.counter?.get, Context);
Expand All @@ -86,7 +86,7 @@ export function createMocks() {

const logger: Middleware<Record<string, unknown>, string, unknown> = ({
getState,
}) => (next) => async (action): Promise<typeof action> => {
}) => (next) => async (action) => {
// eslint-disable-next-line no-console
console.log("action to dispatch", action);
// Call the next dispatch method in the middleware chain.
Expand All @@ -110,7 +110,7 @@ export function createMocks() {
unknown
> = ({ dispatch }) => {
dispatch({ type: "SOME_ACTION" });
return () => async (action): Promise<typeof action> => action;
return () => async (action) => action;
};
const emptyRootDuck = createRootDuck();
const ErrorContext = createContext(
Expand Down
14 changes: 6 additions & 8 deletions tests/index.test.tsx
Expand Up @@ -11,10 +11,9 @@ import {
} from "src";
import { bindActionCreators } from "src/utils/bindActionCreators";
import { connect } from "src/utils/connect";
// eslint-disable-next-line jest/no-mocks-import
import { createMocks } from "./index.mock";

describe("integration", (): void => {
describe("integration", () => {
const {
EnhancedContext,
ErrorContext,
Expand Down Expand Up @@ -112,9 +111,8 @@ describe("integration", (): void => {

describe("createConnect", () => {
const mapStateToProps = createStructuredSelector({
count: rootDuck.selectors.counter?.get ?? ((): number => 0),
isInitialised:
rootDuck.selectors.init?.get ?? ((): boolean => false),
count: rootDuck.selectors.counter?.get ?? (() => 0),
isInitialised: rootDuck.selectors.init?.get ?? (() => false),
});
const mapDispatchToProps = {
increment: rootDuck.actions.counter.increment,
Expand Down Expand Up @@ -262,7 +260,7 @@ describe("integration", (): void => {

it("forwards ref to wrapped component", async () => {
class ClassComponent extends React.PureComponent {
render(): React.ReactElement {
render() {
return <div></div>;
}
}
Expand All @@ -288,7 +286,7 @@ describe("integration", (): void => {
.spyOn(console, "error")
.mockImplementationOnce(() => undefined);
class ClassComponent extends React.PureComponent {
render(): React.ReactElement {
render() {
return <div></div>;
}
}
Expand Down Expand Up @@ -318,7 +316,7 @@ describe("integration", (): void => {

describe("contextSubscribe", () => {
const listener = jest.fn();
function Sample(): React.ReactElement {
function Sample() {
const value = React.useContext(GlobalContext);
React.useEffect(
function contextSubscribe() {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.prod.json
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "dist", "tests"]
"exclude": ["node_modules", "dist", "tests", "e2e"]
}

0 comments on commit 59545b4

Please sign in to comment.