[ell-i-developers] hi all, we had the Monday workshop - I prepared the Dockerfile for test environment creation...

  • From: eero hakala <eero.k.hakala@xxxxxxxxx>
  • To: ell-i-developers@xxxxxxxxxxxxx
  • Date: Mon, 12 Oct 2015 22:47:23 +0300

Hi all, we seem to be in the middle of intiaanikesä - only the temperatures are on a bit low side!



The Dockerfile is in fact quite simple:
======================

FROM debian

RUN apt-get update -qq && \
apt-get install -y nodejs npm && \
npm install -g coffee-script && \
ln -s /usr/bin/nodejs /usr/bin/node

RUN mkdir -p /data
WORKDIR /data
# simple tests
RUN node --version
RUN npm --version
RUN coffee --version


creating the container:
======================
## note: you might need to use sudo for docker command!! ##
docker build --rm=true -t coffee .


and using it is also very easy:
=======================
##this is just hello world ...[console.log("Hello World!")]
docker run -it --rm -v $(pwd):/data -w /data coffee coffee heippa_kahvia.js

##this again runs the unit test environment made/copied by Teemu
docker run -it --rm -v $(pwd):/data -w /data coffee coffee anything.coffee


-eero-

PS these are the required files:

##first one: anything.coffee
unit = require './unit.coffee'

console.log unit

noop = ->
oops = -> throw new Error
result = unit.runAll [oops, noop]
result.assert result.runCount is 2
result.assert result.failCount is 1

console.log 'localtimer.coffee says Success !!


##and the second one: unit.coffee
# kent beck did this short test suite in making making coffeescript

class unit
runCount: 0
failCount: 0
assert: (flag) ->
throw new Error if not flag
@runAll: (tests) ->
result = new unit
result.runTest test for test in tests
result
@run: (test) ->
unit.runAll [test]
runTest: (test) ->
this.runCount++
try
test()
catch
this.failCount++

# self-tests

thrown = false
result = new unit
try
unit.assert false
catch
thrown = true
throw new Error if not thrown

result = unit.run ->
result.assert result.runCount is 1
result.assert result.failCount is 0

result = unit.run -> throw new Error
result.assert result.runCount is 1
result.assert result.failCount is 1

noop = ->
result = unit.runAll [noop, noop]
result.assert result.runCount is 2
result.assert result.failCount is 0

oops = -> throw new Error
result = unit.runAll [oops, noop]
result.assert result.runCount is 2
result.assert result.failCount is 1

result = unit.runAll [->]
result.assert result.runCount is 1
result.assert result.failCount is 0


module.exports = unit

console.log 'unit.coffee says Success !!!'


Other related posts:

  • » [ell-i-developers] hi all, we had the Monday workshop - I prepared the Dockerfile for test environment creation... - eero hakala