Skip to content

Commit

Permalink
fix: Override default configurations.
Browse files Browse the repository at this point in the history
First with framework-specific defaults and then with caller-specified
config.
  • Loading branch information
cartant committed Mar 26, 2020
1 parent 04562c5 commit e4f5930
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
7 changes: 4 additions & 3 deletions source/ava/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export function configure(
assertDeepEqual: t.deepEqual.bind(t)
});
const configured = _configure((t: ExecutionContext) => ({
...configuration,
...factory(t)
...defaults(),
...factory(t),
...configuration
}));
const marbles: MarblesFunction = configured.marbles;

Expand All @@ -71,7 +72,7 @@ export function configure(
return { cases, marbles };
}

const { cases, marbles } = configure(defaults());
const { cases, marbles } = configure({});
export { cases, marbles };

export function fakeSchedulers(
Expand Down
7 changes: 4 additions & 3 deletions source/jasmine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function configure(
} {
const { assert: defaultAssert } = defaults();
const { marbles } = _configure({
...configuration,
...defaults(),
assert: (a, m) => {
// It seems that withContext was introduced in Jasmine 3.3.0 and,
// prior to that, user-defined messages for failures weren't
Expand All @@ -57,7 +57,8 @@ export function configure(
defaultAssert!(a, m);
}
},
assertDeepEqual: (a, e) => expect(a).toEqual(e)
assertDeepEqual: (a, e) => expect(a).toEqual(e),
...configuration
});

function cases<T extends UnnamedCase>(
Expand Down Expand Up @@ -94,7 +95,7 @@ export function configure(
return { cases, marbles };
}

const { cases, marbles } = configure(defaults());
const { cases, marbles } = configure({});
export { cases, marbles };

export function fakeSchedulers(fakeTest: () => any): () => any {
Expand Down
12 changes: 8 additions & 4 deletions source/jest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export function configure(
marbles: MarblesFunction;
} {
const { marbles } = _configure({
...configuration,
...defaults(),
assertDeepEqual: (a, e) => expect(a).toEqual(e),
frameworkMatcher: true
frameworkMatcher: true,
...configuration
});

function cases<T extends UnnamedCase>(
Expand All @@ -66,7 +67,10 @@ export function configure(
)
);
} else {
t(c.name, marbles((m, ...rest: any[]) => func(m, c, ...rest)));
t(
c.name,
marbles((m, ...rest: any[]) => func(m, c, ...rest))
);
}
}, cases);
});
Expand All @@ -75,5 +79,5 @@ export function configure(
return { cases, marbles };
}

const { cases, marbles } = configure(defaults());
const { cases, marbles } = configure({});
export { cases, marbles };
7 changes: 4 additions & 3 deletions source/tape/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export function configure(
assertDeepEqual: t.deepEqual.bind(t)
});
const configured = _configure((t: tape.Test) => ({
...configuration,
...factory(t)
...defaults(),
...factory(t),
...configuration
}));
const marbles: MarblesFunction = configured.marbles;

Expand All @@ -69,7 +70,7 @@ export function configure(
return { cases, marbles };
}

const { cases, marbles } = configure(defaults());
const { cases, marbles } = configure({});
export { cases, marbles };

export function fakeSchedulers(
Expand Down

0 comments on commit e4f5930

Please sign in to comment.