diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..e0c4364 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,18 @@ +#!groovy + +node{ + stage 'Checkout' + checkout scm + + stage 'Setup' + sh 'npm config set registry http://registry.npmjs.org/' + sh 'npm install' + + stage 'Mocha test' + sh './node_modules/mocha/bin/mocha' + + stage 'Cleanup' + echo 'prune and cleanup' + sh 'npm prune' + sh 'rm node_modules -rf' +} diff --git a/helloworld.js b/helloworld.js new file mode 100644 index 0000000..fc6f5ac --- /dev/null +++ b/helloworld.js @@ -0,0 +1,15 @@ +var http = require("http") + +http.createServer(function (request, response) { + + // Send the HTTP header + // HTTP Status: 200 : OK + // Content Type: text/plain + response.writeHead(200, {'Content-Type': 'text/plain'}) + + // Send the response body as "Hello World" + response.end('Hello World') +}).listen(3000) + +// Console will print the message +console.log('Server running') diff --git a/package.json b/package.json new file mode 100644 index 0000000..a617ed0 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "helloworld", + "version": "1.0.0", + "description": "", + "main": "helloworld.js", + "scripts": { + "test": "node_modules/mocha/bin/mocha" + }, + "repository": { + "type": "git", + "url": "https://github.com/SWDV660helloworldtest/helloworld.git" + }, + "author": "", + "license": "BSD", + "bugs": { + "url": "https://github.com/SWDV660helloworldtest/helloworld/issues" + }, + "devDependencies": { + "mocha": "~2.5.3", + "zombie": "~3.0.15" + } +} diff --git a/test/helloworld_test.js b/test/helloworld_test.js new file mode 100644 index 0000000..becdf2b --- /dev/null +++ b/test/helloworld_test.js @@ -0,0 +1,21 @@ +var Browser = require('zombie') +var assert = require('assert') +var app = require('../helloworld') + + +describe('main page', function() { +before(function(){ + this.browser = new Browser({ site: 'http://localhost:3000' }) +}) + +before(function(done) { + this.browser.visit('/', done) +}) + +it('should say hello world', function() { + assert.ok(this.browser.success) + assert.equal(this.browser.text(), "Hello World") +}) +}) + + diff --git a/test/npm-debug.log b/test/npm-debug.log new file mode 100644 index 0000000..a803ce6 --- /dev/null +++ b/test/npm-debug.log @@ -0,0 +1,18 @@ +0 info it worked if it ends with ok +1 verbose cli [ 'node', '/usr/bin/npm', 'test' ] +2 info using npm@1.3.6 +3 info using node@v0.10.48 +4 error Error: ENOENT, open '/home/ec2-user/helloworld/test/package.json' +5 error If you need help, you may report this log at: +5 error +5 error or email it to: +5 error +6 error System Linux 4.14.47-56.37.amzn1.x86_64 +7 error command "node" "/usr/bin/npm" "test" +8 error cwd /home/ec2-user/helloworld/test +9 error node -v v0.10.48 +10 error npm -v 1.3.6 +11 error path /home/ec2-user/helloworld/test/package.json +12 error code ENOENT +13 error errno 34 +14 verbose exit [ 34, true ]