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

Integrate the mobile React Native testsuite with the main Gutenberg build #9883

Merged
merged 18 commits into from
Sep 18, 2018

Conversation

hypest
Copy link
Contributor

@hypest hypest commented Sep 13, 2018

Description

This PR adds the native mobile app repo as a git submodule and includes the mobile testsuite into the npm test script and the Travis test pipeline.

How has this been tested?

Locally doing npm test runs green.

To test:

  1. Checkout the Gutenberg code into a new directory and cd into it
  2. git submodule update --init --recursive to pull in the mobile submodule and its submodules
  3. Follow the typical Gutenberg setup instructions
  4. Tests should run green and also include the mobile tests. To confirm, look for the Setting RN platform to string in your terminal's ouput.

Types of changes

This PR doesn't introduce any code changes. All changes are done in the setup/tooling side of the project. In particular, the changes include:

  • Installing yarn, the package manager used by the mobile project. That's needed by the mobile npm scripts only.
  • The mobile repo has its own set of linting, compilation and run configurations so all those are ignored. .eslintignore got adjusted and .stylelinignore is introduced.
  • The test npm script adopts the test-mobile script to run after the Gutenberg unit tests
  • 3 jobs are added to Travis: code correctness tests, Android codepath tests, iOS codepath tests
  • Gutenberg testsuites (unit, e2e) are ignoring the test modules inside the mobile folder since those need their own Jest configuration.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

The mobile code is assumed to be in the `gutenberg-mobile` subfolder.
The mobile project has its own lint rules and until the two projects can
work off the same rules the main Gutenberg project needs to ignore it.
The mobile project still has Gutenberg as its own git submodule and so,
many packages can be found in two places. Jest tests need to ignore the
occurance of this second gutenberg sourcetree instance.
Instead, run `yarn install` earlier or in the same manner as `npm install`.
@hypest hypest added [Status] In Progress Tracking issues with work in progress Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) labels Sep 13, 2018
@hypest hypest added [Type] Build Tooling Issues or PRs related to build tooling and removed [Status] In Progress Tracking issues with work in progress labels Sep 13, 2018
@@ -72,6 +72,21 @@ npm install
# Make sure npm is up-to-date
npm install npm -g

# Check if yarn is installed
if [ "$TRAVIS" != "true" ] && ! command_exists "yarn"; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why yarn is used for mobile? Can't we just make it "optional" and rely on npm consistently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yarn is the main packager used in React Native apps, at least that's what FB is using in the documentation and all.

We wanted to stay close to whatever is most popular in the React Native ecosystem so we keep our dev setup as "best practices" as possible.

That said, I think there is probably no special reason to stay with yarn down the road so, I could see us replacing that later and certainly when we integrate the 2 toolchains (web, RN) even more.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Nice addition, by looking at travis, it looks like the test are run in parallel and performant enought to include them.

I'd love some instructions on the testing documentation on how to run these locally... and how to potentially debug them if we notice failure.

@hypest
Copy link
Contributor Author

hypest commented Sep 14, 2018

I'd love some instructions on the testing documentation on how to run these locally... and how to potentially debug them if we notice failure.

For sure! I think I could add some instructions. To be honest, not sure where that testing documentation is so, any pointers will be appreciated :)

That said, could we defer adding that documentation to a follow up PR? I can work on that PR immediately but, it would be awesome if we merged this one as soon as we can. It seems that even as we speak, changes land to Gutenberg that break the mobile (recent one: a Dropdown that breaks the mobile build #9687 ) and it would be useful to avoid that now that we have this PR and works. WDYT @youknowriad ?

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍 but I'd appreciate a second opinion before moving forward.

@youknowriad youknowriad requested a review from a team September 17, 2018 08:03
@hypest
Copy link
Contributor Author

hypest commented Sep 17, 2018

FWIW, added fecffe2 to pick up Riad's good suggestion to add some documentation on how to use or debug in case of mobile error.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

There are some workflow issues here. I should expect to be able to run this without any issues, or at least very clear instructions on how to proceed (ideally with as few blockers as possible):

git clone https://github.com/WordPress/gutenberg.git
cd gutenberg
npm install
npm test

But there's a few issues:

  • We don't present the Yarn requirement at any point except through bin/install-node-nvm.sh. I don't use this workflow, so I'd expect others won't as well. Thus, when run a user will see an error sh: yarn: command not found .
  • Even if the user manages to infer their way to installing Yarn, we don't automate the submodule initialization, so the user is then presented with error Command "test:inside-gb" not found.
  • ... I might have more commentary here, but even I couldn't figure out how I was supposed to get these tests actually running past this point. Running git submodule --init --recursive presents me with what appears to be an "invalid command" Git usage listing:
⇒ git submodule --init --recursive

usage: git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
   or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
   or: git submodule [--quiet] init [--] [<path>...]
   or: git submodule [--quiet] deinit [-f|--force] (--all| [--] <path>...)
   or: git submodule [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
   or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
   or: git submodule [--quiet] foreach [--recursive] <command>
   or: git submodule [--quiet] sync [--recursive] [--] [<path>...]
   or: git submodule [--quiet] absorbgitdirs [--] [<path>...]

Even if there's some intention around removing the Yarn dependency, we should then at least make this opt-in (only run by direct command and in Travis) until that's a reality.

```
git submodule --init --recursive
```
You can then use the available script to lanuch the mobile testsuite in isolation:
Copy link
Member

Choose a reason for hiding this comment

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

Typo: "lanuch" -> "launch"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with 60a4935.

package.json Outdated
@@ -181,10 +181,11 @@
"publish:check": "npm run build:packages && lerna updated",
"publish:dev": "npm run build:packages && lerna publish --npm-tag next",
"publish:prod": "npm run build:packages && lerna publish",
"test": "npm run lint && npm run test-unit",
"test": "npm run lint && npm run test-unit && npm run test-mobile",
Copy link
Member

Choose a reason for hiding this comment

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

Can any of these be run concurrently? I seem to recall some race conditions previously which prevented some concurrent testing, but if test-mobile is meant to be isolated from other tests (at least for linting) maybe it's not problematic?

Copy link
Contributor Author

@hypest hypest Sep 17, 2018

Choose a reason for hiding this comment

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

Can't really atest for lint and test-unit between them but yeah, test-mobile should be completely possible to run in parallel to the the rest.

Would you suggest I turn this into "test": "concurrently \"npm run lint && npm run test-unit\" \"npm run test-mobile\"" perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's what I'd have in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done with 0c5da64.

package.json Outdated
"pretest-e2e": "concurrently \"./bin/reset-e2e-tests.sh\" \"npm run build\"",
"test-e2e": "cross-env JEST_PUPPETEER_CONFIG=test/e2e/puppeteer.config.js wp-scripts test-unit-js --config test/e2e/jest.config.json --runInBand",
"test-e2e:watch": "npm run test-e2e -- --watch",
"test-mobile": "cd gutenberg-mobile; yarn test:inside-gb; cd ..;",
Copy link
Member

Choose a reason for hiding this comment

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

Have you checked that this works in Windows?

Copy link
Contributor Author

@hypest hypest Sep 17, 2018

Choose a reason for hiding this comment

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

Hmm, no I haven't 😬

I'd be inclined to modify this into a single yarn --cwd gutenberg-mobile test:inside-gb command if you think it can be problematic in its current form.

@hypest
Copy link
Contributor Author

hypest commented Sep 17, 2018

Thanks for adding your review @aduth ! I've addressed your inline comments and here's some response to your awesome review comments:

There are some workflow issues here. I should expect to be able to run this without any issues:

git clone https://github.com/WordPress/gutenberg.git
npm install
npm test

But there's a few issues:

We don't present the Yarn requirement at any point except through bin/install-node-nvm.sh. I don't use this workflow, so I'd expect others won't as well. Thus, when run a user will see an error sh: yarn: command not found .

Aha, interesting. Not super familiar with the use cases of bin/install-node-nvm.sh but my understanding was that everyone would have been put through the initial setup for Gutenberg dev that involves bin/install-node-nvm.sh been ran anyway. In this case, installing yarn (globally) should be considered a step for that early setup phase.

What I can try and do here though is install yarn as a local dep, not a global package, and use it via npx. In that case, there will be no need for a manual installation of it other than the typical npm install. Would that be a better form of dependency?

Even if the user manages to infer their way to installing Yarn, we don't automate the submodule initialization, so the user is then presented with error Command "test:inside-gb" not found.

Indeed, as mentioned in the PR description, one would need to do that manually. What I can do here is to hook the submodule update to the preinstall script to be run automatically. Updating the submodule is super quick if it has been done once and the submodule ref hasn't changed so, there will be no performance impact at all to repeated use of the script. WDYT?

I might have more commentary here, but even I couldn't figure out how I was supposed to get these tests actually running past this point. Running git submodule --init --recursive presents me with what appears to be an "invalid command" Git usage listing:

Yeah, that's a 🤦‍♂️ error 😃. I forgot to add the update command to git there. I've updated the PR description to include it, sorry for the trouble 😬.

Even if there's some intention around removing the Yarn dependency, we should then at least make this opt-in (only run by direct command and in Travis) until that's a reality.

Gave it a quick try and it won't be trivial to remove the yarn dependency. So, for now, WDYT about adding it to devDependencies instead of a global install?

EDIT: I went ahead and made yarn a dev dependency with 5eaf120 so it is easier to assess.

* Yarn is installed locally as a development dependency
* The mobile submodule is updated in preinstall
* The mobile packages are installed in preinstall as well
* Yarn is executed by providing the working (sub)directory as a
parameter
* No need to install yarn globally in Travis
@hypest
Copy link
Contributor Author

hypest commented Sep 18, 2018

Ready for another pass @aduth ! The "clone repo, npm install, npm test" routine should be available and running correctly, including the mobile tests. Let me know how that works for you, thanks!

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

It might be worth considering the size of Yarn as a dependency, but I'm content to prioritize the developer experience of the install. It didn't seem to bog down for me in any case.

Workflow feels much nicer now. Left one comment for your consideration.

@@ -25,5 +25,8 @@
"/test/e2e",
"<rootDir>/.*/build/",
"<rootDir>/.*/build-module/"
],
"modulePathIgnorePatterns": [
"<rootDir>/gutenberg-mobile/"
Copy link
Member

Choose a reason for hiding this comment

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

Should we include this for coveragePathIgnorePatterns ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good point, seems like we should. Will look into it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done with 24cd903.

@hypest
Copy link
Contributor Author

hypest commented Sep 18, 2018

It might be worth considering the size of Yarn as a dependency

Oh, I might not be well versed with this. Can you elaborate @aduth ? The yarn dependency is added as a devDependencies so I assume it won't affect the runtime bundle, no? Is it a problem even as a dev dependency?

In terms of how impactful can running it on every npm install can be, the repeated run is actually very very fast unless the mobile code or configuration changed, at which case it's normal to have it update whatever is needed anyway.

That said, if there is something more on your mind that is potentially a source of trouble please, do share so we pay attention.

but I'm content to prioritize the developer experience of the install. It didn't seem to bog down for me in any case.

Workflow feels much nicer now. Left one comment for your consideration.

Nice, good to hear! I'm sure we will keep an eye on keeping it good and better as we integrate more and more 👍

@aduth
Copy link
Member

aduth commented Sep 18, 2018

The yarn dependency is added as a devDependencies so I assume it won't affect the runtime bundle, no? Is it a problem even as a dev dependency?

In terms of how impactful can running it on every npm install can be, the repeated run is actually very very fast unless the mobile code or configuration changed, at which case it's normal to have it update whatever is needed anyway.

I wouldn't expect to be a concern for the runtime bundle, no. More in terms of cost as in the added time it takes to get a development environment up-and-running (the time of npm install). As mentioned, I think the workflow wins here are more than enough to offset any cost.

@hypest
Copy link
Contributor Author

hypest commented Sep 18, 2018

Thanks for the thorough reviews here all. Will go ahead and merge now, thanks!

@hypest hypest merged commit cb908cf into master Sep 18, 2018
@hypest hypest deleted the rnmobile/integrate-mobile-rn-testsuite branch September 18, 2018 17:30
@aduth
Copy link
Member

aduth commented Oct 26, 2018

That said, could we defer adding that documentation to a follow up PR?

Gave it a quick try and it won't be trivial to remove the yarn dependency. So, for now, WDYT about adding it to devDependencies instead of a global install?

There's implied to be some follow-up tasks here. Where can I track their progress?

Is the submodule intended to remain long-term? If not, which issue can I follow to track this progress? If so, how do we intend to remedy some of the workflow issues surrounding the submodule (showing as modified in local branch despite not being touched, "Find in Files" revealing duplicate copies from the submodule directory).

@hypest
Copy link
Contributor Author

hypest commented Oct 29, 2018

There's implied to be some follow-up tasks here. Where can I track their progress?

👋 @aduth , I had added some documentation with fecffe2 earlier in this PR. See native-mobile-testing and debugging-native-mobile.

Is the submodule intended to remain long-term?

Not really. But you know how these things go... "short term" can be long :). Joke aside, the current setup kinda helps us move forward but it's far from optimal. I just wished I had some time to at least try the git subtree idea I'm having and take it from there.

If not, which issue can I follow to track this progress?

None atm. Happy to accept suggestions on this one. What's the typical pattern we use in the Gutenberg repo to have such a ticket?

how do we intend to remedy some of the workflow issues surrounding the submodule (showing as modified in local branch despite not being touched

That's weird, how does that happen? Any steps available? FWIW, running the tests doesn't leave any trash behind to mark the submodule as dirty 🤔 . OTOH, changing to a different branch may leave the submodule un-updated, in which case npm install would fix it or if you manually update the submodules.

"Find in Files" revealing duplicate copies from the submodule directory

That should be relatively easy to fix. We just need to update all the nested (inside gutenberg-mobile) submodules except the gutenberg submodule, which is not needed in this setup. That should allieviate the duplicate results.

@chrisvanpatten
Copy link
Member

OTOH, changing to a different branch may leave the submodule un-updated, in which case npm install would fix it or if you manually update the submodules.

It can also happen when running a git pull. npm install does update the submodule and fixes it up.

hypest added a commit that referenced this pull request Oct 31, 2018
aduth pushed a commit that referenced this pull request Oct 31, 2018
* Revert "Have Travis run mobile tests that use the parent code (#10034)"

This reverts commit b1d9fb7.

* Revert "Integrate the mobile React Native testsuite with the main Gutenberg build (#9883)"

This reverts commit cb908cf.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants