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

Fix broken test globs and coverage scripts #475

Merged
merged 4 commits into from May 22, 2020
Merged

Conversation

@jasonkarns
Copy link
Contributor

jasonkarns commented May 7, 2020

Summary

globs
It is not safe to use unquoted globstars within npm scripts because they
are not expanded consistently on all versions of bash. Specifically,
globstar isn't even available until version 4 of bash; and macOS still
ships with v3. (Ergo, globstar won't work on stock macOS)
Further, even if it is available, it's only an option. Nothing ensures
the option is enabled.

Clearly, some prior developer recognized that the tests weren't all
running and they "duplicated" the glob pattern to ensure it matched all
files. However, they did 3 things wrong:

  1. mocha (like virtually all *nix utilities) expects file arguments
    last
  2. they still didn't properly quote the globs, merely worked around the
    globstar issue by manually matching 3 directory levels
  3. the workaround still doesn't robustly match recursive directories
    because it only goes three levels deep

The proper fix is to quote the glob pattern such that mocha itself (by
means of a dependency) will expand the globstar pattern consistently
regardless of shell version.

istanbul
Istanbul coverage is broken (https://travis-ci.org/github/optimizely/javascript-sdk/jobs/683996183#L1612) but istanbul is also deprecated.

This replaces istanbul with nyc and cleans up the coverage scripts and flow. The coverage is still broken (needs some ES or TS plugins for nyc) but it's an improvement.

npm scripts
Also sorts the npm scripts a bit more logically and auto-runs lint after npm-test.

@jasonkarns jasonkarns requested a review from optimizely/fullstack-devs as a code owner May 7, 2020
@jasonkarns
Copy link
Contributor Author

jasonkarns commented May 7, 2020

I also considered updating mocha's version in this PR because it's 2 major versions behind latest. But I decided against it. However, the test suite did run SUCCESSFULLY 🎉 against the latest version (v7.1.2) without any further modifications! So presumably it would be safe to bump.

Copy link
Contributor

mjc1283 left a comment

Thanks for these cleanups, they make sense to me. Just one question about always running nyc as part of npm run test.

packages/optimizely-sdk/package.json Outdated Show resolved Hide resolved
jasonkarns added 4 commits May 21, 2020
It is not safe to use unquoted globstars within npm scripts because they
are not expanded consistently on all versions of bash. Specifically,
globstar isn't even available until version 4 of bash; and macOS still
ships with v3. (Ergo, globstar won't work on stock macOS)
Further, even if it _is_ available, it's only an option. Nothing ensures
the option is enabled.

Clearly, some prior developer recognized that the tests weren't all
running and they "duplicated" the glob pattern to ensure it matched all
files. However, they did 3 things wrong:

1. mocha (like virtually all *nix utilities) expects file arguments
   _last_
2. they still didn't properly quote the globs, merely worked around the
   globstar issue by manually matching 3 directory levels
3. the workaround still doesn't robustly match recursive directories
   because it only goes three levels deep

The proper fix is to quote the glob pattern such that mocha itself (by
means of a dependency) will expand the globstar pattern consistently
regardless of shell version.
Istanbul coverage is broken. Instead of fixing it, replace with nyc
because istanbul is deprecated.
- `cover` script:
  - triggers test run (includes instrumentation)
  - prints report summary to STDOUT
  - generates html report for manual viewing
  - generates lcov report for coveralls
- `coveralls` script:
  - triggers `cover` reporting script
  - uploads lcov.info report to coveralls
@jasonkarns jasonkarns force-pushed the github:npm-scripts branch from 649ef90 to 2d8a8ad May 21, 2020
@jasonkarns
Copy link
Contributor Author

jasonkarns commented May 21, 2020

Updated the scripts to not run coverage as part of npm-test.

To summarize, the istanbul coverage was broken prior to this PR. And after this PR, coverage is still broken, but is configured to use the istanbul cli replacement: nyc.

nyc is reporting 0 coverage after this PR (which is an improvement from before this PR, where the coverage script actually errored). I haven't figured out why nyc is reporting 0 coverage, but I suspect it has something to do with the mocha --exit flag or requiring esm. (Or perhaps even the unhandled rejection hook.)

Perhaps the fix for #487 will fix the coverage. Regardless, this PR doesn't leave the test suite or coverage in a worse place than before, but it still needs work.

packages/optimizely-sdk/package.json Outdated Show resolved Hide resolved
@jasonkarns jasonkarns force-pushed the github:npm-scripts branch from 7180ce1 to 2d8a8ad May 22, 2020
"precover": "nyc npm test",
"cover": "nyc report -r lcov",
"precoveralls": "npm run cover",
"coveralls": "< coverage/lcov.info coveralls",

This comment has been minimized.

@jasonkarns

jasonkarns May 22, 2020 Author Contributor

To clarify the weirdness of putting the file redirection in front: this allows extra flags to be passed when running via npm:

npm run coveralls -- --foo will pass --foo along to the coveralls command. If input/output redirection is tacked on at the end of the script as is common in shell, then that would cause a malformed command.

@mjc1283 mjc1283 merged commit 58b5412 into optimizely:master May 22, 2020
7 checks passed
7 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
optimizely/full-stack-benchmark-suite (javascript - browser) Build result: success
Details
optimizely/full-stack-benchmark-suite (javascript - node) Build result: success
Details
optimizely/fullstack-sdk-compatibility-suite (javascript - browser) Build result: success
Details
optimizely/fullstack-sdk-compatibility-suite (javascript - node) Build result: success
Details
optimizely/react-native-testapp (javascript - react-native-android) Build result: success
Details
optimizely/react-native-testapp (javascript - react-native-ios) Build result: success
Details
@jasonkarns jasonkarns deleted the github:npm-scripts branch May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.