Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase Code Coverage & use nyc #377

Merged
merged 3 commits into from
Aug 10, 2018
Merged

Conversation

erisu
Copy link
Member

@erisu erisu commented Jun 23, 2018

Platforms affected

iOS

What does this PR do?

I wanted to help increase the code coverage for iOS so I wrote some additional tests around the missing area.

I also:

  • Upgraded all of the testing and linting related dependencies.
  • I replaced the outdated Istanbul code coverage npm package istanbul@^0.4.2 with their new maintained Istanbul nyc package nyc@^12.0.2.

This PR requires PR #375 and #376 to be merged before hand. I will rebase this PR as the other PRs are merged.

What testing has been done on this change?

Note: The links provided below contains results with the required PRs, mentioned above, merged.

Checklist

  • Reported an issue in the JIRA database
  • Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
  • Added automated test coverage as appropriate for this change.

@erisu erisu force-pushed the increase-code-coverage branch from 911b5b0 to 934f9ea Compare June 25, 2018 13:37
@brodycj brodycj changed the title Increase Code Coverage Increase Code Coverage & use nyc Jul 31, 2018
});
});

it('should find ios-sim version.', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason versions.get_tool_version('ios-sim'), versions.get_tool_version('ios-deploy'), and versions.get_tool_version('pod') do not work for me when I test on my local system, don't know why. Any clues?

I would also favor moving these into a separate script.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these tools installed locally? These tests can only run on a Darwin environment and with these tools installed.

I did not mock the child process exec so it an actual test, but does not care what is the exact version.

Both locally and on the Travis CI environment has these tools are installed. I did not configure Travis CI to install them. Either the environment already came with the tools or was installed via npm install. From package.json or the .travis.yml script step.

I could mock the data, but by mocking, I would not have discovered that the Mac OSX SDK changed to macOS SDK.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for separate scripts, do you mean something like a bash file? In /cordova-ios/bin there are some individual script files that calls onto versions.js to fetch the value for an individual item.

For example:
/cordova-ios/bin/apple_ios_version
/cordova-ios/bin/apple_osx_version
/cordova-ios/bin/apple_xcode_version

But it is missing the ios-sim, ios-deploy, and pod specific executable script.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I meant separate .spec.js file.

I will try npm i --save-dev ios-deploy and see if that solves at least part of the problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm i --save-dev ios-deploy seems to do the trick, except for versions.get_tool_version('pod'); I just pushed the change to your branch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding ios-deploy to package.json as a devDep will cause AppVeyor to fail. This package can only be installed and used on the Darwin platforms.

I question if testing iOS/macOS platform on AppVeyor is actually needed. Xcode is a build requirement and Windows cant use Xcode, and AppVeyor is running on Windows, what is achieved with this test.

npm ERR! code EBADPLATFORM

npm ERR! notsup Unsupported platform for ios-deploy@1.9.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"ia32"})
npm ERR! notsup Valid OS:    darwin
npm ERR! notsup Valid Arch:  any
npm ERR! notsup Actual OS:   win32
npm ERR! notsup Actual Arch: ia32

Copy link
Member Author

@erisu erisu Aug 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should this dep be added to the platform?

Per documentation, it's expected that the user installed it manually and globally.

  • Having it bundled with the platform might mean fewer setup steps.
  • Could the globally installed ios-deploy version be affected by which platform versions is installed on the project? If so, maybe it should be dep.

https://cordova.apache.org/docs/en/latest/guide/platforms/ios/#installing-the-requirements

@@ -67,5 +67,9 @@
"shelljs",
"xcode",
"xml-escape"
]
],
"nyc": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I would do npm install it writes the following change to package.json:

index 7b21884a..ee6b352a 100644
--- a/package.json
+++ b/package.json
@@ -69,7 +69,12 @@
     "xml-escape"
   ],
   "nyc": {
-    "include": ["bin/templates/scripts/**"],
-    "reporter": ["lcov", "text"]
+    "include": [
+      "bin/templates/scripts/**"
+    ],
+    "reporter": [
+      "lcov",
+      "text"
+    ]
   }
 }

I would favor having the "nyc" entry committed this way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to the formatting, each item on its own line? I can make this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I have a few other general remarks coming on this nice PR.

brodycj pushed a commit to brodycj/cordova-ios that referenced this pull request Jul 31, 2018
(was part of apacheGH-377)

covers update from apacheGH-376

Co-authored-by: エリス <ellis.bryan@gmail.com>
Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
@brodycj
Copy link
Contributor

brodycj commented Jul 31, 2018

Really nice in general. My major comment is that I am personally not ready to break deprecated Node.js 4 compatibility for a couple reasons:

  • make it easier to backport to 4.5.x branch if needed
  • I think we should drop Node.js 4, remove committed node_modules, and increase the major version all at the same time. I don't really want to do this without getting some agreement from others. I think these items should be done at the same time in its own PR, would be happy to take this one on.

I think we can keep deprecated Node.js 4 compat a couple straightforward changes:

  • do not upgrade eslint devDeps in this PR
  • use var instead of let & const for now

I think a valid alternative for using let & const would be to start using "use strict", not sure if we want to keep this for the future or not. Also if we introduce let & const I think we should consider transitioning the existing var declarations.

brodycj pushed a commit to brodycj/cordova-ios that referenced this pull request Jul 31, 2018
(was part of apacheGH-377)

covers update from apacheGH-376

Co-authored-by: エリス <ellis.bryan@gmail.com>
Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
expect(version).not.toBe(undefined);
done();
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case assumes that pod is installed. Easy solution for me is to install using homebrew as discussed in CocoaPods/CocoaPods#2238 (comment).

I have mixed feelings about this test. Positive is that it verifies that versions.get_tool_version() works on globally installed pod tool. Negative is that it may break some developers ability to try npm run unit-tests before raising PRs.

brodycj pushed a commit to brodycj/cordova-ios that referenced this pull request Jul 31, 2018
(was part of apacheGH-377)

covers update from apacheGH-376

Co-authored-by: エリス <ellis.bryan@gmail.com>
Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
brodycj pushed a commit that referenced this pull request Jul 31, 2018
(was part of GH-377)

covers update from GH-376

Co-authored-by: エリス <ellis.bryan@gmail.com>
Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
@brodycj
Copy link
Contributor

brodycj commented Jul 31, 2018

@erisu I took the liberty to include a small part of this PR in GH-384 (#384) that I just merged in order to add coverage for the changes merged from #376. I recommend that you rebase on master whenever you can.

I think you can see that I took a few more minor liberties on the title, description, and added commits to solve a few things.

As a side point I was able to get most of the changes working on 4.5.x with a few changes in PR #385.

@erisu
Copy link
Member Author

erisu commented Aug 1, 2018

@brodybits

With the recent mailing list discussion, to mark the next major Cordova dev release (cordova-ios@5.0.0-dev),
does it mean we can and will drop Node.js 4 for cordova-io after the release?

Some repos have already dropped Node 4 support and began using let, const, class etc in master. For example cordova-android.

I would prefer a uniform coding syntax usage across all repos and not having a one-off restriction on what can be used. I know that the drop support task will take time and create temporary restrictions/differences until completed.

As for the transitioning of var to let and const, I had been making these changes as I go along, with the understanding that Node 4 is soon to be dropped. I had not planned to do a mass search and replace though.

I also agree and excited to see the committed node_modules removed. I have always been wondering behind this.

do not upgrade eslint devDeps in this PR
I suspect this means to revert the eslint only devDeps from my PR, and we will be handled in #382 ?

The only concern I had with the other PR was the @next devDeps usage. I don't normally recommend using non-official release deps in production, though its only used for testing/linting and would not affect user projects.

I haven't looked too much into why it was decided.

@erisu erisu force-pushed the increase-code-coverage branch from 9baf297 to 815ea13 Compare August 1, 2018 02:49
@brodycj
Copy link
Contributor

brodycj commented Aug 1, 2018

@erisu I will raise additional PRs with proposal to split some things more clearly out of this PR (#377) and #382, then address your comments.

@codecov-io
Copy link

codecov-io commented Aug 3, 2018

Codecov Report

Merging #377 into master will increase coverage by 8.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #377      +/-   ##
==========================================
+ Coverage   65.62%   73.68%   +8.05%     
==========================================
  Files          14       11       -3     
  Lines        1702     1463     -239     
  Branches      286        0     -286     
==========================================
- Hits         1117     1078      -39     
+ Misses        585      385     -200
Impacted Files Coverage Δ
bin/templates/scripts/cordova/lib/run.js 22.85% <0%> (-2.54%) ⬇️
bin/templates/scripts/cordova/lib/prepare.js 83.56% <0%> (-1.11%) ⬇️
bin/templates/scripts/cordova/lib/projectFile.js 92.98% <0%> (-0.87%) ⬇️
...ates/scripts/cordova/lib/plugman/pluginHandlers.js 87.93% <0%> (-0.51%) ⬇️
bin/templates/scripts/cordova/lib/PodsJson.js 100% <0%> (ø) ⬆️
bin/templates/scripts/cordova/lib/clean.js
bin/templates/scripts/cordova/loggingHelper.js
...mplates/scripts/cordova/lib/copy-www-build-step.js
bin/templates/scripts/cordova/Api.js 60.99% <0%> (+1.75%) ⬆️
bin/templates/scripts/cordova/lib/Podfile.js 80.34% <0%> (+2.74%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f628f61...7d96cb5. Read the comment docs.

@brodycj
Copy link
Contributor

brodycj commented Aug 3, 2018

@erisu I think this is good, hope we can deal with a few minor points:

I would be fine if you want to finish and merge this one yourself, if you want me to review again, or even if you would like me to take this one over.

@erisu
Copy link
Member Author

erisu commented Aug 6, 2018

@brodybits When you have some time, can you review this one more time? Especially the last three commit.

The last three commit should cover the items from your previous message.

  • Reverted ESLint Package Updates: Will be covered in another PR.
  • Restructured Testing: There are now three jasmine configurations.
    (Unit, Component, and Coverage)

Regards with the second item point, I also agree that users may not install external dependencies such as pods and ios-deploy but should be able to run unit testing.

In this case, I introduced component testing. This is a good example of component level testing where it involves two or more components. I didn't go with e2e for this because its not a full end-to-end test.

  • Travis CI had been updated to run both unit and component.

  • Users can continue to use npm run unit-tests or npm test and not be affected by component testing.

  • Added Jasmin coverage config to display code cover report with both unit and component.

Regards to the last item, commit cleanup, can you explain what is intended? Typically I squash my commits but since it was mentioned to not squash, I am trying to figure out how to clean up in what way.

Please let me know your thoughts.

@brodycj
Copy link
Contributor

brodycj commented Aug 6, 2018

@erisu now I understand a few things. My one major criticism is that I think npm test should do all existing tests, meaning npm test should include e2e (general case) or component (this case). If user does not have standard iOS dev tools including ios-deploy and pod then I think it is fine to say that full npm test would not work. I think these tools should not be extremely hard to install for someone working on cordova-ios.

I personally do not really like squashing multiple kinds of changes together, like both migrating to nyc and adding more test coverage. More things at the same time could be more to grasp at the same time. Major factor is that if someone wants to back-port to an earlier release, separate commits would be nicer. But this is just my personal opinion, some others seem more likely to squash.

And a side question: I thought you had made a change to introduce jasmine-spec-reporter but couldn't find it. Maybe it was someone else. I think it would be nice, probably in a separate PR. Update: It was someone else who introduced jasmine-spec-reporter on cordova-lib, which is now merged, would make a nice separate PR on this and other Cordova repos.

erisu added 3 commits August 6, 2018 12:03
Replaced outdated istanbul with Istanbul nyc (Fixes nodejs 10 coverage run issue)
- Completed remaining versions.js testing for full coverage
- Added Jasmine Coverage Configuration
- Added component test execution to npm test
@erisu erisu force-pushed the increase-code-coverage branch from 6d5086d to 7d96cb5 Compare August 6, 2018 03:26
@brodycj
Copy link
Contributor

brodycj commented Aug 8, 2018

I would like to add another comment that I think the concept of unit test vs e2e integration test is currently not consistent between all Cordova repos, and is actually not so clear to me. For example: it is actually not so clear to me what defines "spec" test vs e2e integration test in cordova-lib. Noting this here before it gets forgotten.

@erisu
Copy link
Member Author

erisu commented Aug 8, 2018

@brodybits Yes, I also see sometimes inconsistencies across all repos. Basically, I see testing broken into three categories. This is how I view testing in general.

What tasks or open action items we should do from these comments is something I am not sure about, as of yet. Maybe we just need document the difference and when to pick one over the other. We should update the repos at least to be consistent with the structure.

Sorry if it sounds a bit generic and maybe textbook.

Unit Testing, which are the test specs and I feel in most cases these are done well.

Component Testing is testing between two or more components. For example our previous situation with the pods and ios-deploy tools. Component testing may also involve environment configurations to ensure that the test work. One good old example is the Application + Database

E2E Testing is testing the entire system as a whole. How we define E2E, I am also not clear. It seems in this repo, E2E represents if the basic app builds. In most cases, I feel E2E starts from the highest point in how end users typically use Cordova. In this case, I would think all of our E2E tests would be within CLI.

There are other testing categories like UI testing.

@erisu
Copy link
Member Author

erisu commented Aug 8, 2018

I also want to update package.json. But I did not know when, where, and should it be brought up. Some of it might be a bit opinionated though.

1. Not all commands are consistent between each repo.

Example:
cordova-ios has npm run unit-tests
cordova-common has npm run jasmine
cordova-docs has npm run test-unit

2. (opinionated) The script naming convention.

"test": "",
"posttest": "",
"cover": "",
"e2e-tests": "",
"objc-tests": "",
"objc-tests-lib": "",
"objc-tests-framework": "",
"preobjc-tests": "",
"unit-tests": "",
"eslint": ""

would become

"coverage": "",
"test:e2e": "",
"test:objc": "",
"test:objc:lib": "",
"test:objc:framework": "",
"test:objc:pre": "",
"test:unit": "",
"linting": ""

This is opinionated so there is no priority and if no action, it is all good.

3. (opinionated) Order of the testing.

"test": "npm run e2e-tests && npm run objc-tests && npm run unit-tests",
"posttest": "npm run eslint",

becomes

"pretest": "npm run eslint",
"test": "npm run test:unit && npm run test:component && npm run test:objc && npm run test:e2e"

Should linting actually be a pretest instead of post?

The order of the tests seems reversed IMO. E2E tests take the longest time to run. It should be the last.

If a unit test fails, it is likely that the e2e tests will fail. The CI I believe stops at the failure? Correct me if I am wrong.

If the e2e ran first, fails, and stop the CI, we had to wait for the test to finish first, and then we have to investigate where in the process it failed.

Prefered Order: unit -> component -> e2e

@brodycj
Copy link
Contributor

brodycj commented Aug 8, 2018

Those testing categories seem to make sense, would need some more time to better understand. Should ideally be discussed somewhere else if it affects multiple repos. Changes approved on my part.

@erisu erisu merged commit c109ce7 into apache:master Aug 10, 2018
erisu added a commit to erisu/cordova-ios that referenced this pull request Jan 16, 2019
(was part of apacheGH-377)

covers update from apacheGH-376

Co-authored-by: エリス <ellis.bryan@gmail.com>
Co-authored-by: Christopher J. Brody <chris.brody@gmail.com>
@erisu erisu deleted the increase-code-coverage branch April 4, 2019 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants