CREATING A DEFAULT PACKAGE.JSON FILE

To create a default package.json using information extracted from the current directory, use the npm init command with the –yes or -y flag

You can create package.json from the command prompt or directly from Visual Studio Code.

1. Open Visual Studio Code
2. Click on Terminal menu
3. Click ‘New Terminal’
4. You will see that Terminal is open at the bottom-most screen of Visual Studio Code
5. Run below command

npm init --yes

6. Default package.json file created will look something like

{
  "name": "protractor-jasmine-typescript",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "MIT"
}

UPDATING PACKAGE.JSON FILE

You can update the ‘description’ and ‘author’ as per your need manually or you can run below commands.

SETTING CONFIG OPTIONS FOR THE INIT COMMAND

# Set author email
npm set init.author.email "[email protected]"

# Set author name
npm set init.author.name "Code with MMAK"

# Update license
npm set init.license "MIT"

SAVING NPM DEPENDENCIES IN PACKAGE.JSON FILE

1. Run below commands one by one so that it gets saved in package.json file and later it will be easy for us to install all dependencies by giving one commend.

# Install Protractor
npm install --save protractor

# Install Jasmine
npm install --save jasmine

# Install Jasmine types
npm install --save-dev @types/jasmine

# Install Typescript
npm install --save typescript

2. If you run command npm install then it will install all the dependency in one go and it will save your time in typing an individual command when you are deploying code on another system.
Finally, you can update the package.json file as below

{
  "name": "protractor-jasmine-typescript",
  "version": "1.0.0",
  "description": "This is Test Automation framework designed using Protractor, Jasmine and TypeScript",
  "homepage": "https://github.com/codewithmmak/protractor-jasmine-typescript",
  "main": "conf.js",
  "dependencies": {
    "jasmine": "^3.3.0",
    "protractor": "^5.4.1",
    "typescript": "^3.1.6"
  },
  "devDependencies": {
    "@types/jasmine": "^3.3.0"
  },
  "scripts": {
    "pretest": "npm run tsc",
    "tsc": "tsc",
    "test": "protractor temp/conf.js"
  },
  "keywords": [
    "protractor",
    "jasmine",
    "typescript",
    "javascript",
    "angular",
    "angularjs",
    "vscode",
    "testing",
    "selenium",
    "webdriverJS",
    "automation testing"
  ],
  "author": "Code with MMAK",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/codewithmmak/protractor-jasmine-typescript.git"
  }
}

You are Done!!!

Leave a Comment