You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But this package.json is still bugged. "test": "pnpm run test:lint && pnpm run test:coverage ", is referencing test:lint which is not defined.
If you run the test command:
thanatos@DESKTOP-5NP8L7E:~/projects/tsed-repos/jest-test$ pnpm run test:unit
> [email protected] test:unit /home/thanatos/projects/tsed-repos/jest-test
> cross-env NODE_ENV=test jest
ReferenceError: module is not defined
at file:///home/thanatos/projects/tsed-repos/jest-test/jest.config.js:4:1
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:395:35)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:329:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1411:24)
at Module._compile (node:internal/modules/cjs/loader:1544:5)
at Object..js (node:internal/modules/cjs/loader:1668:16)
at Module.load (node:internal/modules/cjs/loader:1313:32)
at Function._load (node:internal/modules/cjs/loader:1123:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
ELIFECYCLE Command failed with exit code 1.
ReferenceError: module is not defined is thrown because the config file is wrong.
You could (but shouldn't) change from module.exports = { to export default {:
thanatos@DESKTOP-5NP8L7E:~/projects/tsed-repos/jest-test$ pnpm run test:unit
> [email protected] test:unit /home/thanatos/projects/tsed-repos/jest-test
> cross-env NODE_ENV=test jest
FAIL src/controllers/rest/HelloWorldController.spec.ts
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/home/thanatos/projects/tsed-repos/jest-test/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]/node_modules/@tsed/platform-http/lib/esm/testing/index.js:4
export * from "./FakeAdapter.js";
^^^^^^
SyntaxError: Unexpected token 'export'
> 1 | import { PlatformTest } from "@tsed/platform-http/testing";
| ^
2 | import { HelloWorldController } from "./HelloWorldController.js";
3 |
4 | describe("HelloWorldController", () => {
at Runtime.createScriptFromCode (node_modules/.pnpm/[email protected]/node_modules/jest-runtime/build/index.js:1505:14)
at Object.<anonymous> (src/controllers/rest/HelloWorldController.spec.ts:1:1)
At the end it was much easier to switch from babel to swc and from jest to vitest because this just works.
To Reproduce
See description.
Expected behavior
Tests and package.json should be correct if the project was created with the tsed cli.
To me it looks very hard to maintain and support jest with the limited esmsupport, especially regarding the fact that tsed is now esm only.
So...maybe just drop jest support?
(Funny side note: The first example at https://tsed.dev/docs/testing.html is even importing vitest for the jest example)
Code snippets
Repository URL example
No response
OS
Ubuntu 22.04.5
Node version
22.13.0
Library version
8.4.2
Additional context
No response
The text was updated successfully, but these errors were encountered:
@ThanatosGit I released a fix for th CLI. Now Jest appear with (unstable) title ^^.
I also changed the testing.md page to present vitest example first.
Alright. I don't know if you want to do anything to fix the issues I mentioned above or keep it like it is and close this issue here.
But honestly I would just keep it as unstable =" use at your own risk" as long as jest has no proper esm support. Then this could be revisited
Describe the bug
Creates a
package.json
withoutjest
itself`.Though it does work if you add
Swagger
forDocumentation
(I haven't tested any other combinations).But this
package.json
is still bugged."test": "pnpm run test:lint && pnpm run test:coverage ",
is referencingtest:lint
which is not defined.If you run the test command:
ReferenceError: module is not defined
is thrown because the config file is wrong.You could (but shouldn't) change from
module.exports = {
toexport default {
:You can then do some experimental stuff mentioned in https://jestjs.io/docs/ecmascript-modules but it was a nightmare to get this to work for me.
Eventually, it didn't even work completly. Because I'm using Swagger it needs
import.meta.dirname
if you bootstrap the Server in a test.There is another rabbit hole about mocking it etc. shown here:
https://stackoverflow.com/questions/64961387/how-to-use-import-meta-when-testing-with-jest
At the end it was much easier to switch from
babel
toswc
and fromjest
tovitest
because this just works.To Reproduce
See description.
Expected behavior
Tests and
package.json
should be correct if the project was created with the tsed cli.To me it looks very hard to maintain and support
jest
with the limited esmsupport, especially regarding the fact that tsed is now esm only.So...maybe just drop
jest
support?(Funny side note: The first example at https://tsed.dev/docs/testing.html is even importing
vitest
for thejest
example)Code snippets
Repository URL example
No response
OS
Ubuntu 22.04.5
Node version
22.13.0
Library version
8.4.2
Additional context
No response
The text was updated successfully, but these errors were encountered: