0

In my project we have unit tests files which ends with .spec.ts and protractor test cases which ends with .prot.spec.ts. Now when I run command 'ng test' my protractor files get picked up because it also has the same extention (.spec.ts) but I dont want them to execute. I tried adding the properties like 'exclude' in tsconfig.json, tsconfig.app.json, test.js but it seems that its not working.

I need to know what is the exact place where I can put my configuration so that my protractor files will be excluded.

Please find the screenshots below :

tsConfig.spec.ts

test.js

tsconfig.ts

Error

pritampanhale
  • 106
  • 10
  • possible duplicate of https://stackoverflow.com/questions/42241654/angular-cli-exclude-files-directory-for-ng-test-code-coverage – Indragith Dec 27 '19 at 05:24
  • 1
    @Indragith : we cannot add the 'exclude' property in angular.json, It gives following error. Schema validation failed with the following errors: Data path "" should NOT have additional properties(exclude). – pritampanhale Dec 27 '19 at 05:27
  • You could change the names of your protractor tests to prot.test.ts and then have the protractor configuration file point to *.test.ts. Then ng-test should only pick up karma tests and ng-e2e should pick up protractor tests. – Sankalan Parajuli Dec 27 '19 at 05:28
  • @SankalanParajuli : Yup, Thats the last option. Thank you! – pritampanhale Dec 27 '19 at 05:29
  • @pritampanhale: If I am not wrong, with the latest angular cli version you should add the codeCoverageExclude: ['specify the path here'] instead of codeCoverage: { exclude : [] } – Indragith Dec 27 '19 at 06:02
  • I moved the protractor files to some other folder and it worked for me. – pritampanhale Jan 01 '20 at 11:12

1 Answers1

0

in your test.js, change the glob in the context

const context = require.context('./', true, /^((?!prot).)*\.spec.ts$/);
Akshay Nair
  • 121
  • 1
  • 4