Unexpected token `{` error in jenkinsfile - jenkins

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'
]
}
}
}

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

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

Related

how to integrate ngx-logger into playwright

I'm new in TS & angular. Now I have a legacy playwright project, which I'd like to use ngx-logger for logging.
According to many ngx-logger tutorials, I know there might be 3 steps to integrate:
install ngx-logger
npm install --save ngx-logger
import the library in the root module, i.e., app.module.ts
import { LoggerModule, NgxLoggerLevel } from 'ngx-logger';
import LoggerModule.forRoot in your application module. This is where we can configure the logger:
#NgModule({
imports: [
BrowserModule,
HttpClientModule,
LoggerModule.forRoot({
serverLoggingUrl: 'http://localhost:4201/', // Replace with YOUR API
level: NgxLoggerLevel.TRACE,
serverLogLevel: NgxLoggerLevel.ERROR,
disableConsoleLogging: false
})
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
So finally, we can start logging anywhere in the application:
export class AppComponent {
constructor(private logger: NGXLogger) {
this.logger.debug("Debug message");
this.logger.info("Info message");
this.logger.log("Default log message");
this.logger.warn("Warning message");
this.logger.error("Error message");
}
}
However, I'm stuck in step 2&3, because I don't know where to setup these in a playwright project.
In my playwright project, I only have config files like:
~/playwright.config.ts
~/src/config/launch.config.ts
~/src/config/testrunner.config.ts
none of them contains #NgModule I could inject the codes.
Can anyone give me some hints with how to proceed?
Thank in advance.
package.json
{
"name": "portal-test",
"version": "0.0.0",
"private": true,
"description": "Portal Test Automation Suite",
"homepage": "./",
"dependencies": {
"dotenv": "^16.0.0",
"eml-parser": "^1.0.6",
"expect-playwright": "^0.7.1",
"moment": "^2.29.4",
"ngx-logger": "^5.0.11",
"npm": "^7.19.1",
"path": "^0.12.7",
"pdf.js-extract": "^0.1.5",
"pdfreader": "^1.2.11",
"playwright-core": "^1.15.2",
"request-promise": "^4.2.6",
"ts-node": "^10.3.0",
"typescript": "^4.4.3",
"yarn": "^1.22.10"
},
"scripts": {
"compile": "npx tsc --incremental -p tsconfig.json",
"test": "CI_TEST_ENV=uat npx playwright test --config=src/config/testrunner.config.ts --headed",
"test-local": "CI_TEST_ENV=local npx playwright test --config=src/config/testrunner.config.ts --headed",
"test-local-headless": "CI_TEST_ENV=local npx playwright test --config=src/config/testrunner.config.ts",
"test-dev": "CI_TEST_ENV=dev npx playwright test --config=src/config/testrunner.config.ts --headed",
"test-uat": "CI_TEST_ENV=uat npx playwright test --config=src/config/testrunner.config.ts --headed"
},
"devDependencies": {
"#playwright/test": "^1.28.1",
"playwright": "^1.15.2"
},
"extends": []
}

How to upload nodejs/react Applications Artifacts to private repository by jenkins windows server(Onprem)

please help me with
what are commands we write in jenkins file to upload artifacts to private repository by jenkins windows server(batch commands)
how to deploy the App to remote linux server from jenkins windows server
i have written this code but its showing error
pipeline {
agent any
}
/*
environment{
CI= 'true'
}
*/
stages {
stage('Build') {
steps {
/*
//bat '"C:\\Program Files\\nodejs\\"npm ci'
bat '"C:\\Program Files\\nodejs\\"npm config set registry http://registry.npmjs.org/'
bat '"C:\\Program Files\\nodejs\\"npm config set strict-ssl false'
bat '"C:\\Program Files\\nodejs\\"npm install'
*/
bat 'npm install'
}
}
/*
stage('test') {
steps {
//bat '"C:\\Program Files\\nodejs\\"npm config set registry http://registry.npmjs.org/'
//bat '"C:\\Program Files\\nodejs\\"npm config set strict-ssl false'
bat '"C:\\Program Files\\nodejs\\"npm test'
}
}
*/
stage('Upload to Artifactory') {
steps{
def server = Artifactory.server "ci-artifacts.devops.fds.com"
def uploadSpec = """{
"files": [
{
"pattern": "target/*.jar",
"target": "macys-release-local/com/macys/mas/application name/"
}
]
}"""
server.upload(uploadSpec)
}
}
stage('deploy') {
steps {
bat 'npm run build'
dir('properties'){
sshPublisher(publishers:
[
sshPublisherDesc(configName: 'linux server host name',
transfers: [sshTransfer(excludes: '',
execCommand: '/www/apps/mas/dev/service.sh',
execTimeout: 120000,
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '/mas/dev/',
remoteDirectorySDF: false, removePrefix: '',
sourceFiles: '**/*application-dev.properties')],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: false)
]
)
}
}
}
}
}

How to add a unique constraint on type field with Graphql and Neo4j?

I'm making a GRANDStack application so I'm using neo4j and graphql,
I have this type in my schema.graphql file :
type User {
userId: ID!
username: String! #unique
mail: String! #unique
password: String! #private
}
But I'm still able to create multiple accounts with the same
I know this is possible when I look at neo4j documentation here :
https://neo4j.com/docs/graphql-manual/current/directives/#_unique
but the only I found for now is to manually do something like this in my database :
CREATE CONSTRAINT ON (u:User) ASSERT u.mail IS UNIQUE;
But it's not a good idea, I want this to be automatic
I think my package.json is also up to date :
{
"name": "grand-stack-starter-api",
"version": "0.0.1",
"description": "API app for GRANDstack",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "./node_modules/.bin/nodemon --watch src --ext js,graphql --exec babel-node src/index.js",
"build": "babel src --out-dir build && shx cp .env build 2>/dev/null || : && shx cp src/schema.graphql build",
"now-build": "babel src --out-dir build && shx cp src/schema.graphql build",
"start": "npm run build && node build/index.js",
"seedDb": "./node_modules/.bin/babel-node src/seed/seed-db.js"
},
"author": "William Lyon",
"license": "MIT",
"dependencies": {
"#apollo/client": "^3.2.5",
"#neo4j/graphql": "^2.4.0",
"apollo-server": "^3.5.0",
"apollo-server-lambda": "^2.19.0",
"csv-parse": "^4.10.1",
"dotenv": "^7.0.0",
"graphql": "^16.0.1",
"neo4j-driver": "^4.4.0",
"node-fetch": "^2.6.0",
"react": "^16.13.1"
},
"devDependencies": {
"#babel/cli": "^7.8.4",
"#babel/core": "^7.9.0",
"#babel/node": "^7.8.7",
"#babel/plugin-proposal-class-properties": "^7.8.3",
"#babel/plugin-transform-runtime": "^7.9.0",
"#babel/preset-env": "^7.9.0",
"#babel/preset-react": "^7.9.4",
"#babel/preset-typescript": "^7.9.0",
"#babel/runtime-corejs3": "^7.9.2",
"babel-plugin-auto-import": "^1.0.5",
"babel-plugin-module-resolver": "^4.0.0",
"cross-env": "^7.0.2",
"nodemon": "^1.19.1",
"shx": "^0.3.2"
}
}
So, turned out the documentation is not updated
To fix this I first had to follow this :
https://neo4j.com/docs/graphql-manual/current/type-definitions/constraints/#type-definitions-constraints-unique
the solution would be to add this which is wrong
await neoSchema.assertConstraints({ options: { create: true }});
I talked with someone working at neo4j in their discord and the right function one :
await neoSchema.assertIndexesAndConstraints({ options: { create: true }});
If like me you can't do await since your code is not in a function you can do something like this with .then :
const neoSchema = new Neo4jGraphQL({
...
})
neoSchema
.assertIndexesAndConstraints({ options: { create: true } })
.then(() => {
const server = new ApolloServer({
...
app.listen({ host, port, path }, () => {
console.log(`GraphQL server ready at http://${host}:${port}${path}`)
})
})

Test an .js.erb file with Rails + Webpacker + Jest

I have a Rails 5 app which uses webpacker, with a file app/javascript/packs/components/module_one.js which I'm trying to test with Jest. This file contains an import to an .js.erb file as follows:
// app/javascript/packs/components/module_one.js
import ModuleTwo from './module_two.js.erb'
// ...
module_two.js.erb contains the following:
// app/javascript/packs/components/module_two.js.erb
import ModuleOne from './module_one'
// ...
While running webpack-dev-server everything works as expected, but when I try to run yarn test, it complains with the following error:
FAIL app/javascript/test/module_one.test.js
● Test suite failed to run
/path/to/module_two.js.erb:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import ModuleOne from './module_one'
^^^^^^
SyntaxError: Unexpected token import
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:306:17)
at Object.<anonymous> (app/javascript/packs/components/module_one.js:1:745)
at Object.<anonymous> (app/javascript/test/module_one.test.js:1:124)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.545s
Ran all test suites.
error Command failed with exit code 1.
So it seems like the module_two.js.erb file is not being transformed properly from ES6, because when I remove the first line of module_one.js, it doesn't complain anymore.
Here is my current setup:
// .babelrc
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
}]
],
"plugins": [
"syntax-dynamic-import",
["transform-class-properties", { "spec": true }]
],
"env": {
"test": {
"plugins": ["transform-es2015-modules-commonjs"]
}
}
}
// package.json
{
// ...
"devDependencies": {
"babel-jest": "^21.0.2",
"jest": "^21.0.2",
"regenerator-runtime": "^0.11.0",
"webpack-dev-server": "^2.7.1"
},
"scripts": {
"test": "jest"
},
"jest": {
"roots": [
"<rootDir>/app/javascript/test"
],
"moduleDirectories": [
"<rootDir>/node_modules"
],
"moduleFileExtensions": [
"js",
"jsx",
"erb"
],
"transform": {
"^.+\\.jsx?$": "babel-jest",
"ˆ.+\\.jsx?.erb": "rails-erb-loader"
}
}
}
In case someone else bumps into this.
Your .babelrc seems to be missing "es2015" preset.
Here is well explained about this and other issues configuring JS testing with Rails + Webpacker.

How to require native node module from electron? Getting error with ref and ffi module

when i require "ref" module in my js code and run via node, I get the desired output.
But when i run the same js code via electron by providing necessary changes in package.json, it says "Could not locate the binding file.."
Here is my package.json file
{
"name": "firstapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron .",
"package": "electron-packager . myapp --platform=win32 --arch=ia32 --version=1.0.0 --overwrite"
},
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^1.4.8",
"electron-prebuilt": "^1.4.8",
"electron-rebuild": "^1.4.0",
"ffi": "^2.2.0",
"node-gyp": "^3.4.0",
"reach": "^1.0.0",
"ref": "^1.3.3"
},
"dependencies": {
"ffi": "^2.2.0",
"ref": "^1.3.3"
}
}
And here is my index.js file
const electron = require('electron');
const ref = require('ref');
const app = electron.app
const BrowserWindow = electron.BrowserWindow
let mainWindow
const createWindow = () => {
mainWindow = new BrowserWindow({ name: "ishwar", width: 800, height: 600, visible: true, toolbar: false });
mainWindow.loadURL(__dirname + '/index.html');
mainWindow.webContents.openDevTools()
mainWindow.on('closed', () => {
mainWindow = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
app.quit()
})
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})
When i start the project "npm start" without requiring "ref" I get no error. But when i do with ref, it throws error.
P.S. The main requirement is for "ffi" module, and I have done necessary changes needed to run "ffi". "ffi" intern requires "ref", such that when i run code which includes ref via node, it works perfectly..
Somehow i managed to find the solution for this one. After I installed these package using npm command, I was getting the binding error. As a solution, I needed to run "electron-rebuild" command for that new package externally. Download electron-rebuild module with npm and then run "electorn-rebuild -f -w ffi" and "electron-rebuild -f -w ref". That's all, its working now.

Resources