Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Look into code coverage #19

Open
Arcanemagus opened this issue Sep 1, 2017 · 18 comments
Open

Look into code coverage #19

Arcanemagus opened this issue Sep 1, 2017 · 18 comments

Comments

@Arcanemagus
Copy link
Member

Arcanemagus commented Sep 1, 2017

Code Coverage

The Jasmine 1.3 based test framework built into Atom that most packages use is not only quite out of date, but doesn't support generating code coverage support of a package.

An alternative test framework that supports generating code coverage reports should be looked into.

Atom supports running custom test runners with the atomTestRunner key in package.json. This was introduced in atom/atom#8968, although it looks like the functionality may have changed from what is documented there.

Potential frameworks

Mocha

Jest

@keplersj
Copy link

This might help. https://github.com/keplersj/atom-test-runner-jest

@Arcanemagus
Copy link
Member Author

@keplersj Cleaned up the list, looks like yours isn't (yet?) published on NPM though. Somebody else also built a Jest runner, but their build is failing so I have no idea how usable it is lol.

@keplersj
Copy link

It's live. I've used it for language-crystal to simply the tokenization tests with snapshots. https://github.com/crystal-lang-tools/language-crystal

@keplersj
Copy link

https://www.npmjs.com/package/atom-test-runner-jest

skylize added a commit to AtomLinter/linter-eslint that referenced this issue Jan 16, 2018
As per AtomLinter/Meta#19, it would be ideal to have a test runner with code coverage capabilities. This is a first try at getting Mocha or Jest running inside the Atom environment.

This commit has a working installation of mocha, with test showing the atom globals are found showed as passing in the Atom Spec Runner Window.

Jest is not working at this time. Jest will run inside Atom and try to test the file, but fails to inject the Jest global variables, such as `test` and `expect`.
skylize added a commit to AtomLinter/linter-eslint that referenced this issue Jan 16, 2018
As per AtomLinter/Meta#19, it would be ideal to have a test runner with code coverage capabilities. This is a first try at getting Mocha or Jest running inside the Atom environment.

This commit has a working installation of mocha, with test showing the atom globals are found showed as passing in the Atom Spec Runner Window.

Jest is not working at this time. Jest will run inside Atom and try to test the file, but fails to inject the Jest global variables, such as `test` and `expect`.
@UziTech
Copy link
Member

UziTech commented Feb 17, 2018

atom-jasmine3-test-runner lets you write new tests in Jasmine 3.x while keeping old tests in Jasmine 1.3 while transitioning.

@keplersj
Copy link

If anyone's looking for an example of code coverage in an Atom package, look no further than linter-swiftlint.

@UziTech
Copy link
Member

UziTech commented May 2, 2018

How do you run the tests on linter-swiftlint?

When I try to run window:run-package-specs the window locks up, and when I run atom --test spec I get "No tests found"

@Arcanemagus
Copy link
Member Author

Arcanemagus commented May 2, 2018

Hmmmm, atom --test spec is what the test script and the ci builds run, so that should be working. I don't have a mac to test on so I'll leave it to @keplersj to answer further 🤷‍♂️.

@keplersj
Copy link

keplersj commented May 2, 2018

window:run-package-specs won't work because atom-test-runner-jest does not currently implement that portion of the Atom test runner functionality. A PR if you're interested would be very much appreciated. Running apm test, atom --test ., or atom --test spec should all work as long as you have -spec.js files in the spec. atom-test-runner-jest is simply configuring the atom global and passing the rest off to the Jest CLI. If your not seeing tests picked up and run from there it's most likely due to Jest configuration.

@UziTech
Copy link
Member

UziTech commented May 3, 2018

atom --test spec should all work as long as you have -spec.js files in the spec

do the .ts files need to be transpiled first?

@keplersj
Copy link

keplersj commented May 3, 2018

Not when using jest-prest-atom and atom-typescript-transpiler, like linter-swiftlint. jest-preset-atom is configured to make use of Atom's builtin compile-cache functionality.

@UziTech
Copy link
Member

UziTech commented May 3, 2018

What am I doing wrong?

  1. I cloned the repo
  2. ran npm install
  3. ran apm install
  4. ran npm test
C:\Users\tjbrix\Documents\projects\GitHub\linter-swiftlint>npm test

> linter-swiftlint@1.3.1 test C:\Users\tjbrix\Documents\projects\GitHub\linter-swiftlint
> atom --test spec


No tests found
In C:\Users\tjbrix\Documents\projects\GitHub\linter-swiftlint
  9 files checked.
  testMatch: **/__tests__/**/*.(js|jsx|json|node|ts|tsx|coffee|litcoffee|coffee.md),**/?(*.)(spec|test).(js|jsx|json|node|ts|tsx|coffee|litcoffee|coffee.md),**/spec/**/*-spec.(js|jsx|json|node|ts|tsx|coffee|litcoffee|coffee.md) - 1 match
  testPathIgnorePatterns: \\node_modules\\ - 9 matches
Pattern: C:\Users\tjbrix\Documents\projects\GitHub\linter-swiftlint\spec - 0 matches

@keplersj
Copy link

keplersj commented May 3, 2018

Guess I'll have to break out the Windows and do some debugging. My first guess is that I'm doing something in jest-preset-atom that is incompatible on Windows.

@UziTech
Copy link
Member

UziTech commented May 3, 2018

Seems to be something with Windows. I setup an Ubuntu VM and did the same steps and everything worked.

@keplersj
Copy link

keplersj commented May 3, 2018

@UziTech I've just replicated your issue. Investigating further.

@keplersj
Copy link

keplersj commented May 3, 2018

@UziTech I think I've found a potential solution. Going to verify it doesn't break macOS and Linux.

@keplersj
Copy link

keplersj commented May 3, 2018

@UziTech Fixed in atom-test-runnner-jest@0.2.3

@UziTech
Copy link
Member

UziTech commented May 3, 2018

it works 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants