Compare commits

..

3 Commits

Author SHA1 Message Date
Timo Hocker
7bd4224a05 add tests for subdir 2019-12-11 12:19:02 +01:00
Timo Hocker
d680bf4c5e add subdirectory option 2019-12-11 12:17:29 +01:00
Timo Hocker
d53641ea1b add Jenkins 2019-12-11 12:16:12 +01:00
4 changed files with 69 additions and 5 deletions

46
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,46 @@
pipeline {
agent any
environment {
VERSION = VersionNumber([
versionNumberString:
'${BUILDS_ALL_TIME}',
versionPrefix: '1.1.',
worstResultForIncrement: 'SUCCESS'
])
publish = 0
}
stages {
stage('Setup') {
steps {
echo 'Setting up test environment'
sh 'npm ci'
sh 'nodejs jenkins.js ${VERSION}'
script {
currentBuild.displayName = env.VERSION
}
}
}
stage('Testing') {
steps {
echo 'Running tests...'
sh 'npm test'
}
}
}
post {
success {
script {
publish = sh script: "git log -1 | grep '\\[no publish\\]'", returnStatus: true
if (publish != 0) {
echo 'Deploying'
sh 'npm publish'
} else {
echo 'Build successful, Commit not marked for deploying'
currentBuild.result = "UNSTABLE"
}
}
}
}
}

View File

@ -8,11 +8,11 @@ const path = require('path');
* @param {string} modulefolder
* @param {any} opts object to pass to the handlers (for example database access)
*/
module.exports = function (app, modulefolder, opts) {
module.exports = function (app, modulefolder, opts = {}, subdir = '') {
for (const f of fs.readdirSync(modulefolder)) {
const regex = /(.*?)-(.*?)\.js/;
let [, method, url] = regex.exec(f);
url = '/' + url + '/';
url = '/' + subdir + '/' + url + '/';
url = url
.replace(/^\/root/i, '/')
.replace(/\./g, '/')

5
jenkins.js Normal file
View File

@ -0,0 +1,5 @@
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
pkg.version = process.argv[2];
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));

View File

@ -28,7 +28,7 @@ describe('requestor', () => {
});
it('should detect all requests on root', () => {
requestor(mock, './test/root', {});
requestor(mock, './test/root');
expect(mock.registered).to.have.all.keys([
'post-/',
'get-/',
@ -39,7 +39,7 @@ describe('requestor', () => {
});
it('should detect requests on root.subfolder', () => {
requestor(mock, './test/root.sub', {});
requestor(mock, './test/root.sub');
expect(mock.registered).to.have.all.keys([
'post-/sub/',
'get-/sub/',
@ -50,7 +50,7 @@ describe('requestor', () => {
});
it('should detect requests on subfolder', () => {
requestor(mock, './test/sub', {});
requestor(mock, './test/sub');
expect(mock.registered).to.have.all.keys([
'post-/sub/',
'get-/sub/',
@ -61,4 +61,17 @@ describe('requestor', () => {
'all-/sub/root/'
]);
});
it('should build requests with subdirectory', () => {
requestor(mock, './test/sub', {}, 'test');
expect(mock.registered).to.have.all.keys([
'post-/test/sub/',
'get-/test/sub/',
'put-/test/sub/',
'delete-/test/sub/',
'all-/test/sub/',
'get-/test/sub/lv1/lv2/lv3/',
'all-/test/sub/root/'
]);
});
});