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

Audit @flow and "use strict" #3451

Merged
merged 7 commits into from
May 12, 2017
Merged

Audit @flow and "use strict" #3451

merged 7 commits into from
May 12, 2017

Conversation

mpontus
Copy link
Contributor

@mpontus mpontus commented May 3, 2017

These changes address the proposal from #3169

Summary

  • "use strict" was removed and replaced with transform-strict-mode babel plugin.
  • Contributing guidelines and dangerfile have been updated to reflect this change.
  • @flow annotations have been added to some files

In regards to the use of "use strict" there remains to be an issue with following file:
https://github.com/facebook/jest/blob/master/packages/jest-util/src/setGlobal.js

Babel plugin is going to add "use strict" annotation to the compiled file which will break unit tests for Node 7.3.

Summary of all failing tests
 FAIL  packages/jest-runtime/src/__tests__/Runtime-cli-test.js (6.138s)
  ● Runtime › cli › always disables automocking

    expect(received).toMatch(expected)
    
    Expected value to match:
      "Hello, world!
    "
    Received:
      ""
      
      at Object.it (packages/jest-runtime/src/__tests__/Runtime-cli-test.js:46:29)
      at process._tickCallback (internal/process/next_tick.js:103:7)

 FAIL  integration_tests/__tests__/env-test.js (5.488s)
  ● Environment override › uses jsdom when specified

    TypeError: Cannot read property 'trim' of undefined
      
      at getLog (integration_tests/__tests__/env-test.js:13:65)
      at Object.it (integration_tests/__tests__/env-test.js:19:12)
      at process._tickCallback (internal/process/next_tick.js:103:7)

Following files were left without @flow annotations. As far as I know typechecking them would require some changes to the codebase which I was hesitant to introduce without explicit instructions.

https://github.com/facebook/jest/blob/master/packages/jest-config/src/vendor/jsonlint.js
https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/jasmine/createSpy.js
https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/jasmine/Env.js

Test plan
Verify that typechecking produces no errors:

$ yarn test
yarn run v0.23.2
$ yarn run typecheck --silent && yarn run lint --silent && yarn run jest --silent && yarn run test-examples --silent 
....
Ran all test suites in 10 projects.
Done in 81.75s.

Find files processible by babel with "use strict" (should be no files)

$ find packages/*/src -name '*.js' -not \( -path '*/__tests__/*' -or -path '*/__mocks__/*' \) | xargs -d "\n" grep -l "'use strict'"

Find package source files without @flow

$ find packages/*/src \( -name '*.js' -or -name '*.jsx' \) -not \( -path '*/__tests__/*' -or -path '*/__mocks__/*' \) |xargs -d "\n" grep -L '@flow'
packages/jest-config/src/vendor/jsonlint.js
packages/jest-jasmine2/src/jasmine/createSpy.js
packages/jest-jasmine2/src/jasmine/Env.js

@mpontus
Copy link
Contributor Author

mpontus commented May 3, 2017

I reverted the removal of "use strict" from test and mock files. These files will not be processed by babel during the execution of integration tests, and will cause them to fail for Node 4 which does not permit the use of block-scoped declarations (let) outside of strict mode.

@codecov-io
Copy link

codecov-io commented May 3, 2017

Codecov Report

Merging #3451 into master will increase coverage by 0.11%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3451      +/-   ##
==========================================
+ Coverage   62.28%   62.39%   +0.11%     
==========================================
  Files         181      181              
  Lines        6714     6646      -68     
  Branches        6        6              
==========================================
- Hits         4182     4147      -35     
+ Misses       2529     2496      -33     
  Partials        3        3
Impacted Files Coverage Δ
packages/jest-cli/src/lib/updateArgv.js 95.23% <ø> (ø) ⬆️
packages/jest-validate/src/errors.js 100% <ø> (ø) ⬆️
packages/jest-validate/src/index.js 0% <ø> (ø) ⬆️
packages/jest-util/src/formatTestResults.js 0% <ø> (ø) ⬆️
packages/jest-jasmine2/src/p-timeout.js 100% <ø> (ø) ⬆️
packages/jest-cli/src/lib/getTestPathPattern.js 60% <ø> (ø) ⬆️
...ckages/jest-config/src/reporterValidationErrors.js 20% <ø> (-13.34%) ⬇️
packages/jest-test-typescript-parser/src/index.js 0% <ø> (ø) ⬆️
packages/jest-haste-map/src/worker.js 94.59% <ø> (ø) ⬆️
packages/jest-cli/src/generateEmptyCoverage.js 90% <ø> (ø) ⬆️
... and 183 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 6a12116...2eb2769. Read the comment docs.

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good! I think we could further improve types in Jasmine, but maybe not in this diff. Also @wtgtybhertgeghgtwtg is probably working on that already.


function ReportDispatcher(methods) {
function ReportDispatcher(methods: Object) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

methods are an array, could you improve this type?

var result = true;

var asymmetricResult = asymmetricMatch(a, b);
if (!isUndefined(asymmetricResult)) {
if (asymmetricResult !== void 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

undefined maybe?

@mpontus
Copy link
Contributor Author

mpontus commented May 4, 2017

Thanks @thymikee! I updated my pull request as per your suggestions.

On a related note, would it be acceptable if I rebase my branch on top of jest/master while pull request is open?

@thymikee
Copy link
Collaborator

thymikee commented May 4, 2017

Of course it is acceptable! :)

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Just this one change and I can approve this :)

package.json Outdated
@@ -14,6 +14,7 @@
"babel-preset-env": "^1.4.0",
"babel-preset-react": "^6.24.1",
"babel-preset-react-native": "^1.9.1",
"babel-plugin-transform-strict-mode": "^6.22.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use version 6.24.1? We already have that in our transitive deps (see yarn.lock)

@jest-bot
Copy link
Contributor

jest-bot commented May 5, 2017

Warnings
⚠️ Changes were made to package.json, but not to yarn.lock - Perhaps you need to run `yarn install`?

Generated by 🚫 dangerJS

@cpojer cpojer merged commit 9b157c3 into jestjs:master May 12, 2017
@cpojer
Copy link
Member

cpojer commented May 12, 2017

The node 7.3 thing, I don't care any more. That was reverted and we don't need it. We can tell people to either downgrade Jest or upgrade node if it happens.

orta pushed a commit to orta/jest that referenced this pull request Jul 7, 2017
* Remove 'use strict' from all files

* 'use strict' removed from pacakges' sources
* Strict mode is now enabled automatically by babel
* 'use strict' check removed from dangerfile
* Updated contributing guidelines

* Enable @flow for most files

* Commit yarn.lock

* Revert removal of "use strict" in test and mock files

* Improve annotations for ReportDispatcher

* Replace "void 0" with "undefined"

* Update babel-plugin-transform-strict-mode to match transitive deps
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
* Remove 'use strict' from all files

* 'use strict' removed from pacakges' sources
* Strict mode is now enabled automatically by babel
* 'use strict' check removed from dangerfile
* Updated contributing guidelines

* Enable @flow for most files

* Commit yarn.lock

* Revert removal of "use strict" in test and mock files

* Improve annotations for ReportDispatcher

* Replace "void 0" with "undefined"

* Update babel-plugin-transform-strict-mode to match transitive deps
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants