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

New command - cavy init #9

Merged
merged 16 commits into from Apr 18, 2019
Merged

New command - cavy init #9

merged 16 commits into from Apr 18, 2019

Conversation

@AbigailMcP
Copy link
Collaborator

@AbigailMcP AbigailMcP commented Mar 22, 2019

Includes

  • A new command cavy init that creates an example index.test.js file and exampleSpec.js in a specs folder.
    • The command takes an additional extra argument for the name of the spec folder, just in case users have other tests that they keep in a specs folder. Fall back on specs if no argument is given.
  • Templates for these example files
  • Pulling out all test runner code into a separate file for readability now we have more commands

To think about

  • If someone already has an index.test.js file then at the moment I'm just ignoring that set up step (no overwrite). Happy to hear other people's opinions on what could happen.
  • Could get rid of the argument for spec directory thing and instead step people through extra set up steps if conflicts arise ('Enter a directory name..'). This is a good first pass though.

To do

  • Add instructions to the README once we're happy with functionality

To test

  • npm link this branch to test out locally in the Cavy Directory sample app
@AbigailMcP AbigailMcP requested a review from jalada Mar 22, 2019
@jalada
Copy link
Contributor

@jalada jalada commented Apr 1, 2019

(Related: #8)

Copy link
Contributor

@jalada jalada left a comment

Now we have three sub-commands, instead of two that are basically the same, how do you feel about swapping to Commander's git-style sub-commands? https://github.com/tj/commander.js#git-style-sub-commands?


// Create a exampleTest.js file in the specified folder in the route of the
// project.
mkdirSync(`./${folderName}`);

This comment has been minimized.

@jalada

jalada Apr 16, 2019
Contributor

  1. Can we sanitise this input?
  2. Do we need the ./? Does that break this on Windows?
» node cavy.js init foo/bar
cavy: Adding Cavy to your project...
fs.js:121
    throw err;
    ^

Error: ENOENT: no such file or directory, mkdir './foo/bar'

This comment has been minimized.

@jalada

jalada Apr 16, 2019
Contributor

As per below, perhaps disregard my point about ./.

This comment has been minimized.

@AbigailMcP

AbigailMcP Apr 17, 2019
Author Collaborator

Agreed, should test on Windows, a couple of people have raised issues that I think could be down to Windows environments. And if the GitHub dev survey is anything to go by...

This comment has been minimized.

@jalada

jalada Apr 17, 2019
Contributor

Oh now interesting, maybe I shouldn't have used the word sanitise. Because now if I did cavy init myproject/specs will I end up with a folder called myprojectspecs? I think it'd be better to return an error to avoid anything unexpected.

This comment has been minimized.

@AbigailMcP

AbigailMcP Apr 18, 2019
Author Collaborator

Agreed, @jalada - now exits if folder name invalid.

src/init.js Outdated
writeFileSync(`./${folderName}/exampleSpec.js`, specContent);

// Don't overwrite any index.test.js file that already exists.
if (DEFAULT_ENTRY_FILE) {

This comment has been minimized.

@jalada

jalada Apr 16, 2019
Contributor

This is always true; I think you mean to check the file exists?

This comment has been minimized.

@AbigailMcP

AbigailMcP Apr 17, 2019
Author Collaborator

Oops!

src/init.js Show resolved Hide resolved
templates/index.test.js Show resolved Hide resolved
templates/index.test.js Outdated Show resolved Hide resolved
templates/exampleSpec.js Show resolved Hide resolved
src/runTests.js Show resolved Hide resolved
@AbigailMcP
Copy link
Collaborator Author

@AbigailMcP AbigailMcP commented Apr 17, 2019

@jalada - this is ready for you to look at again.

@jalada
Copy link
Contributor

@jalada jalada commented Apr 17, 2019

Definitely time for something in the README!

@jalada
Copy link
Contributor

@jalada jalada commented Apr 18, 2019

:shipit:

@jalada
jalada approved these changes Apr 18, 2019
@AbigailMcP AbigailMcP merged commit 9cf3d88 into master Apr 18, 2019
@AbigailMcP AbigailMcP deleted the cavy-init branch Apr 18, 2019
@jalada jalada mentioned this pull request Apr 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.