nordcloud / serverless-mocha-plugin

Plugin for Serverless Framework which adds support for test-driven development using Mocha
MIT License
159 stars 50 forks source link

Not working with typescript and serverless v2 #157

Closed rgarcianat closed 2 years ago

rgarcianat commented 2 years ago

The package works fine on serverless V1 and typescript, but when migrating to serverless V2, Typescript files are being executed directly instead of the transpiled file.

 Syntax Error --------------------------------------------

 /serverless/electric-profile/test/answer.ts:2
  import * as chai from 'chai'
  ^^^^^^

  SyntaxError: Cannot use import statement outside a module
      at compileFunction (<anonymous>)
      at wrapSafe (internal/modules/cjs/loader.js:1001:16)
      at Module._compile (internal/modules/cjs/loader.js:1049:27)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
      at Module.load (internal/modules/cjs/loader.js:950:32)
      at Function.Module._load (internal/modules/cjs/loader.js:790:12)
      at Module.require (internal/modules/cjs/loader.js:974:19)
      at require (internal/modules/cjs/helpers.js:93:18)
      at /home/rennerp/workspace/bovitz/serverless/electric-profile/node_modules/mocha/lib/mocha.js:334:36
      at Array.forEach (<anonymous>)
      at Mocha.loadFiles (/home/rennerp/workspace/bovitz/serverless/electric-profile/node_modules/mocha/lib/mocha.js:331:14)
      at Mocha.run (/home/rennerp/workspace/bovitz/serverless/electric-profile/node_modules/mocha/lib/mocha.js:809:10)
      at /home/rennerp/workspace/bovitz/serverless/electric-profile/node_modules/serverless-mocha-plugin/index.js:324:17

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.