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

build(dev-infra): setup basic e2e structure #410

Merged
merged 2 commits into from Jul 14, 2020
Merged

build(dev-infra): setup basic e2e structure #410

merged 2 commits into from Jul 14, 2020

Conversation

ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented Jul 12, 2020

Summary

  • Added scripts folder which includes e2e.js to run e2e tests with example apps. This folder also contains some helpers.

  • Added an example app using Angular 10 with basic setup for jest and jest-preset-angular.

  • Added new scripts to package.json.

Test plan

  • Check out this branch and run yarn test:e2e in your local.

Additional information

This PR only creates a basic e2e structure setup but won't include this into CI yet. The next PR will do it (also including moving the app in example to e2e folder)

@ahnpnl ahnpnl requested a review from wtho July 12, 2020 11:21
@ahnpnl ahnpnl changed the title chore(dev-infra): setup basic e2e structure build(dev-infra): setup basic e2e structure Jul 12, 2020
Copy link
Collaborator

@wtho wtho left a comment

Choose a reason for hiding this comment

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

For me the /scripts/ look fine, but a /scripts/README.md explaining the basic features of each script would be great, just to lower the bar for contributors a bit.

Otherwise this is a great modularization of the preset, thank you!

.npmignore Outdated Show resolved Hide resolved
.npmignore Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Jul 12, 2020

Sure I will add some explanations for each script

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Jul 12, 2020

added README.md in scripts.

@ahnpnl ahnpnl requested a review from thymikee as a code owner July 12, 2020 20:58
scripts/lib/spawn-sync.js Outdated Show resolved Hide resolved

What will happen in order is as following:

1. A bundle (we'll call it `[bundle]`) will be created for `jest-preset-angular` using `npm pack` (`yarn pack` is buggy).
Copy link
Owner

Choose a reason for hiding this comment

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

I'd suggest running from the source, to simplify setup. But running bundle has its own benefits, so I won't oppose too much

## Running tests

You run the tests on example apps with `yarn test:e2e` (or `npm run test:e2e)`. In `scripts/lib/paths.js`,
`projectsToRun` must be modified if a new project is added to `e2e`.
Copy link
Owner

Choose a reason for hiding this comment

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

could be determined automatically using glob package on e2e/ directory. However, I'd much prefer using Jest's "projects" to facilitate e2e testing, which would get rid of custom sync tests running script

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do in a separate PR to setup yarn workspace and use jest "projects"

scripts/e2e.js Outdated

// then we can run the tests
const useYarn = existsSync(join(monorepoRealPath, 'yarn.lock'))
const cmdLine = projectPkg.scripts && projectPkg.scripts.test ? [useYarn ? 'yarn' : 'npm', 'test'] : ['jest']
Copy link
Owner

Choose a reason for hiding this comment

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

we run "npm" install to then run "yarn test"? would be nicer to pick one package manager (I suggest yarn) and stick to it. I'm fine with using "npm pack" for packing

Copy link
Collaborator Author

@ahnpnl ahnpnl Jul 13, 2020

Choose a reason for hiding this comment

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

ya the part of installing other dependencies can stick with yarn. However, the part of installing the .tgz needs to stick with npm because yarn doesn't have the option to say "no change in package.json when installing this dependency", see yarnpkg/yarn#1743


## Why

E2E tests being in a temporary folder of the operating system ensure none of the parents would be containing `node_modules`.
Copy link
Owner

Choose a reason for hiding this comment

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

I don't see any reference to creating a temporary dir in the code. I can only see chdir to e2e/<project> and running commands there. In such case, I'd highly suggest using Jest's "projects" feature:
https://jestjs.io/docs/en/configuration#projects-arraystring--projectconfig and use Yarn workspaces to minimize the network payload when downloading all dependencies of the project and e2e tests. This may be challenging to set up, but faster builds, less maintenance and less network payloads are really nice to have

Copy link
Owner

Choose a reason for hiding this comment

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

If there's no Yarn workspace in the project now, I'd consider adding it later, after this PR is merged, because now with e2e it makes sense to use it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok let's do it in a separate PR to setup yarn workspace + jest "project"

Copy link
Collaborator

Choose a reason for hiding this comment

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

The issue is that we have different behavior of the preset for a Angular v9 and v10 App, so we want to test both. If we use yarn workspaces and only install the dependencies once, we should not be able to install different Angular versions. Correct me if I'm wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok actually I think this will work with yarn workspaces, but we will see in the follow-up PR.

Copy link
Collaborator

@wtho wtho left a comment

Choose a reason for hiding this comment

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

Thumbs up from my side once the comments are resolved 👍

Just to keep track of what to do later:

  • Turn project into Yarn Workspace
  • Use glob to determine which projects are located in e2e instead of modifying paths.js each time
  • Move /example to e2e as test-app-v9
  • add test-app-v10 to CI

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Jul 13, 2020

made a push for:

  • Use execa when executing commands

  • Install dependencies and run tests for projects with yarn, only installing bundle with npm

The rest of the comments are for another PR which is related to yarn workspace and jest projects.

@ahnpnl ahnpnl merged commit 64dc7e4 into thymikee:master Jul 14, 2020
@ahnpnl ahnpnl deleted the e2e-setup branch July 14, 2020 15:59
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.

None yet

3 participants