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

Import mixin from yarn workspace package - TypeError: Class constructor cannot be invoked without 'new' #1109

Closed
nullxone opened this issue May 26, 2019 · 2 comments

Comments

@nullxone
Copy link

Issue :

Importing and using a mixin from a package in the same yarn workspace shows error
TypeError: Class constructor cannot be invoked without 'new'

Expected behavior :

should not error.
should behave identically to running tools separately. i.e.
configuring jest to point to the build folder output of tsc (instead of src) and running the following produces no errors:
tsc -b .
jest

One strange thing is that the types generated related to mixins applied base class imported from a different package and mixin defined in the same package are slightly different. (File: server/build/Product.d.ts). Everything else seems to be the exact same.

declare const Product_base: {
    new (...args: any[]): {
        timestamp: number;
    };
} & typeof Foo;
declare const Product2_base: (new (...args: any[]) => {
    timestamp: number;
}) & typeof Foo;

Debug log:

log file content
# content of ts-jest.log :
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"24.0.2"},"message":"creating jest presets not handling JavaScript files","sequence":1,"time":"2019-05-26T04:27:28.138Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"24.0.2"},"message":"creating Importer singleton","sequence":2,"time":"2019-05-26T04:27:28.866Z"}
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"24.0.2"},"message":"creating jest presets not handling JavaScript files","sequence":3,"time":"2019-05-26T04:27:28.870Z"}
{"context":{"actualVersion":"24.8.0","expectedVersion":">=24 <25","logLevel":20,"namespace":"versions","package":"ts-jest","version":"24.0.2"},"message":"checking version of jest: OK","sequence":4,"time":"2019-05-26T04:27:28.872Z"}
{"context":{"baseOptions":{},"logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"24.0.2"},"message":"created new transformer","sequence":5,"time":"2019-05-26T04:27:28.872Z"}
{"context":{"fileName":"/js/server/src/spec.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"config":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/tmp/jest_0","clearMocks":true,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/js","dependencyExtractor":null,"detectLeaks":false,"detectOpenHandles":false,"displayName":"SERVER","errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globalSetup":null,"globalTeardown":null,"globals":{"ts-jest":{"tsConfig":"tsconfig.json"}},"haste":{"computeSha1":false,"providesModuleNodeModules":[],"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":{},"modulePathIgnorePatterns":[],"name":"524dcda91d222f1438dacdc6254406cd","prettierPath":"prettier","resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/js/server","roots":["/js/server/src"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"/js/node_modules/jest-environment-node/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__spec__/**/*.ts","**/?(*.)spec.ts"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/js/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/js/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"instrument":false,"rootDir":"/js/server"},"transformerId":1,"version":"24.0.2"},"message":"computing cache key for /js/server/src/spec.ts","sequence":6,"time":"2019-05-26T04:27:28.873Z"}
{"context":{"logLevel":30,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"24.0.2"},"message":"no matching config-set found, creating a new one","sequence":7,"time":"2019-05-26T04:27:28.873Z"}
{"context":{"config":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/tmp/jest_0","clearMocks":true,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/js","dependencyExtractor":null,"detectLeaks":false,"detectOpenHandles":false,"displayName":"SERVER","errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globalSetup":null,"globalTeardown":null,"globals":{"ts-jest":{"tsConfig":"tsconfig.json"}},"haste":{"computeSha1":false,"providesModuleNodeModules":[],"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":{},"modulePathIgnorePatterns":[],"name":"524dcda91d222f1438dacdc6254406cd","prettierPath":"prettier","resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/js/server","roots":["/js/server/src"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"/js/node_modules/jest-environment-node/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__spec__/**/*.ts","**/?(*.)spec.ts"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/js/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/js/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"backports","package":"ts-jest","transformerId":1,"version":"24.0.2"},"message":"backporting config","sequence":8,"time":"2019-05-26T04:27:28.874Z"}
{"context":{"jestConfig":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/tmp/jest_0","clearMocks":true,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/js","dependencyExtractor":null,"detectLeaks":false,"detectOpenHandles":false,"displayName":"SERVER","errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globalSetup":null,"globalTeardown":null,"globals":{"ts-jest":{"tsConfig":"tsconfig.json"}},"haste":{"computeSha1":false,"providesModuleNodeModules":[],"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":{},"modulePathIgnorePatterns":[],"name":"524dcda91d222f1438dacdc6254406cd","prettierPath":"prettier","resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/js/server","roots":["/js/server/src"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"/js/node_modules/jest-environment-node/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__spec__/**/*.ts","**/?(*.)spec.ts"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/js/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/js/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"24.0.2"},"message":"normalized jest config","sequence":9,"time":"2019-05-26T04:27:28.874Z"}
{"context":{"fromPath":"tsconfig.json","logLevel":20,"namespace":"config","package":"ts-jest","toPath":"/js/tsconfig.json","transformerId":1,"version":"24.0.2"},"message":"resolved path from tsconfig.json to /js/tsconfig.json","sequence":10,"time":"2019-05-26T04:27:28.875Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsJestConfig":{"compiler":"typescript","diagnostics":{"ignoreCodes":[6059,18002,18003],"pretty":true,"throws":true},"isolatedModules":false,"packageJson":{"kind":"file"},"transformers":[],"tsConfig":{"kind":"file","value":"/js/tsconfig.json"}},"version":"24.0.2"},"message":"normalized ts-jest config","sequence":11,"time":"2019-05-26T04:27:28.875Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"24.0.2"},"message":"babel is disabled","sequence":12,"time":"2019-05-26T04:27:28.877Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","requireResult":{"exists":true,"given":"typescript","path":"/js/node_modules/typescript/lib/typescript.js"},"version":"24.0.2"},"message":"loaded module typescript","sequence":13,"time":"2019-05-26T04:27:29.135Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"24.0.2"},"message":"patching typescript","sequence":14,"time":"2019-05-26T04:27:29.135Z"}
{"context":{"actualVersion":"3.5.0-rc","expectedVersion":">=2.7 <4","logLevel":20,"namespace":"versions","package":"ts-jest","version":"24.0.2"},"message":"checking version of typescript: NOT OK","sequence":15,"time":"2019-05-26T04:27:29.136Z"}
{"context":{"logLevel":40,"namespace":"versions","package":"ts-jest","version":"24.0.2"},"message":"Version 3.5.0-rc of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions.","sequence":16,"time":"2019-05-26T04:27:29.136Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsConfigFileName":"/js/tsconfig.json","version":"24.0.2"},"message":"readTsConfig(): reading /js/tsconfig.json","sequence":17,"time":"2019-05-26T04:27:29.136Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsconfig":{"input":{"compilerOptions":{},"files":[],"references":[{"path":"./common"},{"path":"./server"}]},"resolved":{"compileOnSave":false,"configFileSpecs":{"filesSpecs":[],"wildcardDirectories":{}},"errors":[],"fileNames":[],"options":{"configFilePath":"/js/tsconfig.json","declaration":false,"inlineSourceMap":false,"inlineSources":true,"module":1,"noEmit":false,"outDir":"$$ts-jest$$","removeComments":false,"sourceMap":true,"target":1},"projectReferences":[{"originalPath":"./common","path":"/js/common"},{"originalPath":"./server","path":"/js/server"}],"raw":{"compileOnSave":false,"compilerOptions":{},"files":[],"references":[{"path":"./common"},{"path":"./server"}]},"typeAcquisition":{"enable":false,"exclude":[],"include":[]},"wildcardDirectories":{}}},"version":"24.0.2"},"message":"normalized typescript config","sequence":18,"time":"2019-05-26T04:27:29.145Z"}
{"context":{"fileName":"/js/server/src/Product.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"config":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/tmp/jest_0","clearMocks":true,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/js","dependencyExtractor":null,"detectLeaks":false,"detectOpenHandles":false,"displayName":"SERVER","errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globalSetup":null,"globalTeardown":null,"globals":{"ts-jest":{"tsConfig":"tsconfig.json"}},"haste":{"computeSha1":false,"providesModuleNodeModules":[],"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":{},"modulePathIgnorePatterns":[],"name":"524dcda91d222f1438dacdc6254406cd","prettierPath":"prettier","resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/js/server","roots":["/js/server/src"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"/js/node_modules/jest-environment-node/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__spec__/**/*.ts","**/?(*.)spec.ts"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/js/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/js/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"instrument":false,"rootDir":"/js/server"},"transformerId":1,"version":"24.0.2"},"message":"computing cache key for /js/server/src/Product.ts","sequence":19,"time":"2019-05-26T04:27:29.148Z"}

Minimal repo :

https://github.com/nullxone/tmp-ts-jest-import-mixin-constructor-error

It includes a comparison to defining the mixin in the same package, which does not error.

Related?

#571__

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 12, 2020

Close as related to monorepo support in #1336

@ahnpnl ahnpnl closed this as completed Jan 12, 2020
AArnott added a commit to AArnott/cloudbuild-task that referenced this issue Feb 3, 2020
AArnott added a commit to AArnott/cloudbuild-task that referenced this issue Feb 3, 2020
AArnott added a commit to AArnott/cloudbuild-task that referenced this issue Feb 3, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented Feb 13, 2020

hi @nullxone , what is the meaning of export default 1 in your Product.ts ? The test runs successfully if I change it to export default c

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

2 participants