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

chore(testing): add integration test for init command #29

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Nov 4, 2019

This PR adds some integration tests for the init command

Changes

Adds tests for the following:

  • the init command works without a flag
  • the init command works with a flag of a valid project
  • the init command displays an error when you pass an invalid flag
  • the init command installs eb-scripts and adds a script to the package.json

Screenshots

image

Checklist

  • tested locally
  • installed new dependencies
  • updated the docs
  • added a test

Fixes #19

@jsjoeio jsjoeio requested a review from a team November 4, 2019 18:59
@jsjoeio jsjoeio self-assigned this Nov 4, 2019
Copy link

@jeffreyzhen jeffreyzhen left a comment

Choose a reason for hiding this comment

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

Great work 🔥 🔥 just a few questions

afterEach(() => {
jest.resetModules();
});
describe("my thing", () => {

Choose a reason for hiding this comment

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

should probably use something more descriptive 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️ that's embarrassing

jest.mock("fs");
jest.spyOn(process, "cwd").mockImplementation(() => "/custom/path/to");

const { getTemplateLocation } = require("../utils/getTemplateLocation");

Choose a reason for hiding this comment

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

Why's this getting reimported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Great question. I asked the same thing (Alvin wrote the original test).

The reason for that is this: we're spying on process.cwd(), which is used inside the getTemplateLocation function's file. By reimporting it, within the it block after we've mocked the implementation for process.cwd, the mock works as expected and the test assertion passes.

If we remove that and use the "global" import for that file, process.cwd() does not use our mock. I found this out through trial and error, and from reading these relevant Jest issues:

I will add a comment to explain that (condensed of course). Great question!

}
});

it("expects to find a backup.json and package.json", async () => {

Choose a reason for hiding this comment

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

Should we be checking for yarn.lock to exist here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Jeffery, your eyes are impeccable - great catch - I'll add that in now

Copy link

@jeffreyzhen jeffreyzhen left a comment

Choose a reason for hiding this comment

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

:shipit:

@jsjoeio jsjoeio merged commit 4a6ce0e into jsjoeio/issue-20-generate-integration-test Nov 6, 2019
@jsjoeio
Copy link
Contributor Author

jsjoeio commented Nov 6, 2019

@all-contributors please add @jeffreyzhen for review

@allcontributors
Copy link
Contributor

@jsjoeio

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

@jsjoeio jsjoeio deleted the jsjoeio/issue-19-init-integration-test branch November 7, 2019 15:00
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.

2 participants