Skip to content

Commit

Permalink
feat(2683): nodejs upgrade (#39)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Node 18 upgrade && eslint upgrade
  • Loading branch information
klu909 authored Dec 15, 2022
1 parent f748930 commit 2fa7f32
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 87 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const Executor = require('screwdriver-executor-base');
const path = require('path');
const jenkins = require('jenkins');
const Jenkins = require('jenkins');
const xmlescape = require('xml-escape');
const tinytim = require('tinytim');
const Breaker = require('circuit-fuses').breaker;
Expand Down Expand Up @@ -260,7 +260,7 @@ class JenkinsExecutor extends Executor {

// need to pass port number in the future
this[baseUrl] = `http://${this.username}:${this[password]}@${this.host}:${this.port}`;
this.jenkinsClient = jenkins({
this.jenkinsClient = new Jenkins({
baseUrl: this[baseUrl],
crumbIssuer: true
});
Expand Down
36 changes: 16 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"name": "screwdriver-executor-jenkins",
"version": "5.0.0",
"version": "6.0.0",
"description": "Jenkins Executor plugin for Screwdriver",
"main": "index.js",
"scripts": {
"pretest": "eslint .",
"test": "nyc --report-dir ./artifacts/coverage --reporter=lcov mocha --reporter mocha-multi-reporters --reporter-options configFile=./mocha.config.json --recursive --timeout 4000 --retries 1 --exit --allow-uncaught true --color true",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
"test": "nyc --report-dir ./artifacts/coverage --reporter=lcov mocha --reporter mocha-multi-reporters --reporter-options configFile=./mocha.config.json --recursive --timeout 4000 --retries 1 --exit --allow-uncaught true --color true"
},
"repository": {
"type": "git",
"url": "git@github.com:screwdriver-cd/executor-jenkins.git"
"url": "git+https://github.com/screwdriver-cd/executor-jenkins.git"
},
"homepage": "https://github.com/screwdriver-cd/executor-jenkins",
"bugs": "https://github.com/screwdriver-cd/executor-jenkins/issues",
"bugs": "https://github.com/screwdriver-cd/screwdriver/issues",
"keywords": [
"screwdriver",
"yahoo"
Expand All @@ -33,28 +32,25 @@
"Tiffany Kyi <[email protected]>"
],
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^7.7.0",
"eslint-config-screwdriver": "^5.0.4",
"mocha": "^8.2.1",
"chai": "^4.3.7",
"eslint": "^8.28.0",
"eslint-config-screwdriver": "^7.0.0",
"mocha": "^10.1.0",
"mocha-multi-reporters": "^1.5.1",
"mocha-sonarqube-reporter": "^1.0.2",
"nyc": "^15.0.0",
"mockery": "^2.0.0",
"sinon": "^9.0.3"
"nyc": "^15.1.0",
"mockery": "^2.1.0",
"sinon": "^15.0.0"
},
"dependencies": {
"@hapi/hoek": "^9.0.4",
"circuit-fuses": "^4.0.4",
"jenkins": "^0.28.0",
"screwdriver-executor-base": "^8.0.0",
"@hapi/hoek": "^10.0.1",
"circuit-fuses": "^5.0.0",
"jenkins": "^1.0.1",
"screwdriver-executor-base": "^9.0.0",
"tinytim": "^0.1.1",
"xml-escape": "^1.1.0"
},
"release": {
"debug": false,
"verifyConditions": {
"path": "./node_modules/semantic-release/src/lib/plugin-noop.js"
}
"debug": false
}
}
2 changes: 1 addition & 1 deletion screwdriver.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
shared:
image: node:12
image: node:18

jobs:
main:
Expand Down
143 changes: 79 additions & 64 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ describe('index', () => {
let getOpts;
let stopOpts;
let destroyOpts;
const apiUri = 'https://api.sd.cd';

beforeEach(() => {
getOpts = {
Expand All @@ -365,49 +366,44 @@ describe('index', () => {
});

it('return null when the build is successfully stopped', done => {
breakerMock.runCommand
.withArgs(getOpts)
.onCall(0)
.resolves(fakeJobInfo);
breakerMock.runCommand
.withArgs(getOpts)
.onCall(1)
.resolves(fakeCompletedJobInfo);
breakerMock.runCommand.withArgs(getOpts).onCall(0).resolves(fakeJobInfo);
breakerMock.runCommand.withArgs(getOpts).onCall(1).resolves(fakeCompletedJobInfo);
breakerMock.runCommand.withArgs(stopOpts).resolves(null);
breakerMock.runCommand.withArgs(destroyOpts).resolves(null);

executor.stop({ buildId: config.buildId }).then(ret => {
assert.isNull(ret);
assert.calledWith(breakerMock.runCommand, getOpts);
assert.calledWith(breakerMock.runCommand, stopOpts);
assert.calledWith(breakerMock.runCommand, destroyOpts);
done();
});
executor
.stop({
apiUri,
buildId: config.buildId
})
.then(ret => {
assert.isNull(ret);
assert.calledWith(breakerMock.runCommand, getOpts);
assert.calledWith(breakerMock.runCommand, stopOpts);
assert.calledWith(breakerMock.runCommand, destroyOpts);
done();
});
});

it('return null when the build is successfully stopped after a while', done => {
breakerMock.runCommand
.withArgs(getOpts)
.onCall(0)
.resolves(fakeJobInfo);
breakerMock.runCommand
.withArgs(getOpts)
.onCall(1)
.resolves(fakeJobInfo);
breakerMock.runCommand
.withArgs(getOpts)
.onCall(2)
.resolves(fakeCompletedJobInfo);
breakerMock.runCommand.withArgs(getOpts).onCall(0).resolves(fakeJobInfo);
breakerMock.runCommand.withArgs(getOpts).onCall(1).resolves(fakeJobInfo);
breakerMock.runCommand.withArgs(getOpts).onCall(2).resolves(fakeCompletedJobInfo);
breakerMock.runCommand.withArgs(stopOpts).resolves(null);
breakerMock.runCommand.withArgs(destroyOpts).resolves(null);

executor.stop({ buildId: config.buildId }).then(ret => {
assert.isNull(ret);
assert.calledWith(breakerMock.runCommand, getOpts);
assert.calledWith(breakerMock.runCommand, stopOpts);
assert.calledWith(breakerMock.runCommand, destroyOpts);
done();
});
executor
.stop({
apiUri,
buildId: config.buildId
})
.then(ret => {
assert.isNull(ret);
assert.calledWith(breakerMock.runCommand, getOpts);
assert.calledWith(breakerMock.runCommand, stopOpts);
assert.calledWith(breakerMock.runCommand, destroyOpts);
done();
});
});

it('return error when the job not stopped until the timelimit', done => {
Expand All @@ -417,22 +413,32 @@ describe('index', () => {
breakerMock.runCommand.withArgs(stopOpts).resolves(null);
breakerMock.runCommand.withArgs(destroyOpts).resolves(null);

executor.stop({ buildId: config.buildId }).catch(err => {
assert.deepEqual(err.message, 'Clean up timeout exceeded');
assert.calledWith(breakerMock.runCommand, getOpts);
assert.calledWith(breakerMock.runCommand, stopOpts);
done();
});
executor
.stop({
apiUri,
buildId: config.buildId
})
.catch(err => {
assert.deepEqual(err.message, 'Clean up timeout exceeded');
assert.calledWith(breakerMock.runCommand, getOpts);
assert.calledWith(breakerMock.runCommand, stopOpts);
done();
});
});

it('return error when there are no jobs in process yet', done => {
breakerMock.runCommand.withArgs(getOpts).resolves(null);
breakerMock.runCommand.withArgs(stopOpts).resolves(null);

executor.stop({ buildId: config.buildId }).catch(err => {
assert.deepEqual(err.message, 'No jobs in process yet, try later');
done();
});
executor
.stop({
apiUri,
buildId: config.buildId
})
.catch(err => {
assert.deepEqual(err.message, 'No jobs in process yet, try later');
done();
});
});

it('return error when job.get is getting error', done => {
Expand All @@ -441,10 +447,15 @@ describe('index', () => {
breakerMock.runCommand.withArgs(getOpts).rejects(error);
breakerMock.runCommand.withArgs(stopOpts).resolves();

executor.stop({ buildId: config.buildId }).catch(err => {
assert.deepEqual(err, error);
done();
});
executor
.stop({
apiUri,
buildId: config.buildId
})
.catch(err => {
assert.deepEqual(err, error);
done();
});
});

it('return error when build.stop is getting error', done => {
Expand All @@ -453,29 +464,33 @@ describe('index', () => {
breakerMock.runCommand.withArgs(getOpts).resolves(fakeJobInfo);
breakerMock.runCommand.withArgs(stopOpts).rejects(error);

executor.stop({ buildId: config.buildId }).catch(err => {
assert.deepEqual(err, error);
done();
});
executor
.stop({
apiUri,
buildId: config.buildId
})
.catch(err => {
assert.deepEqual(err, error);
done();
});
});

it('return error when second job.get is getting error', done => {
const error = new Error('job.get error');

breakerMock.runCommand
.withArgs(getOpts)
.onCall(0)
.resolves(fakeJobInfo);
breakerMock.runCommand
.withArgs(getOpts)
.onCall(1)
.rejects(error);
breakerMock.runCommand.withArgs(getOpts).onCall(0).resolves(fakeJobInfo);
breakerMock.runCommand.withArgs(getOpts).onCall(1).rejects(error);
breakerMock.runCommand.withArgs(stopOpts).resolves();

executor.stop({ buildId: config.buildId }).catch(err => {
assert.deepEqual(err, error);
done();
});
executor
.stop({
apiUri,
buildId: config.buildId
})
.catch(err => {
assert.deepEqual(err, error);
done();
});
});
});

Expand Down

0 comments on commit 2fa7f32

Please sign in to comment.