Marcoil has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172762
Change subject: Add mocha tests for accessing the Parsoid API through HTTP
......................................................................
Add mocha tests for accessing the Parsoid API through HTTP
So far:
* Simple wikitext and HTML conversion
* body parameter to omit HTML header
Change-Id: Ie1e3d06223ff6c0854f9a8ca4b22e6a55b599a46
---
M package.json
A tests/mocha/api.js
M tests/test.localsettings.js
3 files changed, 75 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/62/172762/1
diff --git a/package.json b/package.json
index 9b276e8..931ac2c 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,8 @@
"devDependencies": {
"chai": "~1.9.1",
"colors": "~0.6.2",
- "mocha": "~1.21.4"
+ "mocha": "~1.21.4",
+ "supertest": "0.14.0"
},
"bin": {
"parse.js": "tests/parse.js"
diff --git a/tests/mocha/api.js b/tests/mocha/api.js
new file mode 100644
index 0000000..6f537c7
--- /dev/null
+++ b/tests/mocha/api.js
@@ -0,0 +1,72 @@
+/** Test cases for lib/mediawiki.Util.js */
+'use strict';
+/*global describe, it, before*/
+
+var apiServer = require('../apiServer.js'),
+ request = require('supertest'),
+ domino = require('domino'),
+ should = require('chai').should();
+
+describe('Parsoid API', function () {
+ var api;
+
+ before(function (done) {
+ new Promise(function (resolve, reject) {
+ // Start a mock MediaWiki API server
+ console.log("Starting mock api");
+ apiServer.startMockAPIServer({port: 7001}, resolve);
+ }).then(function () {
+ console.log("starting parsoid");
+ apiServer.startParsoidServer(null, function (url) {
+ api = url;
+ done();
+ });
+ });
+ apiServer.exitOnProcessTerm();
+ });
+
+ it("converts simple wikitext to HTML", function (done) {
+ request(api)
+ .post('/localhost/Main_Page')
+ .send({wt: "foo"})
+ .expect(200)
+ .expect(function (res) {
+ var doc = domino.createDocument(res.text);
+ doc.should.have.property('nodeName', '#document');
+ doc.outerHTML.startsWith('<!DOCTYPE
html>').should.equal(true);
+
doc.outerHTML.endsWith('</body></html>').should.equal(true);
+ // verify that body has only one <html> tag, one <body>
tag, etc.
+ doc.childNodes.length.should.equal(2);// <!DOCTYPE> and
<html>
+ doc.firstChild.nodeName.should.equal('html');
+ doc.lastChild.nodeName.should.equal('HTML');
+ // <html> children should be <head> and <body>
+ var html = doc.documentElement;
+ html.childNodes.length.should.equal(2);
+ html.firstChild.nodeName.should.equal('HEAD');
+ html.lastChild.nodeName.should.equal('BODY');
+ // <body> should have one child, <p>
+ var body = doc.body;
+ body.childElementCount.should.equal(1);
+ body.firstElementChild.nodeName.should.equal('P');
+ var p = doc.body.firstElementChild;
+ p.innerHTML.should.equal('foo');
+ })
+ .end(done);
+ });
+
+ it("converts simple HTML to wikitext", function (done) {
+ request(api)
+ .post('/localhost/Main_Page')
+ .send({html: "<i>foo</i>"})
+ .expect(200)
+ .expect("''foo''", done);
+ });
+
+ it("respects body parameter", function (done) {
+ request(api)
+ .post('/localhost/Main_Page')
+ .send({wt: "''foo''", body: 1})
+ .expect(200)
+ .expect(/^<body/, done);
+ });
+});
diff --git a/tests/test.localsettings.js b/tests/test.localsettings.js
index 811c33d..b78bd92 100644
--- a/tests/test.localsettings.js
+++ b/tests/test.localsettings.js
@@ -9,7 +9,7 @@
exports.setup = function( parsoidConfig ) {
// The URL here is supposed to be your MediaWiki installation root
- parsoidConfig.setInterwiki( 'localhost', 'http://localhost/w/api.php' );
+ parsoidConfig.setInterwiki( 'localhost',
'http://localhost:7001/api.php' );
// Use the PHP preprocessor to expand templates via the MW API (default
true)
//parsoidConfig.usePHPPreProcessor = false;
--
To view, visit https://gerrit.wikimedia.org/r/172762
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1e3d06223ff6c0854f9a8ca4b22e6a55b599a46
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits