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

TypeError: Cannot read property 'some' of undefined #1387

Closed
felinto-dev opened this issue Feb 16, 2021 · 11 comments
Closed

TypeError: Cannot read property 'some' of undefined #1387

felinto-dev opened this issue Feb 16, 2021 · 11 comments

Comments

@felinto-dev
Copy link

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I'm trying to use "GraphQL CLI Plugin" in e2e tests following this tutorial:
https://docs.nestjs.com/graphql/cli-plugin#integration-with-ts-jest-e2e-tests
But the code does not work because when I run the e2e tests I get this error:

api_1  | > jest --config ./test/jest-e2e.json
api_1  |
api_1  | FAIL test/modules/auth/auth.e2e-spec.ts
api_1  |    Test suite failed to run
api_1  |
api_1  |     TypeError: Cannot read property 'some' of undefined
api_1  |
api_1  |       4 | module.exports.name = 'nestjs-graphql-transformer';
api_1  |       5 | module.exports.version = 1;
api_1  |     > 6 | module.exports.factory = (cs) => transformer.before({}, cs.tsCompiler.program);
api_1  |         |                                                            ^
api_1  |       7 |
api_1  |
api_1  |       at ConfigSet.isTestFile (../node_modules/ts-jest/dist/config/config-set.js:436:40)
api_1  |       at ../node_modules/ts-jest/dist/compiler/language-service.js:116:55
api_1  |           at Array.filter (<anonymous>)
api_1  |       at Object.exports.initializeLanguageServiceInstance (../node_modules/ts-jest/dist/compiler/language-service.js:116:10)
api_1  |       at Object.exports.createCompilerInstance (../node_modules/ts-jest/dist/compiler/instance.js:51:30)
api_1  |       at ConfigSet.get (../node_modules/ts-jest/dist/config/config-set.js:396:31)
api_1  |       at ConfigSet.<anonymous> (../node_modules/ts-jest/dist/utils/memoize.js:44:24)
api_1  |       at Object.module.exports.factory (test/ast.ts:6:60)
api_1  |       at ../node_modules/ts-jest/dist/config/config-set.js:267:61
api_1  |           at Array.map (<anonymous>)

These are some relevant files about this issue:

jest-e2e.json:

{
  "moduleDirectories": [
    "node_modules",
    "src"
  ],
  "moduleFileExtensions": ["js", "json", "ts"],
  "modulePathIgnorePatterns": ["<rootDir>/dist"],
  "moduleNameMapper": {
    "@/(.*)": "<rootDir>/src/$1"
  },
  "rootDir": "..",
  "testEnvironment": "node",
  "testRegex": ".e2e-spec.ts$",
  "transform": {
    "^.+\\.(t|j)s$": "ts-jest"
  },
  "globals": {
    "ts-jest": {
      "astTransformers": {
        "before": ["<rootDir>/test/ast.ts"]
      }
    }
  }
}

ast.ts:

// eslint-disable-next-line @typescript-eslint/no-var-requires
const transformer = require('@nestjs/graphql/plugin');

module.exports.name = 'nestjs-graphql-transformer';
module.exports.version = 1;
module.exports.factory = (cs) => transformer.before({}, cs.tsCompiler.program);

package.json:

    "test:e2e": "npm run build && jest --config ./test/jest-e2e.json",

Environment


Nest version: 7.5
 
For Tooling issues:
- Node version: 15.15.5
- Platform:  Windows

Others:
@nestjs/graphq: 7.9.8
ts-jest: 26.5.0
ts-node: 9.1.1
@kamilmysliwiec
Copy link
Member

Please provide a minimum reproduction repository.

@felinto-dev
Copy link
Author

felinto-dev commented Feb 16, 2021

Please provide a minimum reproduction repository.

You need to have Docker installed to replicate this issue.

  1. Unzip the package
  2. Change the current directory to the zip directory
  3. npm i
  4. npm run test:e2e-docker

@kamilmysliwiec
Copy link
Member

Could you please create a Github repository (instead of sending a .zip file)?

@felinto-dev
Copy link
Author

felinto-dev commented Feb 16, 2021

It was not my intention for this project to be public, but ok, I did it
https://github.com/felinto-dev/repo-fntwork-nestjs-issue

I appreciate your help.

@kamilmysliwiec
Copy link
Member

Would you be able to make this a minimal reproduction repository (without any additional, unnecessary modules?). This way you wouldn't have to share your entire project too.

@felinto-dev
Copy link
Author

felinto-dev commented Feb 16, 2021

I am able to replicate the bug

I used this nests sample project as minimal repository.
https://github.com/nestjs/nest/tree/master/sample/23-graphql-code-first

Please, check the git commit to check what files I changed to reproduce this issue.
https://github.com/felinto-dev/tscompiler-nestjs-issue

Please, let me know if you are able to replicate this issue.

cd project_directory
npm i
npm run test:e2e

@CatsMiaow
Copy link

CatsMiaow commented Feb 17, 2021

I confirmed it as a problem with the ts-jest version.

v26.4.4 no problem
v26.5.1(latest) error

This is a different story, but with nestjs-graphql-transformer is test speed slow every time I run the test. Perhaps it is because the cache is not applied.

@kamilmysliwiec
Copy link
Member

Can we report this issue in the ts-jest repository then? It seems that adding a check whether this._matchablePatterns property is not undefined in the ConfigSet#isTestFile would fix this issue (config-set.js file).

@CatsMiaow
Copy link

Created an issue. kulshekhar/ts-jest#2371
There seems to be a code change in ts-jest v26.5.x.

@kamilmysliwiec
Copy link
Member

Thanks! Let's track this here kulshekhar/ts-jest#2371

@CatsMiaow
Copy link

Fixed in ts-jest v26.5.2

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

No branches or pull requests

3 participants