npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jest_ci_4

v1.0.0

Published

A simple project setup to demonstrate CI automated testing using JEST tests on GitHub

Downloads

68

Readme

GitHub Actions and Jest Testing CI/CD Setup Project Overview This project demonstrates how to set up a Continuous Integration/Continuous Deployment (CI/CD) pipeline using GitHub Actions and Jest testing. By integrating these tools, I automated the process of running unit tests on my JavaScript project every time changes are pushed to my GitHub repository. This setup ensures that my code is always tested and provides feedback on the success or failure of my changes in real-time.

Why It Matters Automating testing with CI/CD tools like GitHub Actions improves the development workflow by:

Ensuring consistency: Every change gets tested automatically. Saving time: Reduces the need to manually run tests after every change. Preventing bugs: Automatically catches errors early in the development process. This setup is beneficial for developers aiming to maintain high code quality and reduce manual intervention in testing.

Steps to Set Up GitHub Actions and Jest Testing

  1. Install GitHub CLI Before starting with the project, make sure to install the GitHub CLI to interact with your repositories directly from the terminal.

Run the following command to check if GitHub CLI is installed: bash Copy code gh --version If not installed, follow the installation guide at cli.github.com. 2. Authenticate GitHub CLI Once the GitHub CLI is installed, authenticate it with your GitHub account by running:

bash Copy code gh auth login Follow the prompts to authenticate via your Personal Access Token (PAT).

  1. Create a New GitHub Repository Create a new GitHub repository to store your project code. You can also use an existing repository if you prefer.

bash Copy code gh repo create --public gh repo clone / cd 4. Set Up Your JavaScript Project In this project, I used Jest, a testing framework, to ensure that my code functions as expected. Here's how you can set it up:

Initialize the project with npm:

bash Copy code npm init -y Install Jest as a development dependency:

bash Copy code npm install jest --save-dev Create a test folder and add an example test:

bash Copy code mkdir tests touch tests/example.test.js Add a simple Jest test in tests/example.test.js:

javascript Copy code test('adds 1 + 2 to equal 3', () => { expect(1 + 2).toBe(3); }); Run the test locally:

bash Copy code npx jest 5. Commit and Push Your Code to GitHub Once Jest is set up and your test is working, commit the changes to your GitHub repository.

bash Copy code git add . git commit -m "Initial project setup" git push -u origin main 6. Set Up GitHub Actions Workflow To automate the testing process, set up a GitHub Actions workflow. Create the necessary folders and YAML file to define the workflow.

Create the workflow directory and YAML file:

bash Copy code mkdir -p .github/workflows touch .github/workflows/ci.yml Add the following content to ci.yml:

yaml Copy code name: Jest CI

on: push: branches: [main]

jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '16' - run: npm install - run: npm test Commit and push the workflow file to GitHub: bash Copy code git add .github/workflows/ci.yml git commit -m "Add CI workflow" git push 7. Test the Workflow To ensure that everything is working, make a small change to your project and push it to GitHub. The GitHub Actions workflow should trigger and run the tests.

bash Copy code echo "// Test change" >> index.js git add . git commit -m "Test workflow" git push Check the GitHub Actions tab to view the status of your tests.

  1. Document the Process Finally, update your README.md file with detailed instructions on setting up the GitHub CLI, configuring the GitHub Actions workflow, and running the tests. Include screenshots of the GitHub Actions logs and console output for test results.

Results By following these steps, I was able to successfully set up automated testing for my project. Now, every time I make a change and push it to GitHub, the tests are automatically run, providing me with real-time feedback on the success or failure of my code.

This process ensures that I catch errors early and maintain the integrity of my code. I've also included detailed instructions and screenshots to help you replicate this setup.

Challenges and Solutions One of the main challenges I faced was ensuring the YAML file was correctly formatted. YAML is sensitive to indentation, and a small mistake can cause the workflow to fail. After testing different configurations and reviewing documentation, I successfully got the tests running with the Jest testing framework.

Screenshots GitHub Actions Log ![GitHub Actions Log](Insert your screenshot here)

Console Output ![Console Output](Insert your screenshot here)

Call to Action Feel free to explore the full project on my GitHub repository. Clone the repository, set up the CI/CD workflow, and experiment with running Jest tests automatically whenever you make changes to the code.

You can find the project here.

Contributing Contributions are welcome! If you have suggestions or improvements for this setup, feel free to open an issue or submit a pull request.

License This project is open-source and available under the MIT License.