0

Im using Playwright for integration tests. But when I run it through jenkinsfile I see this error unexpected token {. Error happens at npm run test-chrome. Does anyone know what could be the issue?

package.json

{
  "name": "playwright",
  "version": "1.0.0",
  "description": "Automation tests",
  "main": "index.js",
  "scripts": {
    "test": "npx playwright test --headed --workers=1",
    "test-firefox": "npx playwright test --headed --workers=1 --project=firefox",
    "test-chrome": "npx playwright test --headed --workers=1 --project=chromium",
    "test-headless": "npx playwright test",
    "test-chrome": "export URL=https://www.google.com && npx playwright test --workers=1 --project=chromium"
  },
  "author": "home_cei",
  "license": "ISC",
  "devDependencies": {
    "@playwright/test": "^1.19.0",
    "prettier": "^2.4.3",
    "allure-playwright": "^2.0.0-beta.15",
    "mocha": "^9.1.2"
  },
  "dependencies": {
    "chai": "^4.3.4",
    "playwright-core": "^1.19.0"
  }
}

jenkinsfile

pipeline {
agent {
    label 'cicd-build'
  }
  stages {
    stage('Install Playwright') {
      steps {
        sh 'npm install'
      }
    }
    stage('Test') {
      steps {
        sh 'npm run test-chrome'
      }
    }
   }
      post {
        success {
        publishHTML target: [
        reportDir: 'Report',
        reportFiles: 'index.html',
        reportName: 'Test_Results'
        ]
        }
      }
    }
Gaurav
  • 1,332
  • 11
  • 22

2 Answers2

1

"test-chrome" seems to be a duplicated key in the scripts section of your package.json. Maybe that's what's causing the issue.

Víctor
  • 533
  • 3
  • 7
0

This error was happening because I was using wrong node version <12. After changing my version, it works fine.

Gaurav
  • 1,332
  • 11
  • 22