Agung
Agung

Reputation: 13803

No test files found: "test" when testing security rules using Mocha using Typescript

I have tried to find similar problem in stackoverflow but no one can solve my issue.

I am trying to test my firebase security rules, using Typescript and Mocha, but I can't even run my test

here is my project directory

enter image description here

I install my dev dependecies using this code:

npm install chai mocha ts-node @types/chai @types/mocha --save-dev

here is my dev dependecies

 "devDependencies": {
    "@firebase/rules-unit-testing": "^1.2.5",
    "@types/chai": "^4.2.15",
    "@types/mocha": "^8.2.2",
    "@types/uuid": "^8.3.0",
    "@typescript-eslint/eslint-plugin": "^3.9.1",
    "@typescript-eslint/parser": "^3.8.0",
    "chai": "^4.3.4",
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.22.0",
    "mocha": "^8.3.2",
    "ts-node": "^9.1.1",
    "typescript": "^3.9.9"
  },

and here is my script npm

"scripts": {
    "test": "mocha --exit"
  },

but when run npm run test , from functions directory I have error

Error: No test files found: "test"

I have tried using

mocha --require ts-node/register --watch-extensions ts 'test/**/*.ts'

I still have the same error. what should I do?

Upvotes: 2

Views: 2538

Answers (1)

Agung
Agung

Reputation: 13803

I finally can run the test using

mocha -r ts-node/register src/**/*.test.ts --timeout 60000 --exit

don't forget to install ts-node as dev dependecy and please note that the file name should be in format

myFileName.test.ts

Upvotes: 5

Related Questions