Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Refactor create-project to support testing the cli and middleware integration #488

Merged
merged 5 commits into from Dec 1, 2017
Merged

Refactor create-project to support testing the cli and middleware integration #488

merged 5 commits into from Dec 1, 2017

Conversation

eliperelman
Copy link
Member

Fixes #472. The tests take a little while, but it runs pretty well!

We attempt to run each preset, along with tests, and linting in the project and make sure they all pass for each project type. There's more that can be done here as well, such as making sure the package.json and .neutrinorc.js have the right contents.

@eliperelman eliperelman requested a review from a team November 23, 2017 18:04
Copy link
Member

@helfi92 helfi92 left a comment

Choose a reason for hiding this comment

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

Lovely! See comments regarding a couple of concerns. Otherwise, I'm really happy with the changes :)

}

if (this.data.linter) {
this.spawnCommandSync('neutrino', ['lint', '--fix'], { stdio: 'ignore' });
this.spawnCommandSync('neutrino', ['lint', '--fix'], { stdio: this.options.stdio, cwd: this.options.directory });
Copy link
Member

Choose a reason for hiding this comment

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

Would this output to the user when linting fails to fix? I think we shouldn't output any linting errors when we're in the installing phase.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is normally set to ignore, but during testing we want to see the output so it fails the test.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. What you said makes a lot of sense :)

this.log(`\n${chalk.green('Success!')} Created ${chalk.cyan(this.options.directory)} at ${chalk.yellow(process.cwd())}`);
this.log(`To get started, change your current working directory to: ${chalk.cyan(this.options.directory)}`);
this.log(`\n${chalk.green('Hooray, I successfully created your project!')}`);
this.log(`To get started, change your current working directory to:\n ${chalk.cyan(this.options.directory)}`);
Copy link
Member

Choose a reason for hiding this comment

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

"Hooray" :)

If the user is installing an app, what do you think if we log something like:

"To start your application, run yarn start" (or npm start if isYarn evaluates to false)

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it.

@@ -6,18 +6,15 @@ module.exports = () => [
choices: [
{
name: 'A web or Node.js application',
value: 'application',
checked: true
Copy link
Member

Choose a reason for hiding this comment

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

Would omitting the checked property default to having the first option checked? Not having at least one checked property would maybe require the user to press the keyboard down arrow before seeing one of the options selected.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this causes the first option to be selected. I think checked only works for checkable items, which these weren't.

@@ -1,25 +1,30 @@
const projects = {
'@neutrinojs/airbnb': {
type: 'linting',
Copy link
Member

Choose a reason for hiding this comment

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

What do you think if we store the types in a constant.

const TYPES = {
  LINTING: 'linting',
  PROJECT: 'project',
  TESTING: 'testing'
}

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@eliperelman
Copy link
Member Author

Full output image:

terminal output

@eliperelman
Copy link
Member Author

(Using the test env makes it use links for local deps instead of npm/yarn lookups.)

@helfi92
Copy link
Member

helfi92 commented Nov 27, 2017

Looks great! I assume the directory name you chose when taking the screenshot was db408292ac69f703. Just making sure 😅

@eliperelman
Copy link
Member Author

Haha yeah, I use a random directory every time. I use an alias to generate the directory:

alias random="node -e \"process.stdout.write(require('crypto').randomBytes(8).toString('hex'))"\"

@helfi92
Copy link
Member

helfi92 commented Nov 28, 2017

I love it! Thanks a lot for sharing 🙏 Added it to my list of aliases!

@eliperelman
Copy link
Member Author

Revised PR again, and will also need to update when @helfi92's extensions PR lands. I've done some work to the Vue preset to make it pass the tests, and have also made some changes to the tests themselves to get them to run better in parallel, making it faster.

@eliperelman eliperelman merged commit cd5fa51 into neutrinojs:master Dec 1, 2017
@edmorley
Copy link
Member

edmorley commented Dec 4, 2017

Included in this PR were some additions of:
const NEUTRINO_MODULES = join(__dirname, '../../node_modules');

I'm not really sure what that path if trying to reference? It seems like it might not be taking into account hoisting properly. It might be worth adding some comments alongside them?

@eliperelman
Copy link
Member Author

When running create-project from the tests, packages are linked instead of installed, since we don't want non-existent versions installed in the repo, but rather to test the current local versions of the packages. But when linking the vue package, the vue-loader had a lot of trouble trying to find its deps because of hoisting combined with a different linked structure, and adding NEUTRINO_MODULES fixed that.

@eliperelman
Copy link
Member Author

Either way, adding more explanatory in comments would be a good thing, and I'll start doing that.

@edmorley
Copy link
Member

edmorley commented Dec 4, 2017

Ah ok. I'm concerned that it will now mean projects using Neutrino starting looking for node_modules outside their project directory though? (Given hoisting will mean the directory is close to the project root already, even before the ../../)

@eliperelman
Copy link
Member Author

eliperelman commented Dec 4, 2017

@edmorley oooooooo great point. 🤔

Maybe we should instead add this only when working in the monorepo, maybe with an environment variable or Neutrino option?

@jaridmargolin
Copy link
Contributor

Is this specific to working with lerna or monorepos in general? I wonder if you can just sniff for lerna.json.

@eliperelman
Copy link
Member Author

@jaridmargolin you make an excellent point, and one which highlights a greater need for #516. If the package.json gets injected into options and is accessible by middleware, it then becomes super easy to determine if this is the monorepo, because we can just look at the name!

.add(MODULES)
.when(neutrino.options.packageJson.name === 'neutrino-dev', (modules) => {
  modules.add(NEUTRINO_MODULES);
})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants