4

I am using NestJs for my new project.

I am adding all the files with this command. git add .

when I commit after adding all the files husky prevents committing and shows me this error.

[path to the file]/.spec.ts' is not included in the project.

husky > pre-commit hook failed (add --no-verify to bypass)

I implicitly added the file but It still throwing me that error.

my tsconfig.json file

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "allowJs": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "lib": ["dom", "es2018", "esnext"]
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

and this is how I added husky commands in the package.json file

 "scripts": {
    "lint": "tslint -p tsconfig.json -c tslint.json",
  },


"husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "post-commit": "git push origin HEAD"
    }
  },
  "lint-staged": {
    "*.ts": [
      "tslint -p tsconfig.json -c tslint.json",
      "git add"
    ]
  },
Dulara Malindu
  • 1,477
  • 4
  • 18
  • 37
  • Are you running the `lint-staged` commands in the `pre-commit` hook and expecting them to change what's going to be committed? – bk2204 Jan 08 '19 at 01:33
  • I used this solution for resolve my issue https://stackoverflow.com/a/63948896/1862590 – Sathiamoorthy Apr 16 '21 at 12:09

2 Answers2

3

If you are on windows OS, the hooks script which will include in your package.json should be of this form below

"husky": {
    "hooks": {
      "pre-push": "set CI=true&&npm test"
    }
  },

For other Operating System make use of below snippet

 "husky": {
 "hooks": {
 "pre-push": "CI=true npm test"}},

More information on: https://facebook.github.io/create-react-app/docs/running-tests#on-your-own-environment

Alabi Temitope
  • 405
  • 5
  • 16
0

Can it be that your pre commit hook is failing because you have "**/*.spec.ts" as value in exclude property in your tsconfig.json file?

Could you edit file like this and test it:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "allowJs": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "lib": ["dom", "es2018", "esnext"]
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}
Ivan Vasiljevic
  • 5,478
  • 2
  • 30
  • 35