Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add integration tests
adds a testmatrix for different magnolia versions to run
integration tests based on bash or cheerio.

uses a bootstrap.xml to setup the page.
  • Loading branch information
robertkowalski committed Feb 10, 2017
1 parent d2cf96b commit 9f7339b
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .travis.yml
@@ -1,3 +1,38 @@
language: node_js
node_js:
- "6"

env:
- MAGNOLIA_CE_VERSION=5.5.1
- MAGNOLIA_CE_VERSION=5.5

sudo: false
addons:
apt:
packages:
- oracle-java8-installer
- oracle-java8-set-default

dist: trusty

before_script:

- cd .. && git clone -b proto https://github.com/robertkowalski/magnolia-cli && cd magnolia-cli && npm i -g . && cd ..

This comment has been minimized.

Copy link
@robertkowalski

robertkowalski Feb 10, 2017

Author Owner

use latest version which contains mgnl start

- mgnl -h

- mkdir -p magnolia && cd magnolia && mgnl jumpstart --magnolia-version=$MAGNOLIA_CE_VERSION && cd ..

- cd mgnl-custom && npm run build && cd ..

- cp -R mgnl-custom magnolia/light-modules/
- cp magnolia/light-modules/mgnl-custom/dev/test/fixtures/website.ci-testpage.xml magnolia/apache-tomcat/webapps/magnoliaAuthor/WEB-INF/bootstrap/common

- mkdir -p magnolia/apache-tomcat/logs/
- touch magnolia/apache-tomcat/logs/catalina.out
- pwd && ls
- cd magnolia
- mgnl start &
- until fgrep -q "Server startup" apache-tomcat/logs/catalina.out; do sleep 1; done

- cd ..
- cd mgnl-custom
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -3,3 +3,24 @@
# mgnl-custom

Small demo module built with webpack.


## Tests

### Fixture Setup

Fixture was exported from Magnolia using the "Export"-functionality of the UI

### JS Unit Tests

Unit tests are using Jest as test runner, as it supplies a DOM environment

### Template / Integration tests

Tests are super simple and based `cheerio`. Mocha is used as test runner

### Travis

Main test step in Travis executes `npm test`

Setting up the Magnolia server is done with the `before_script` hook.
150 changes: 150 additions & 0 deletions dev/test/fixtures/website.ci-testpage.xml
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="ci-testpage" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>mgnl:page</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true">
<sv:value>mgnl:hasVersion</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>b8815614-b331-4d15-940b-c37fe80d2b70</sv:value>
</sv:property>
<sv:property sv:name="hideInNav" sv:type="Boolean">
<sv:value>false</sv:value>
</sv:property>
<sv:property sv:name="jcr:createdBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:property sv:name="mgnl:activationStatus" sv:type="Boolean">
<sv:value>true</sv:value>
</sv:property>
<sv:property sv:name="mgnl:comment" sv:type="String">
<sv:value/>
</sv:property>
<sv:property sv:name="mgnl:created" sv:type="Date">
<sv:value>2017-02-03T12:38:38.746Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:createdBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastActivated" sv:type="Date">
<sv:value>2017-02-03T12:40:05.367Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastActivatedBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModified" sv:type="Date">
<sv:value>2017-02-03T12:39:46.658Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModifiedBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:template" sv:type="String">
<sv:value>mtk:pages/basic</sv:value>
</sv:property>
<sv:node sv:name="main">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>mgnl:area</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>c342b5e3-934a-40eb-bc8f-2290da580ca8</sv:value>
</sv:property>
<sv:property sv:name="jcr:createdBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:property sv:name="mgnl:activationStatus" sv:type="Boolean">
<sv:value>true</sv:value>
</sv:property>
<sv:property sv:name="mgnl:created" sv:type="Date">
<sv:value>2017-02-03T12:39:06.215Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:createdBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastActivated" sv:type="Date">
<sv:value>2017-02-03T12:40:05.370Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastActivatedBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModified" sv:type="Date">
<sv:value>2017-02-03T12:39:46.658Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModifiedBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:node sv:name="0">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>mgnl:component</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>16395e0f-768a-47c3-956c-b8c3f87956e3</sv:value>
</sv:property>
<sv:property sv:name="elementClass" sv:type="String">
<sv:value>.furbie</sv:value>
</sv:property>
<sv:property sv:name="jcr:createdBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:property sv:name="mgnl:activationStatus" sv:type="Boolean">
<sv:value>true</sv:value>
</sv:property>
<sv:property sv:name="mgnl:created" sv:type="Date">
<sv:value>2017-02-03T12:39:46.659Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:createdBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastActivated" sv:type="Date">
<sv:value>2017-02-03T12:40:05.374Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastActivatedBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModified" sv:type="Date">
<sv:value>2017-02-03T12:39:46.659Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModifiedBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:template" sv:type="String">
<sv:value>mgnl-custom:components/mgnl-custom</sv:value>
</sv:property>
<sv:property sv:name="option" sv:type="String">
<sv:value>a</sv:value>
</sv:property>
</sv:node>
</sv:node>
<sv:node sv:name="footer">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>mgnl:area</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>11cf10fb-d1c8-4295-86ac-91285788f57c</sv:value>
</sv:property>
<sv:property sv:name="jcr:createdBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:property sv:name="mgnl:activationStatus" sv:type="Boolean">
<sv:value>true</sv:value>
</sv:property>
<sv:property sv:name="mgnl:created" sv:type="Date">
<sv:value>2017-02-03T12:39:06.281Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:createdBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastActivated" sv:type="Date">
<sv:value>2017-02-03T12:40:05.375Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastActivatedBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModified" sv:type="Date">
<sv:value>2017-02-03T12:39:06.281Z</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModifiedBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
</sv:node>
</sv:node>
38 changes: 38 additions & 0 deletions dev/test/integration/cheerio.js
@@ -0,0 +1,38 @@
// mocha based tests

const assert = require('assert')
const request = require('request')
const cheerio = require('cheerio')

const URL = 'http://localhost:8080/magnoliaPublic/ci-testpage.html'

describe('integration test', () => {

it('renders the template with the css class furbie', (done) => {
request({
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:51.0) Gecko/20100101 Firefox/51.0'
},
uri: URL
}, (err, res, body) => {
const $ = cheerio.load(body)
assert.equal($('.furbie').length, 1)
done()
})
}).timeout(10000)

it('renders the template variable in the script tag', (done) => {
request({
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:51.0) Gecko/20100101 Firefox/51.0'
},
uri: URL
}, (err, res, body) => {
const $ = cheerio.load(body)
const scriptTagContent = $('script').text()
assert.ok(/\.furbie/.test(scriptTagContent), '.furbie in script')
done()
})
})

})
4 changes: 4 additions & 0 deletions dev/test/integration/simple.sh
@@ -0,0 +1,4 @@
#!/bin/sh

curl http://localhost:8080/magnoliaPublic/ci-testpage.html
curl http://localhost:8080/magnoliaPublic/ci-testpage.html | grep "furbie"
2 changes: 2 additions & 0 deletions dev/test/unit/calendar.test.js
@@ -1,3 +1,5 @@
// jest based tests

import Calendar from '../../js/calendar.js'

describe('calendar', () => {
Expand Down
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -4,10 +4,12 @@
"description": "no dependencies, no cry",
"main": "index.js",
"scripts": {
"test": "jest",
"test": "npm run unit && npm run integration",
"unit": "jest",
"integration": "mocha ./dev/test/integration/cheerio.js",
"build": "webpack webpack.config.js",
"watch": "npm run build -- --watch",
"prepublish": "npm run test && echo \"Building...\" && npm run build"
"prepublish": "echo \"Building...\" && npm run build"
},
"repository": {
"type": "git",
Expand All @@ -30,9 +32,11 @@
"babel-preset-airbnb": "^2.2.3",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"cheerio": "^0.22.0",
"css-loader": "^0.26.1",
"jest": "^18.1.0",
"mocha": "^3.2.0",
"request": "^2.79.0",
"style-loader": "^0.13.1",
"webpack": "^2.2.1"
}
Expand Down

0 comments on commit 9f7339b

Please sign in to comment.