Skip to content

Latest commit

 

History

History
105 lines (74 loc) · 2.2 KB

File metadata and controls

105 lines (74 loc) · 2.2 KB

1. Environment

  • Node v25.9.0
  • PNPM 10.30.3

2. Reference

3. JEST install for Unit Test

3-1. Build a Node.js project

$ pnpm init

You will be asked some questions, but just keep tapping "Enter" key.

3-2. Install required packages

$ pnpm install --save-dev jest babel-jest babel-core @babel/core @babel/preset-env

3-3. Install a plugin with babel to convert JEST to CommonJS

$ pnpm install --save-dev jest babel-jest

3-4. Run a unittest

To execute all unit tests, run npx jest.

$ pnpm jest
 PASS  __tests__/hello.test.js (24.047 s)
  ✓ Hello (3 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        48.781 s
Ran all test suites.

To execute a unit test, run npx jest ./__test__/{filename}_test.js.

$ npx jest ./basic/__tests__/hello_test.js
PASS  basic/__tests__/hello_test.js (15.283 s)
 ✓ hello (2 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        38.076 s
Ran all test suites matching /basic\/__tests__\/hello_test.js/i.

4. Ajax

To setup a local server, run the following command and access http://localhost:3000. - To use another port, assign one with --port [port] option.

$ cd ajax
$ npx @js-primer/local-server

5. Node.js

5-1. Setup local server

To setup a local server, run the following command and access http://localhost:3000. - To use another port, assign one with --port [port] option.

$ cd nodejs
$ npx @js-primer/local-server

5-2. Unit test

To execute unit tests, run the following command.

$ npm test

6. Todo App

6-1. Setup local server

To setup a local server, run the following command and access http://localhost:3000. - To use another port, assign one with --port [port] option.

$ cd todo_app
$ npx @js-primer/local-server