-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Typescript support #1
Comments
I bet you can use ts-node's ESM loader to do this today. Turn on swc mode for speed. |
I made a demo combining ts-node with this test runner: I see that esmock is mentioned in the readme. If you want to combine ts-node with esmock or any other loader, try this: |
@cspotcode awesome, it works! I'll close the issue then! 👍 |
Any chance this can be added to the README? |
Thank you @cspotcode! I'll create an "examples" folder that shows both this and how to mock ES modules using a loader. |
from this PR and discussion iambumblehead/esmock#155 we found that, using the latest node v18.9.0... jest + jest-light-runner + ts-node/esm
|
Looks like you do not want typechecking, and you got a typechecking error here. So I would turn off typechecking. |
@cspotcode thank you, with this tsconfig.json, the ts-node test is passing. I will update the comment above shortly, {
"extends": "ts-node/node16/tsconfig.json",
"ts-node": {
"transpileOnly": true,
"files": true
},
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "ESNext",
"moduleResolution": "node"
}
} |
Sounds good, you can also remove the |
the person who opened the issue at esmock, @cyberwombat, also wants to use a jest.config.ts file that looks like this,export default {
testEnvironment: 'jest-environment-node',
setupFiles: ['./test/setup.ts'],
setupFilesAfterEnv: ['./test/bootstrap.ts'],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
diagnostics: false,
compilerHost: true,
incremental: true
}
]
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
'^lib/(.*)$': 'src/lib/$1'
},
extensionsToTreatAsEsm: ['.ts'],
testPathIgnorePatterns: ['<rootDir>/dist', '.history'],
modulePaths: ['<rootDir>/src', '<rootDir>/test', '<rootDir>'],
preset: 'ts-jest'
} Is it possible to support this, while using jest-light-runner with --loader=ts-node/esm? |
ts-node fails in windows CI pipeline, seemingly because of the slash "/" in "ts-node/esm" {
"scripts": {
"test:win32": "set NODE_OPTIONS=\"--loader=ts-node/esm --loader=esmock\" && jest esmock.node-jest.test.ts"
}
} https://github.com/iambumblehead/esmock/actions/runs/3091643663/jobs/5001967546 Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './esm --loader=esmock' is not defined by "exports" in D:\a\esmock\esmock\tests\tests-jest-ts\node_modules\ts-node\package.json imported from D:\a\esmock\esmock\tests\tests-jest-ts\
at new NodeError (node:internal/errors:393:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:340:9) |
Mistake in your quoting
It thinks the subpath is this full string:
Cuz of a mistake in quoting |
it seems the solution is so obvious, no explanation is needed :) but I do not know the solution. I think I understand the problem you are pointing out, but I don't know how to solve it |
https://stackoverflow.com/questions/535975/dealing-with-quotes-in-windows-batch-scripts Does this work? |
the suggestion will be used in the test pipeline here https://github.com/iambumblehead/esmock/actions/runs/3091925933/jobs/5002604159 @liuxingbaoyu it worked! I was not able to solve that --thank you for that suggestion |
Feature request: would be awesome if it supported typescript compilation (no type-checking needed).
Maybe something simple like
esbuild
transformer can be added for*.ts
files, that'll cover 99% of the common needs.Awesome runner, by the way!
The text was updated successfully, but these errors were encountered: