Giter Club home page Giter Club logo

advent-of-code-2023's Introduction

Advent of Code 2023 - TDD Javascript

Advent of Code 2023 is a yearly event where you solve a series of programming puzzles. This is the repo where I will be storing my solutions.

The magic template this repo is based on can be found here.

Prerequisites

Getting Started with the template

Make sure to build the project and pull down package dependencies by running yarn under the root of the Template.

This Template is separated into two folders src and tests. src will be for any features you create and tests is where you'll be testing against them. This isn't set up to be a web or mobile project, but it will mimic a similar project structure.

The tests folder is separated even further. It has different kinds of tests grouped together. Only unit type tests are there at the moment but e2e or integration tests can be added as well. Notice how the tests are under unit/features. For organization, these tests should match the folder structure as they do under src.

This Template is already configured to work with both jest and vitest so feel free to pick your favorite and start testing.

Creating and Testing a Simple "Hello World" Program with Jest

  1. Create a New Feature File:

    • First, create a new JavaScript file in the src folder. For example, let's create a simple "Hello World" program.
    • Run the following command in your terminal to create the file:
      touch src/helloWorld.js
  2. Write the "Hello World" Code:

    • Open src/helloWorld.js in your editor and add the following code:

      function helloWorld() {
        return "Hello World";
      }
      
      module.exports = helloWorld;
  3. Create a Test File for the Feature:

    • Next, create a test file in the tests/unit folder.
    • Ensure the directory exists and create the test file with these commands:
      mkdir -p tests/unit
      touch tests/unit/helloWorld.test.js
  4. Write the Test for "Hello World":

    • Open tests/unit/helloWorld.test.js in your editor and add the following test code:

      const helloWorld = require("../../src/helloWorld");
      
      test("says hello", () => {
        expect(helloWorld()).toBe("Hello World");
      });
  5. Run the Tests:

    • To run the tests, use the Jest testing framework with the command yarn jest.
    • This command will run all test files in your project, including the new test for your "Hello World" program.
  6. Run the "Hello World" Program:

    • Optionally, you can run the "Hello World" program directly using Node.js.
    • Run node src/helloWorld.js in the terminal. You might need to modify the helloWorld.js file to log the output if you want to see it in the console.

Available Scripts

In the project directory, you can run:

yarn jest

Runs all the jest tests.

yarn jest:unit

Runs all jest tests under the unit folder.

yarn vitest

Runs all the vitest tests.

yarn vitest:unit

Runs all the vitests tests under the unit folder.

yarn test:all

Runs all jest and vitest tests.

yarn format

  • Format all the files in the project using prettier
  • Targets all files, except those in noted in the .prettierignore file
  • Applies the formatting rules in the .prettierrc file

yarn lint

  • Lints all the files in the project using ESLint
  • It targets all files, except those in noted in the .eslintignore file
  • Applies the linting rules in the .eslintrc file
  • Includes a caching mechanism to speed up subsequent lint runs
    • Stores the cache in the ./node_modules/.cache/eslint directory.

advent-of-code-2023's People

Contributors

nlewis84 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.