The setup session is very simple. However, I still have problem with install nvm :
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 -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
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.
nvm install node # the lastest version
nvm use node
guix package install node
node --version
a = "hello"
console.log(a)
run it in shell:
node test.js
This is everything for setting up node.js.
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.
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
Jest is the test framework to run our tests.
npm i jest
npm i -g jest # install globally
cd your_project_folder
npm init -y # initialize your project
Create a file for your solutions in your project folder. Let’s call it preflight.js.
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.
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')
These examples will be your tests and the following instructions will show you how to create tests and run them.
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
Add this line to preflight.js. As you solve more exercises, just keep this line at the end.
module.exports = allFuns
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")
})
})
Run the test with
jest preflight.test.js
node_modules/jest/bin/jest.js preflight.test.js # run from the library
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
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).
npm install --save request # install request locally for current project
npm install -g request # install request globally for each project