taimos / ask-sdk-test

Alexa Skill Test Framework for Typescript and ASK2
MIT License
21 stars 12 forks source link

Error running tests: mocha_1.it is not a function #24

Closed habuma closed 1 year ago

habuma commented 3 years ago

Description

Whenever I run a spec, I get an error saying that mocha_1.it is not a function. I can run mocha against a simpler spec that doesn't use ask-sdk-test with no problems. But as soon as I start using ask-sdk-test in a spec, it fails.

This could very well be something I'm doing wrong, but I've tried a variety of things with no luck and just need a little help to move forward.

Steps to Reproduce

  1. Created a new skill using the ASK CLI and the "Hello world" skill for AWS Lambda deployment.
  2. npm i ask-sdk-test
  3. Created a directory named "tests"
  4. Created skill.spec.ts in the tests directory that is much like the one shown on the ask-sdk-test README, slightly altered to point at my skill's index.js file relative to the test directory and with message altered to match the message from the "Hello world" template's launch request handler.
  5. Run mocha -r ts-node/register tests/skill.spec.ts.

Expected behavior: [What you expected to happen]

The test should either pass or fail, but not fail to run with an error and stack trace.

Actual behavior: [What actually happened]

Received the following error and stack trace:

$ mocha -r ts-node/register tests/skill.spec.ts

TypeError: mocha_1.it is not a function
    at AlexaTest.test (/Users/habuma/Projects/AlexaSkills/test-it/lambda/node_modules/ask-sdk-test/lib/tester/AlexaTest.ts:108:9)
    at Suite.<anonymous> (/Users/habuma/Projects/AlexaSkills/test-it/lambda/tests/skill.spec.ts:14:15)
    at Object.create (/opt/homebrew/lib/node_modules/mocha/lib/interfaces/common.js:148:19)
    at context.describe.context.context (/opt/homebrew/lib/node_modules/mocha/lib/interfaces/bdd.js:42:27)
    at Object.<anonymous> (/Users/habuma/Projects/AlexaSkills/test-it/lambda/tests/skill.spec.ts:13:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module.m._compile (/opt/homebrew/lib/node_modules/ts-node/src/index.ts:1056:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object.require.extensions.<computed> [as .ts] (/opt/homebrew/lib/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.exports.requireOrImport (/opt/homebrew/lib/node_modules/mocha/lib/esm-utils.js:20:12)
    at Object.exports.loadFilesAsync (/opt/homebrew/lib/node_modules/mocha/lib/esm-utils.js:33:34)
    at Mocha.loadFilesAsync (/opt/homebrew/lib/node_modules/mocha/lib/mocha.js:431:19)
    at singleRun (/opt/homebrew/lib/node_modules/mocha/lib/cli/run-helpers.js:125:15)
    at exports.runMocha (/opt/homebrew/lib/node_modules/mocha/lib/cli/run-helpers.js:190:10)
    at Object.exports.handler (/opt/homebrew/lib/node_modules/mocha/lib/cli/run.js:362:11)
    at /opt/homebrew/lib/node_modules/mocha/node_modules/yargs/lib/command.js:241:49

Environment

NodeJS-Version: [put your NodeJS version here]

v14.15.4

TypeScript-Version: [put your TypeScript version here]

4.1.3

OS: [put your operating system here]

MacOS 11.1 (Big Sur) on M1 machine.

habuma commented 3 years ago

FWIW, I did see the comment on #7, but that didn't help me. I did try deleting all js.map files, but that didn't help. Moreover, I don't want to delete *.js because that would delete my skill fulfillment code.

abhjroy commented 1 year ago

Hi @habuma have you resolved this issue. if yes then can you please describe how did you resolve it.

habuma commented 1 year ago

It has been resolved, although I honestly don't know what I did to resolve it. Will close this issue and reopen it if I encounter the problem again.