Skip to content

MockTestRunner & TaskMockRunner + Typescript and Mocha #1091

Open
@marcopelegrini

Description

@marcopelegrini

Hi,

I've been banging my head trying to move my project to esm using Mocha + ts-node and run tests before transpiling

@DmitriiBobreshev maybe you can help me as you did a lot of work in this area here 7c0de0d

Basically, if I follow the docs: https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?view=azure-devops and setup mocha + nyc I get everything working, but basically no coverage for the ts files

My assumption is that this is happening because the task is running from the dist folder rather than from the source (as setup in nyc)

Everything else in my project works fine (I can basically ignore dist during tests) and running everything from ts.

On the other hand, if I try to run MockTestRunner & TaskMockRunner with the ts files I get this:

For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
/Users/marco/Dev/typescript-node-template/test/setup/task-mock-runner.ts:1
import tmrm = require("azure-pipelines-task-lib/mock-run");
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1126:15)
    at Module._compile (node:internal/modules/cjs/loader:1162:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47
Image

I wonder if there's anything I'm missing or this is really not supported and won't be?

Any inputs are appreciated.

Example project attached. Check commented lines for more info

Thank you

MockTestRunner-issue-with-ts.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions