Skip to content

nyc-config-typescript and decorators #1437

@cexbrayat

Description

@cexbrayat

Considering a simple TS file like src/main.ts

function Foo(constructorFunction: Function) {
  console.log('Foo decorator')
}

@Foo
class Main {
  constructor() {
    console.log('Running')
  }
}

new Main();

then trying to instrument it by running:

yarn nyc instrument --compact=false src instrumented

with the following configuration:

"nyc": {
  "extends": "@istanbuljs/nyc-config-typescript",
  "all": true
}

then the result file instrumented/main.ts is not instrumented.

If we comment the @Foo decorator, then the file is instrumented again.

function Foo(constructorFunction: Function) {
  console.log('Foo decorator')
}

// @Foo
class Main {
  constructor() {
    console.log('Running')
  }
}

new Main();

result instrumented/main.ts:

// ...
function Foo(constructorFunction: Function) {
  cov_1eomntdplb.f[0]++;
  cov_1eomntdplb.s[0]++;
  console.log('Foo decorator');
} // @Foo

class Main {
  constructor() {
    cov_1eomntdplb.f[1]++;
    cov_1eomntdplb.s[1]++;
    console.log('Running');
  }
}

cov_1eomntdplb.s[2]++;
new Main();

Am I missing something or is there an issue with decorators?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions