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

[legacy-framework] [#330] Fix new app command order #367

Closed
wants to merge 7 commits into from
Closed

[legacy-framework] [#330] Fix new app command order #367

wants to merge 7 commits into from

Conversation

peaonunes
Copy link
Collaborator

Type: bug fix

Closes: blitz-js/legacy-framework#506

What are the changes and their implications? ⚙️

  • Git init happens before any other step in AppGenerator.
  • Husky hooks will now correctly be applied when commiting files.

Checklist

  • Tests added for changes
  • Any added terminal logging uses packages/server/src/log.ts

Breaking change: no

Other information

I've took the opportunity to add tests as there were none before. I had to do some tricky mocks though, not super happy.

Locally when I run yarn test in the root folder in the project the cli tests fail. However, when running inside the cd packages/cli && yarn test everything is green. Does anyone know what is the issue?
I had to ignore the test hooks because they were not allowing me to push the code.

@peaonunes peaonunes requested a review from aem as a code owner April 30, 2020 11:45
} else {
console.error('Failed to run git add')
}
if (gitInitResult.status === 0) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Curious on the motivation behind not failing if the git commands fail. If we want to i am happy to make them throw error here as well as the other commands inside this generator.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not super set on failing if git init fails just because it's not a mandatory part of the setup process. I'll open an issue to discuss this more though, thanks for bringing it up!

await generator.run()
} catch (e) {
expect(e).toEqual(new Error('Failed to yarn install'))
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tried hard to make this work with toThrow, but seems to be a known issue.
jestjs/jest#1700

@@ -64,7 +68,7 @@ class AppGenerator extends Generator<AppGeneratorOptions> {

const result = spawn.sync(this.options.yarn ? 'yarn' : 'npm', ['install'], {stdio: 'inherit'})
if (result.status !== 0) {
throw new Error()
throw new Error(`Failed to ${this.options.yarn ? 'yarn' : 'npm'} install`)
}

console.log(chalk.hex(themeColor).bold('\nDependencies successfully installed.'))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Curious why we are using log helper and/or console.log|console.error. Should it be unified?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've been incrementally migrating to the @blitzjs/server/utils/log helper as I touch relelvant lines. We haven't touched the app generator meaningfully in a bit so I haven't had a chance to migrate these log lines. If you want to migrate these to use the main logging utility it would be a huge help!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done c31ba55

@aem
Copy link
Collaborator

aem commented Apr 30, 2020

Thanks so much for the PR! I hadn't noticed this, great find + fix!

Locally when I run yarn test in the root folder in the project the cli tests fail. However, when running inside the cd packages/cli && yarn test everything is green. Does anyone know what is the issue?

This is a known issue, the tests run in parallel in the prepush hook but there's a race condition there :( Since we reuqire a successful build to merge and the CI build runs the tests serially it's ok to ignore them locally, there's no chance it'll make it into the canary branch.

@@ -64,7 +68,7 @@ class AppGenerator extends Generator<AppGeneratorOptions> {

const result = spawn.sync(this.options.yarn ? 'yarn' : 'npm', ['install'], {stdio: 'inherit'})
if (result.status !== 0) {
throw new Error()
throw new Error(`Failed to ${this.options.yarn ? 'yarn' : 'npm'} install`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we now use the yarn/npm split in a few places, would it be possible to pull that logic out into a constant? It'll prevent any chance of us (most likely me 😬) messing it up in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done 77d4a5c

@@ -0,0 +1,237 @@
import * as fs from 'fs-extra'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you so much for adding some test scaffolding here! I think @dajinchu added an in-memory filesystem to Jest in the server package, maybe we could follow a similar pattern here so we could actually generate the app for real to make sure things work ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I focused on unit tests here so I tried to mock all the external integrations. I believe we may want to have a good amount of both unit and integration tests.
However, we could add those integrations tests in a different suit file to not conflict setup etc. What do you think of us having some sort of app.int.test.ts (I am bad at naming) or even a different folder cli/test/integration?
I am happy to add these as a new PR so we incrementally improve the quality of the tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah we used mock-fs which worked pretty well.

for (let command of commands) {
const result = spawn.sync(...command)
if (result.status !== 0) {
console.error(`Fialed to run command ${command[0]} with ${command[1].join(' ')} options.`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
console.error(`Fialed to run command ${command[0]} with ${command[1].join(' ')} options.`)
console.error(`Failed to run command ${command[0]} with ${command[1].join(' ')} options.`)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done 77d4a5c

@peaonunes
Copy link
Collaborator Author

New changes were added while this PR is being reviewed, I will take a time to rebase and fix the conflicts.

@flybayer
Copy link
Member

flybayer commented May 1, 2020

Thank you @peaonunes! I'll mark as draft — mark it as ready for review once it's updated.

@all-contributors add @peaonunes for code

@allcontributors
Copy link

@flybayer

I've put up a pull request to add @peaonunes! 🎉

@peaonunes peaonunes marked this pull request as ready for review May 1, 2020 09:17
@peaonunes
Copy link
Collaborator Author

Hey @flybayer thanks, I've updated now.
@aem this is ready for review again.

Unfortunately seems like a lot have changed from when I started adding tests and refactoring some calls. So I had to undo those. In order to avoid this happening again I've only made the change needed on this PR and added tests related to it. Happy on refactor again portions of this code in the future.

@flybayer
Copy link
Member

flybayer commented May 2, 2020

@peaonunes did you see your tests are failing?

@peaonunes
Copy link
Collaborator Author

Hey yeah. Trying to figure out why, its complaining about using wothBrand. My changes have nothing to do with the failing point, but at the same time the code is up to date with canary. I might start fresh from canary again in a few hours.

@peaonunes
Copy link
Collaborator Author

Hey, everyone.
Closing this PR , I sorted everything out in this new one #399.
Sorry for the mess.
cc: @aem @flybayer

@peaonunes peaonunes closed this May 2, 2020
@simondebbarma simondebbarma added kind/bug Something isn't working status/done and removed status/in-review labels May 2, 2020
@dillondotzip dillondotzip changed the title [#330] Fix new app command order [legacy-framework] [#330] Fix new app command order Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working status/done
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: husky hooks not being installed on blitz new
5 participants