Ava: Update TypeScript recipe given new extensions support

Created on 31 May 2018  Â·  9Comments  Â·  Source: avajs/ava

It'd be good to update the TypeScript recipe in light of AVA's new extensions support.

I'm suggesting the following in the release notes, but I must admit I haven't actually tested it, and it's not mentioned in the recipe yet:

{
    "ava": {
        "compileEnhancements": false,
        "extensions": ["ts"],
        "require": [
            "ts-node/register"
        ]
    }
}

Shout if you're up for trying the snippet and updating the recipe 😄

help wanted documentation typescript

All 9 comments

I had to add "babel": false, option to the above config, otherwise it gives the following error:

 ✖ Internal error
  Error: Cannot apply enhancement-only precompilation, possible bad usage

"ava": "1.0.0-beta.5.1",

@vladimiry could you share your full AVA config, and any Babel config you may have? If configured correctly these files should skip the regular Babel pipeline so you shouldn't have to disable it.

@novemberborn here it's https://github.com/vladimiry/protonmail-desktop-app/tree/06ac40ee0c537e536b9fa82623e7a8864c98fdef, tests can be executed running yarn && yarn test:electron:main. I don't use babel for this project, but it comes with ava, would be great ava uses it as an optional dependency if that's possible.

Besides what I noticed is that output is not informative enough. For example I explicitly cause a TS error, like using nonexistent / not imported type (TS2304):
ts error

and I then get the output that doesn't show me what error and on which line is happened, but just the non-zero exit code: 1 thing:

  TSError: ⨯ Unable to compile TypeScript:

  createTSError (node_modules/ts-node/src/index.ts:250:12)
  getOutput (node_modules/ts-node/src/index.ts:358:40)
  Object.compile (node_modules/ts-node/src/index.ts:545:11)
  Module.m._compile (node_modules/ts-node/src/index.ts:430:43)
  Object.require.extensions.(anonymous function) [as .ts] (node_modules/ts-node/src/index.ts:433:12)

  ✖ src/electron/main/ipc-main-api.spec.ts exited with a non-zero exit code: 1

@novemberborn Above mentioned ignoring of error.message printing is happening here https://github.com/avajs/ava/blob/1e0e8e84dbc8ed70286d01dd9c8d290f30533aad/lib/reporters/verbose.js#L231

error message lost

The TSError you are getting is probably due to type checking failing. We should make note in the docs that you can require ts-node/register/transpile-only instead, which will pass even if type checking is not perfect.

Relevent parts of my package.json:

  "ava": {
    "babel": false,
    "compileEnhancements": false,
    "extensions": [
      "ts"
    ],
    "require": [
      "./test/bootstrap.js",
      "ts-node/register/transpile-only"
    ]
  }

Works with ava 1.0.0-beta.5.1

We should make note in the docs that you can require ts-node/register/transpile-only instead, which will pass even if type checking is not perfect.

Getting TSError is totally fine, it's an expected behaviour and I want it to be like that, the issue is that error.message is currently not being displayed by ava, only the error.summary is.

@vladimiry could you open a separate issue regarding our handling of TSError. If possible I'd love it if we could recognize those and display better output, in lieu of built-in TypeScript support.

@vladimiry could you open a separate issue regarding our handling of TSError. If possible I'd love it if we could recognize those and display better output, in lieu of built-in TypeScript support.

Oh never mind, I see @btkostner already made a PR at #1834.

@vladimiry OK I figured out the problem. See https://github.com/avajs/ava/issues/1836.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sindresorhus picture sindresorhus  Â·  5Comments

dlumma picture dlumma  Â·  4Comments

ehmicky picture ehmicky  Â·  4Comments

clitetailor picture clitetailor  Â·  3Comments

nickjanssen picture nickjanssen  Â·  4Comments