Closed plastikfan closed 4 years ago
Tried new "nyc" package.json entry as documented at: https://azimi.me/2016/09/30/nyc-mocha-typescript.1.html which resulted in an error about imports requiring esModuleInterop. I don't know which config this comes from.
legacy mocha.opts file "--require ts-node/register --require source-map-support/register --full-trace tests/*/.spec.ts"
replaced by "mocha" entry in package.json:
"mocha": { "include": "tests/*/.spec.ts", "full-trace": true, "require": ["ts-node/register", "source-map-support/register"] },
mocha config moved into separate .mocharc file: { "spec": "tests/*/.spec.ts", "full-trace": true, "require": ["ts-node/register", "source-map-support/register"] }
Found this which may be useful: https://github.com/nobrainr/typescript-webpack-starter
Try using this https://nobrainr.github.io/typescript-webpack-starter/ to generate the skeleton
Fixed coverage issue, just to find that all the unit tests are running twice. Looking at this article: https://formidable.com/blog/2018/finding-webpack-duplicates-with-inspectpack-plugin/
As a clarification, all you need to get coverage to work is a valid "nyc" definition in package.json and .mocharc. Unfortunately, the tests are running twice!.
The problem of the tests running twice has been fixed and in doing so has also fixed my understanding of coverage. The "cov" command is self sufficient; it doesnt require previous build to be performed as this is part of the coverage command. When you run "cov", the mocha/nyc settings are consulted in package.json and .mocharc. These refer to the .ts source. The problem of running the tests twice was because the .js bundle was being passed into "nyc mocha
Coveralls not working: Couldn't find a repository matching this job. But according to: https://github.com/lemurheavy/coveralls-public/issues/1376, you need to make sure that your env has GITHUB_TOKEN = ${{ secrets.GITHUB_TOKEN }}. So next thing to learn is setting env variables
Need to defined encrypted envronment variable for the token as described at https://docs.travis-ci.com/user/environment-variables/ and https://stackoverflow.com/questions/41528849/nyc-coveralls-integration-not-working
The documentation about encrypting environment variables at https://docs.travis-ci.com/user/environment-variables/#defining-encrypted-variables-in-travisyml is really shite.
The bit that says this: travis encrypt MY_SECRET_ENV=super_secret --add env.global
means that when you run this, it will add the encryped entry into your travis file automatically.
NB: The token is now encryped, but you need to regularly regenerate your token and re-encrypt using this method. You regenerate the token on coveralls and copy that token into the command locally, So for example, lets say your generated token is 1234. You would run the command:
travis encrypt COVERALLS_REPO_TOKEN=1234 --add env.global
Code coverage with coveralls (https://github.com/nickmerwin/node-coveralls) https://github.com/alanshaw/nodeunit-lcov-coveralls-example
https://github.com/zinserjan/mocha-webpack/blob/master/docs/guides/code-coverage.md
Might need to use remap-istanbul (https://www.sitepen.com/blog/code-coverage-for-typescript-and-other-transpiled-languages/)
This link may be better as it focuses on webpack and typescript: https://tomasalabes.me/blog/typescript/tests/code-coverage/webpack/2018/09/24/ts-code-coverage.html
Istanbul typescript/mocha integration: https://istanbul.js.org/docs/tutorials/typescript/
And: https://zinserjan.github.io/mocha-webpack/docs/guides/code-coverage.html