Skip to content

Latest commit

 

History

History
193 lines (176 loc) · 5.29 KB

setup.org

File metadata and controls

193 lines (176 loc) · 5.29 KB

install nvm - node version manager

The setup session is very simple. However, I still have problem with install nvm :

curl

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

@hwong0305 suggested that I should try

curl -o- http://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

I did not try because I started ‘git installation’.

wget

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

git

cd
git clone https://github.com/nvm-sh/nvm.git .nvm
cd ~/.nvm
git checkout v0.35.3
. nvm.sh
command -v nvm # should output nvm

It works.

install node

using nvm

nvm install node # the lastest version
nvm use node

guix

guix package install node
node --version

run test.js

a = "hello"
console.log(a)

run it in shell:

node test.js

This is everything for setting up node.js.

install c0d3

From the page, you may see the message: “Please update your CLI client by opening your terminal and running the command: npm i -g c0d3” It means you need install c0d3, just do

nvm use node
npm -v
npm i -g c0d3 # failed in guix - issue 2

The CLI for c0d3 will be added.

setup curriculum

git clone https://github.com/garageScript/curriculum
cd curriculum
npm install
git checkout master
git checkout -b p1 # create new branch for problem 1
git merge master
# edit solution for problem 1: js0/1.js
npm run test
git add js0/1.js
git commit -m "solve problem 1"
c0d3 login
c0d3 submit
git checkout master
git merge p1
...
git checkout p1
git merge master

setup jest

Jest is the test framework to run our tests.

install jest

npm i jest
npm i -g jest # install globally
cd your_project_folder
npm init -y # initialize your project

create solution file

Create a file for your solutions in your project folder. Let’s call it preflight.js.

create a test file

Create a file for the tests in your project folder. Call it preflight.test.js. The word test in the filename is important; Jest will only run files with test in the filename.

link solution file and test file

First tell your test file to include the file that will have your solutions:

// fn will be an object with all your preflight solutions
const fn = require('./preflight.js')

example using jest

These examples will be your tests and the following instructions will show you how to create tests and run them.

step 1

In the preflight.js file, set up the object that will be exported to the test file and write your solution. For now, you just need to know that allFuns is an object.

const allFuns = {}

const removeCharX = ( ... ) => {
  // Your code goes here
}

allFuns.removeCharX = removeCharX // You need this line for every function
                                  // you write

step 2

Add this line to preflight.js. As you solve more exercises, just keep this line at the end.

module.exports = allFuns

step 3

Open the Tests toggle and paste the code into your preflight.test.js file.

describe('removeCharX function', () => {
    it('should remove the first character', () => {
        const str = "We're in the endgame now."
        const result = fn.removeCharX(str, 0)
        expect(result).toEqual("e're in the endgame now.")
    })
    it('return the original string', () => {
        const str = "a"
        const result = fn.removeCharX(str, 3)
        expect(result).toEqual("a")
    })
    it('return the original string', () => {
        const str = "abc"
        const result = fn.removeCharX(str, -3)
        expect(result).toEqual("abc")
    })
})

step 4

Run the test with

jest preflight.test.js
node_modules/jest/bin/jest.js preflight.test.js # run from the library

step 5

To have your tests automatically re-run as you edit the code or add new tests, run jest with the –watch option in one terminal and leave it running. As you change your code in your editor your tests will run automatically. Press q to exit when you’re done.

jest --watch preflight.test.js

summary

For each new exercise, click the Tests toggle and add the tests to your preflight.test.js file. Then add your solution to the preflight.js file and re-run the tests (or leave them running with –watch).

setup request

npm install --save request  # install request locally for current project
npm install -g request # install request globally for each project