Skip to content

Instantly share code, notes, and snippets.

@abhijithvijayan
Last active June 26, 2022 16:11
Show Gist options
  • Save abhijithvijayan/47791037d85db5de397e1e6017a728ba to your computer and use it in GitHub Desktop.
Save abhijithvijayan/47791037d85db5de397e1e6017a728ba to your computer and use it in GitHub Desktop.
summary
  • JavaScript runs on browser in Browser's JavaScript engine(V8 in Chrome, Spidermonkey in firefox, etc)

  • Somebody ported V8 engine and made it installable in server. This is what is Node.js.

  • You can run JavaScript in node.js(instead of the browser)

  • Even servers can be written in node.js(with libraries like express.js)

  • With Node.js unlimited possibilities arose

  • Thats how Node.js Packages were born(now known as npm packages)

  • These are just some javascript files published into some registry(like a telephone registry but for js packages)

  • npmjs.com is a good package registry widely used

  • In node.js, then came the need to manage these packages(as people wanted to use packages written by other folks)

  • so package managers like npm(by npmjs.com) and yarn(by facebook) was born (// These tools are similar to Maven in Java)

  • npm CLI(when you install node.js, npm cli is also auto installed) uses a file called package.json (it is a JSON file) for managing dependencies

  • when you install a depedency(any random node.js package) npm cli updates it in package.json file

  • Now comes cypress

  • since cypress is another npm package, you can install with the npm cli

  • cypress runs on the browser and performs actions exactly like selenium

  • watch this to understand it in 100seconds https://www.youtube.com/watch?v=BQqzfHQkREo

installing nodejs on your machine

  • since nodejs has many versions, and at the time of writing you will be using a particular version of nodejs, you would probably need to use a different version of nodejs for a different project
  • this can be achieved using NVM
  • install using https://github.com/coreybutler/nvm-windows/releases/download/1.1.9/nvm-setup.exe
  • cypress requires 12 or 14 or above version of nodejs
  • once NVM is installed, you can run
      nvm install 14
    
  • that will install nodejs 14 on windows

installing cypress

since nodejs is installed, npm(the package manager tool) wil be auto installed

  • to install cypress
  • create a folder(say test-cypress)
  • run
      npm install cypress --save-dev
    
  • the --save-dev argument means telling npm to install the package as a dev dependency(rather than a dependeny). dependencies are the packages you want to use in the production code of the app itself since testing is not part of the production code, the package should be installed as a dev dependency
  • the install command will create a folder called node_modules. this is where all the packages are installed to.
  • to run cypress you need to use the cypress binary, for that you can make use of npm cli
  • if you write a key value pair in package.json under "scripts" key, you can use npm cli to run the script
    • // this is package.json
    {
           "name": "hello-there",
           "scripts": {
               "cypress:open": "cypress open"
           }
    }
    
  • this will let you run npm run cypress:open
  • this will launch cypress for you
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment