graphql-modules icon indicating copy to clipboard operation
graphql-modules copied to clipboard

Expose TestModuleConfig interface

Open landau opened this issue 3 years ago • 1 comments
trafficstars

Is your feature request related to a problem? Please describe.

In tests, I may want to define a variable of type TestModuleConfig scoped for the entire test suite. It is not possible to get compile errors at the declaration site because TestModuleConfig is not exposed. Further, if I want to modify that object later, I won't receive compile time errors at that line of code.

Describe the solution you'd like

Export this type to users of graphql-modules https://github.com/Urigo/graphql-modules/blob/75552e6775202a8c8a69d3aa587033d9c0987da2/packages/graphql-modules/src/testing/test-module.ts#L29-L38

Describe alternatives you've considered

Copy/pasta of the type into a project or each test file is not ideal, especially if the type changes on this project.

Additional context If the type is exposed, users would be able to do this.

// using something like Jest
describe('my test', () => {
  let config: TestModuleConfig;

  beforeEach(() => {
    config = { ...baseConfigStuff };
  });

 test('first test', () => { 
    const app = testkit.mockModule(someModule, config);
  });

  test('second test which modifies config', () => { 
    config.typeDefs = 'wrong type'; // GET AN ERROR RIGHT HERE'
    const app = testkit.mockModule(someModule, config);
  });

Perhaps there are other types worth exporting as well, but this is one I've come across thus far.

landau avatar Feb 11 '22 19:02 landau

I realize now that I could get the config setting in this manner:

let testModuleConfig:  NonNullable<Parameters<typeof testkit.testModule>['1']>;

...but that can quickly become burdensome as the number of tests increase.

landau avatar Feb 14 '22 16:02 landau