Skip to content
This repository was archived by the owner on Feb 13, 2018. It is now read-only.

Commit 75aeecf

Browse files
committed
Add casper tests
Add some new casper tests
1 parent 6b81f4f commit 75aeecf

File tree

5 files changed

+171
-5
lines changed

5 files changed

+171
-5
lines changed

casper-runner.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
3+
const spawn = require('child_process').spawn;
4+
5+
require('dotenv').config({ silent: true });
6+
7+
const app = require('./app');
8+
const port = 3000;
9+
10+
const server = app.listen(port, () => {
11+
// eslint-disable-next-line no-console
12+
console.log('Server running on port: %d', port);
13+
14+
function kill(code) {
15+
server.close(() => {
16+
// eslint-disable-next-line no-process-exit
17+
process.exit(code);
18+
});
19+
}
20+
21+
function runTests() {
22+
const casper = spawn('npm', ['run', 'test-integration']);
23+
casper.stdout.pipe(process.stdout);
24+
25+
casper.on('error', (error) => {
26+
// eslint-disable-next-line no-console
27+
console.log(`ERROR: ${error}`);
28+
server.close(() => {
29+
process.exit(1);
30+
});
31+
});
32+
33+
casper.on('close', kill);
34+
}
35+
36+
runTests();
37+
});

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@
4343
},
4444
"scripts": {
4545
"start": "node server.js",
46-
"test": "npm run lint && npm run smoketest",
47-
"smoketest": "istanbul cover ./node_modules/mocha/bin/_mocha",
46+
"test-integration": "casperjs test ./test/integration/test.*.js",
47+
"test-integration-runner": "NODE_ENV=test node casper-runner.js",
48+
"test": "npm run lint && npm run test-unit && npm run test-integration-runner",
49+
"test-unit": "istanbul cover ./node_modules/mocha/bin/_mocha test/unit",
4850
"lint": "eslint .",
4951
"autofix": "eslint --fix .",
5052
"codecov": "npm run test && (codecov || true)"
5153
},
5254
"devDependencies": {
5355
"babel-eslint": "^7.0.0",
56+
"casperjs": "^1.1.3",
5457
"codecov": "^1.0.1",
5558
"eslint": "^3.3.1",
5659
"eslint-config-airbnb": "^12.0.0",

test/integration/test.mainpage.js

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/* eslint no-undef: 0 */
2+
/* eslint prefer-arrow-callback: 0 */
3+
casper.test.begin('Document Conversion Demo', 31, function suite(test) {
4+
const baseHost = 'http://localhost:3000';
5+
6+
function testButtonExists() {
7+
test.assertExists('label[for="source-sampleHTML.html"]', 'Sample html - button is found');
8+
test.assertExists('label[for="source-sampleWORD.docx"]', 'Sample docx - button is found');
9+
test.assertExists('label[for="source-samplePDF.pdf"]', 'Sample pdf - button is found');
10+
test.assertExists('label[for="source-custom"]', 'Upload a file - button is found');
11+
}
12+
13+
function testOutputSection() {
14+
// Brings up Choose an output format - check for 3 new buttons
15+
casper.waitForSelector('div._content--choose-output-format', function () {
16+
test.assertExists('label[for="destination-json"]', 'Answer units JSON - button is found');
17+
test.assertExists('label[for="destination-html"]', 'Normlized HTML - button is found');
18+
test.assertExists('label[for="destination-text"]', 'Plain text - button is found');
19+
});
20+
}
21+
22+
function testHtmlButtonClick() {
23+
casper.then(function () {
24+
this.click('label[for="source-sampleHTML.html"]');
25+
});
26+
27+
testOutputSection();
28+
}
29+
30+
function testDocxButtonClick() {
31+
casper.then(function () {
32+
this.click('label[for="source-sampleWORD.docx"]');
33+
});
34+
35+
testOutputSection();
36+
}
37+
38+
function testPdfButtonClick() {
39+
casper.then(function () {
40+
this.click('label[for="source-samplePDF.pdf"]');
41+
});
42+
43+
testOutputSection();
44+
}
45+
46+
function testUploadButtonClick() {
47+
casper.then(function () {
48+
this.click('label[for="source-custom"]');
49+
});
50+
51+
casper.waitForSelector('div._content--choose-output-format', function () {
52+
test.assertExists('label[for="file-chooser-input"]', 'Choose your file - button is found');
53+
});
54+
}
55+
56+
function checkLinkDest(starturl, selectorToClick) {
57+
casper.thenOpen(starturl, function () { });
58+
casper.then(function () { this.click(selectorToClick); });
59+
test.assertHttpStatus(200);
60+
}
61+
62+
function testHeaderLinks() {
63+
checkLinkDest(baseHost, 'nav.jumbotron--nav h5:nth-child(1)');
64+
checkLinkDest(baseHost, 'nav.jumbotron--nav li:nth-child(1)');
65+
checkLinkDest(baseHost, 'nav.jumbotron--nav li:nth-child(2)');
66+
checkLinkDest(baseHost, 'nav.jumbotron--nav li:nth-child(3)');
67+
}
68+
69+
function testDocumentSection() {
70+
// Brings up Document section - Your document and Output document
71+
casper.waitForSelector('div._content--output', function () {
72+
test.assertExists('div[class="tab-panels"]', 'The tab panel is found');
73+
test.assertExists('a[class="active tab-panels--tab base--a"]', 'Your document - is found');
74+
test.assertExists('a[class=" tab-panels--tab base--a"]', 'Output document - is found');
75+
});
76+
}
77+
78+
function testOutputFormatButtonsClick() {
79+
casper.then(function () {
80+
this.click('label[for="destination-json"]');
81+
});
82+
83+
testDocumentSection();
84+
85+
casper.then(function () {
86+
this.click('label[for="destination-html"]');
87+
});
88+
89+
testDocumentSection();
90+
91+
casper.then(function () {
92+
this.click('label[for="destination-text"]');
93+
});
94+
95+
testDocumentSection();
96+
97+
// Your document
98+
casper.then(function () {
99+
this.click('ul.tab-panels--tab-list li:nth-child(1)');
100+
});
101+
test.assertHttpStatus(200);
102+
103+
// Output document
104+
casper.then(function () {
105+
this.click('ul.tab-panels--tab-list li:nth-child(2)');
106+
});
107+
test.assertHttpStatus(200);
108+
}
109+
110+
casper.start(baseHost, function (result) {
111+
test.assert(result.status === 200, 'Front page opens');
112+
test.assertEquals(this.getTitle(), 'Document Conversion Demo', 'Title is found');
113+
114+
testButtonExists();
115+
testHtmlButtonClick();
116+
testDocxButtonClick();
117+
testPdfButtonClick();
118+
testUploadButtonClick();
119+
testHeaderLinks();
120+
testOutputFormatButtonsClick();
121+
});
122+
123+
casper.run(function () {
124+
test.done();
125+
});
126+
});

test/test.express.js renamed to test/unit/test.express.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
const path = require('path');
1919
// load default variables for testing
20-
require('dotenv').config({ path: path.join(__dirname, '../.env.example') });
20+
require('dotenv').config({ path: path.join(__dirname, '../../.env.example') });
2121

2222

23-
const app = require('../app');
23+
const app = require('../../app');
2424
const request = require('supertest');
2525

2626
describe('express', () => {

test/test.react.js renamed to test/unit/test.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require('babel-register');
2020

2121
describe('react', () => {
2222
it('should render some html', () => {
23-
const index = require('../views/index.jsx').default;
23+
const index = require('../../views/index.jsx').default;
2424
const element = React.createElement(index, null);
2525
const result = ReactDOMServer.renderToString(element);
2626
assert(result);

0 commit comments

Comments
 (0)