Skip to content

[Beginner] Create a Project

loripam edited this page Dec 21, 2021 · 6 revisions

Steps

  1. Open a terminal. cd into a directory/folder wherein you'd like to keep your projects and define NAME.
cd $TUT
NAME=sample

✔️ In this case, sample will be our directory name.

step 1


  1. Initiate project in the directory.
mkdir $NAME
cd $NAME
npm init -y
npm init ava
npm i -D  typescript ts-node
mkdir src
mkdir test

✔️ This creates the directory sample and moves into it. Then it initializes the node package manager, sets up AVA, and the language Typescript. Lastly, it creates two empty directories src and test for all of our code.

step 2


  1. Once done, open up Visual Studio Code.
code .

✔️ This will launch VS Code with the sample file as defined in Step 1.

step 3 a

step 3 b


  1. Add test runner config (AVA settings in package.json). You can also simply type in ava which will automatically show an option to fill in the snippets you need if you already have ava-recipes installed.
"ava": {
 "files": [
 "test/**/*.test.ts"
 ],
 "extensions": [
 "ts"
 ],
 "require": [
 "ts-node/register"
 ]
},

✔️ Go to extensions on VS Code and look for ava-recipes and ava-launch then install them. The former will allow you to easily add snippets by typing the keywords. It automatically fills in the code that you need. The latter is for debugging and running single AVA tests easily using multiple npm scripts. You will need it later.

step4b


  1. Open a bash terminal within VS Code to add the language config files.
TS_CONFIG=https://raw.githubusercontent.com/YizYah/testingWebinar/main/tsconfig.json
wget $TS_CONFIG -O tsconfig.json

INT_CONFIG=https://raw.githubusercontent.com/YizYah/testingWebinar/main/int-tests.config.cjs
wget $INT_CONFIG -O int-tests.config.cjs

GIT_IGNORE=https://raw.githubusercontent.com/YizYah/testingWebinar/main/.gitignore
wget $GIT_IGNORE -O .gitignore

✔️ The following files will show up: tsconfig.json .gitignore int-tests.config.cjs

Notes

  • Prerequisite: node should be installed
Clone this wiki locally