Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose TestModuleConfig interface #2113

Open
landau opened this issue Feb 11, 2022 · 1 comment
Open

Expose TestModuleConfig interface #2113

landau opened this issue Feb 11, 2022 · 1 comment

Comments

@landau
Copy link

landau commented Feb 11, 2022

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

type TestModuleConfig = {
replaceExtensions?: boolean;
inheritTypeDefs?: Module[];
} & Partial<
Pick<
ApplicationConfig,
'providers' | 'modules' | 'middlewares' | 'schemaBuilder'
>
> &
Partial<Pick<ModuleConfig, 'typeDefs' | 'resolvers'>>;

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
Copy link
Author

landau commented Feb 14, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant