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

mocha --watch breaks on second run #559

Closed
AndrewO opened this issue Mar 3, 2020 · 2 comments
Closed

mocha --watch breaks on second run #559

AndrewO opened this issue Mar 3, 2020 · 2 comments
Labels
Question ❔ Not future request, proposal or bug issue Solved ✔️ The issue has been solved

Comments

@AndrewO
Copy link

AndrewO commented Mar 3, 2020

Describe the bug

When I test my project with mocha, it runs fine. When I run with mocha --watch, the first test passes and the second one reports Error: Schema must contain uniquely named types but contains multiple types named "CreateNoteResponse".

To Reproduce

Using this .mocharrc.js:

'use strict';

module.exports = {
	extension: ['ts'],
	opts: false,
	require: [
		'reflect-metadata',
		'ts-node/register'
	],
	recursive: true,
	spec: 'src/**/*.test.ts',
	'watch-files': ['src/**/*.ts', 'test/*.ts'],
};
  1. Run mocha --watch
  2. Observe tests pass.
  3. Save a watched file.
  4. Observe an error.

Expected behavior

I'd expect that reloading works. Possibly related to Webpack hot reload issues in #289 ?

Logs

     Error: Schema must contain uniquely named types but contains multiple types named "CreateNoteResponse".
      at typeMapReducer (node_modules/graphql/type/schema.js:262:13)
      at Array.reduce (<anonymous>)
      at new GraphQLSchema (node_modules/graphql/type/schema.js:145:28)
      at Function.generateFromMetadataSync (node_modules/type-graphql/dist/schema/schema-generator.js:31:24)
      at Function.<anonymous> (node_modules/type-graphql/dist/schema/schema-generator.js:16:33)

Enviorment (please complete the following information):

  • OS: macOS 10.14.6
  • Node: v10.16.3
  • Package version: v0.17.6
  • TypeScript version: 3.8.2

Additional context

Way back when I set up the project, I used Jest instead. I don't believe it had this issue, but I can't confirm that.

Also, I attempted to solve this with getMetadataStorage().clear() before running buildSchema, but that resulted in Error: Type Query must define one or more fields..

The issue occurs regardless of whether or not you use buildSchema or buildSchemaSync.

@MichalLytek
Copy link
Owner

Way back when I set up the project, I used Jest instead. I don't believe it had this issue, but I can't confirm that.

Jest spawn new Node process for each test run, so it has a clear global metadata storage.

If you want to use mocha, you need to upgrade to type-graphql@beta as it contains a fix for multiple schemas and schemas leaks.

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Question ❔ Not future request, proposal or bug issue labels Mar 3, 2020
@MichalLytek
Copy link
Owner

Closing for a housekeeping purposes 🔒

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question ❔ Not future request, proposal or bug issue Solved ✔️ The issue has been solved
Projects
None yet
Development

No branches or pull requests

2 participants