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

Ts node support #245

Closed
wants to merge 2 commits into from
Closed

Ts node support #245

wants to merge 2 commits into from

Conversation

chgeo
Copy link
Member

@chgeo chgeo commented Jun 14, 2021

No description provided.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


d060338 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Kkoile
Copy link

Kkoile commented Jun 14, 2021

Unfortunately I was still not able to get the existing tests running with the current master version of cds. Neither with jest 26 or 27.

@chgeo
Copy link
Member Author

chgeo commented Jun 14, 2021

Unfortunately I was still not able to get the existing tests running with the current master version of cds. Neither with jest 26 or 27.

Yes, that's what I observe as well. Needs more investigation...

@chgeo
Copy link
Member Author

chgeo commented Jun 14, 2021

@Kkoile can you allow edits from maintainers for this PR?

@tsteckenborn
Copy link
Contributor

Unfortunately I was still not able to get the existing tests running with the current master version of cds. Neither with jest 26 or 27.

Yes, that's what I observe as well. Needs more investigation...

I have not tested it in this repository, but in general, it seems to work with Jest using jasmine2 as test runner. With Jest 27, the default test runner was changed to jest-circus (see here). The problem is probably related to this. There were some changes that can lead to errors, see for example here.

@chgeo
Copy link
Member Author

chgeo commented Jun 15, 2021

Had a closer look and some findings.

Turns out there is an error on server startup that sap/cds swallows:

$  TYPESCRIPT_SUPPORT=true npx jest@^26 -- --preset ts-jest --testMatch test/*.test.ts
 FAIL  test/hello-world-ts.test.ts
  Hello world!
    ✕ should say hello with class impl from a typescript file (147 ms)

  ● Hello world! › should say hello with class impl from a typescript file

    SyntaxError: /Users/.../cap/samples/hello/world.ts: Unexpected token, expected "," (2:13)

      1 | module.exports = class say {
    > 2 |     hello(req: any) {
        |              ^
      3 |         return `Hello ${req.data.to} from a typescript file!`
      4 |     }
      5 | }

      at Parser._raise (../../node_modules/@babel/parser/src/parser/error.js:134:45)
      at Parser.raiseWithData (../../node_modules/@babel/parser/src/parser/error.js:129:17)
      at Parser.raise (../../node_modules/@babel/parser/src/parser/error.js:78:17)
      at Parser.unexpected (../../node_modules/@babel/parser/src/parser/util.js:179:16)
      at Parser.expect (../../node_modules/@babel/parser/src/parser/util.js:144:28)
      at Parser.parseBindingList (../../node_modules/@babel/parser/src/parser/lval.js:315:14)
      at Parser.parseFunctionParams (../../node_modules/@babel/parser/src/parser/statement.js:1207:24)
      at Parser.parseMethod (../../node_modules/@babel/parser/src/parser/expression.js:2063:10)
      at Parser.pushClassMethod (../../node_modules/@babel/parser/src/parser/statement.js:1655:12)
      at Parser.parseClassMemberWithIsStatic (../../node_modules/@babel/parser/src/parser/statement.js:1479:12)

→ This actually looks like ts-jest is not active
→ Will fix the error reporting separately

This changes if one configures the preset in package.json:

  "jest": {
    "testEnvironment": "node",
    "preset": "ts-jest"
  }

results in

 FAIL  test/hello-world-ts.test.ts
  ● Test suite failed to run

    TypeError: Jest: a transform must export a `process` function.

      at ScriptTransformer._getTransformer (../../node_modules/@jest/transform/build/ScriptTransformer.js:360:13)
      at ScriptTransformer.transformSource (../../node_modules/@jest/transform/build/ScriptTransformer.js:427:28)
      at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:569:40)
      at ScriptTransformer.transform (../../node_modules/@jest/transform/build/ScriptTransformer.js:607:25)

Now something is wrong w/ the ts-jest or its config.
@Kkoile maybe you can take it from here

@chgeo
Copy link
Member Author

chgeo commented Jul 12, 2021

I have pulled this over to PR #248 in the original repo.
See there for more.

@chgeo chgeo closed this Jul 12, 2021
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

Successfully merging this pull request may close these issues.

None yet

4 participants