feat(testing): removed early testBedSetup context resolving
MODIFY
packages/@integration/test/http.integration.spec.ts
packages/@integration/test/http.integration.spec.ts
import { pipe } from 'fp-ts/lib/pipeable';
import { HttpStatus } from '@marblejs/core';
import { ContentType } from '@marblejs/core/dist/+internal/http';
-import { createHttpTestBed, createTestBedSetup, TestBedSetup, HttpTestBed } from '@marblejs/testing';
+import { createHttpTestBed, createTestBedSetup } from '@marblejs/testing';
import { listener } from '../src/http';
const useTestBedSetup = createTestBedSetup({
@@ -9,15 +9,9 @@ const useTestBedSetup = createTestBedSetup({
});
describe('API integration', () => {
- let testBedSetup: TestBedSetup<HttpTestBed>;
+ const testBedSetup = useTestBedSetup()
- beforeEach(async () => {
- testBedSetup = await useTestBedSetup();
- });
-
- afterEach(async () => {
- return testBedSetup.cleanup();
- });
+ afterEach(() => testBedSetup.cleanup());
test('POST "/" returns 404 when route not found', async () => {
const testBed = await testBedSetup.useTestBed();

MODIFY
packages/testing/src/testBed/testBedContainer.spec.ts
packages/testing/src/testBed/testBedContainer.spec.ts
@@ -30,7 +30,7 @@ describe('#createTestBedSetup cleanup container', () => {
});
test('automatically closes bound EventBus', async () => {
- const { useTestBed, cleanup } = await useTestBedSetup();
+ const { useTestBed, cleanup } = useTestBedSetup();
const testBed = await useTestBed();
const eventBus = useContext(EventBusToken)(testBed.ask);
@@ -46,7 +46,7 @@ describe('#createTestBedSetup cleanup container', () => {
});
test('automatically cleanups custom dependency', async () => {
- const { useTestBed, cleanup } = await useTestBedSetup();
+ const { useTestBed, cleanup } = useTestBedSetup();
const testBed = await useTestBed([customDependencyBound]);
const customDependency = useContext(customDependencyToken)(testBed.ask);

MODIFY
packages/testing/src/testBed/testBedSetup.interface.ts
packages/testing/src/testBed/testBedSetup.interface.ts
import { IO } from 'fp-ts/lib/IO';
-import { BoundDependency, ContextProvider } from '@marblejs/core';
+import { BoundDependency } from '@marblejs/core';
import { DependencyCleanup } from './testBedContainer.interface';
import { TestBed, TestBedFactory } from './testBed.interface';
@@ -10,7 +10,6 @@ export interface TestBedSetupConfig<T extends TestBed> {
}
export interface TestBedSetup<T extends TestBed> {
- ask: ContextProvider;
useTestBed: TestBedFactory<T>;
cleanup: IO<Promise<void>>;
}

MODIFY
packages/testing/src/testBed/testBedSetup.spec.ts
packages/testing/src/testBed/testBedSetup.spec.ts
@@ -21,26 +21,8 @@ describe('#createTestBedSetup - HTTP', () => {
const useTestBedSetup = createTestBedSetup({ testBed, dependencies });
- test('#useTestBedSetup.ask has access to default dependencies', async () => {
- const { ask, cleanup } = await useTestBedSetup(prependDependencies);
- const dependency = useContext(dependency1.token)(ask);
-
- expect(dependency).toEqual(dependency1.value);
-
- await cleanup();
- });
-
- test('#useTestBedSetup.ask has access to prepend dependencies', async () => {
- const { ask, cleanup } = await useTestBedSetup(prependDependencies);
- const dependency = useContext(dependency2.token)(ask);
-
- expect(dependency).toEqual(dependency2.value);
-
- await cleanup();
- });
-
test('testBed initialized with useTestBed has access to default dependencies', async () => {
- const { useTestBed, cleanup } = await useTestBedSetup(prependDependencies);
+ const { useTestBed, cleanup } = useTestBedSetup(prependDependencies);
const testBed = await useTestBed(customDependencies);
const dependency = useContext(dependency1.token)(testBed.ask);
@@ -50,7 +32,7 @@ describe('#createTestBedSetup - HTTP', () => {
});
test('testBed initialized with useTestBed has access to prepend dependencies', async () => {
- const { useTestBed, cleanup } = await useTestBedSetup(prependDependencies);
+ const { useTestBed, cleanup } = useTestBedSetup(prependDependencies);
const testBed = await useTestBed(customDependencies);
const dependency = useContext(dependency2.token)(testBed.ask);
@@ -60,7 +42,7 @@ describe('#createTestBedSetup - HTTP', () => {
});
test('testBed initialized with useTestBed has access to custom dependencies', async () => {
- const { useTestBed, cleanup } = await useTestBedSetup(prependDependencies);
+ const { useTestBed, cleanup } = useTestBedSetup(prependDependencies);
const testBed = await useTestBed(customDependencies);
const dependency = useContext(dependency3.token)(testBed.ask);
@@ -71,13 +53,12 @@ describe('#createTestBedSetup - HTTP', () => {
test('#useTestBedSetup can override subset of dependencies', async () => {
const newValue = createUuid();
- const { useTestBed, ask, cleanup } = await useTestBedSetup([
+ const { useTestBed, cleanup } = useTestBedSetup([
bindTo(dependency1.token)(() => newValue),
]);
const testBed = await useTestBed();
- expect(useContext(dependency1.token)(ask)).toEqual(newValue);
expect(useContext(dependency1.token)(testBed.ask)).toEqual(newValue);
await cleanup();
@@ -85,7 +66,7 @@ describe('#createTestBedSetup - HTTP', () => {
test('#useTestBed can override subset of dependencies', async () => {
const newValue = createUuid();
- const { useTestBed, cleanup } = await useTestBedSetup(prependDependencies);
+ const { useTestBed, cleanup } = useTestBedSetup(prependDependencies);
const testBed = await useTestBed([
bindTo(dependency2.token)(() => newValue),
@@ -95,16 +76,4 @@ describe('#createTestBedSetup - HTTP', () => {
await cleanup();
});
-
- test('#useTestBedSetup doesn\'t have access to #useTestBed dependencies', async () => {
- const { ask, useTestBed, cleanup } = await useTestBedSetup(prependDependencies);
-
- await useTestBed(customDependencies);
-
- jest.spyOn(console, 'error').mockImplementation();
-
- expect(() => useContext(dependency3.token)(ask)).toThrow();
-
- await cleanup();
- });
});

MODIFY
packages/testing/src/testBed/testBedSetup.ts
packages/testing/src/testBed/testBedSetup.ts
-import { BoundDependency, contextFactory, lookup } from '@marblejs/core';
+import { BoundDependency } from '@marblejs/core';
import { TestBedSetupConfig, TestBedSetup } from './testBedSetup.interface';
import { createTestBedContainer } from './testBedContainer';
import { TestBed } from './testBed.interface';
@@ -6,20 +6,13 @@ import { TestBed } from './testBed.interface';
type CreateTestBedSetup = <T extends TestBed>
(config: TestBedSetupConfig<T>) =>
(prependDependencies?: readonly BoundDependency<any>[]) =>
- Promise<TestBedSetup<T>>
+ TestBedSetup<T>
-export const createTestBedSetup: CreateTestBedSetup = config => async (prependDependencies = []) => {
+export const createTestBedSetup: CreateTestBedSetup = config => (prependDependencies = []) => {
const { dependencies: defaultDependencies = [], cleanups = [] } = config;
const { cleanup, register } = createTestBedContainer({ cleanups });
- const boundContext = await contextFactory(
- ...defaultDependencies,
- ...prependDependencies,
- );
-
- const ask = lookup(boundContext);
-
const useTestBed = async (dependencies: BoundDependency<any>[] = []) => {
const testBed = await config.testBed([
...defaultDependencies,
@@ -33,7 +26,6 @@ export const createTestBedSetup: CreateTestBedSetup = config => async (prependDe
};
return {
- ask,
useTestBed,
cleanup,
};

feat(testing): removed early testBedSetup context resolving