Skip to content

mocha --watch breaks on second run #559

Closed
@AndrewO

Description

@AndrewO

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Question ❔Not future request, proposal or bug issueSolved ✔️The issue has been solved

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions