Debian Codegraph @

vendor/wikimedia/parsoid/tests/api-testing/RoundTrip.js

raw
1 /**
2 * Cases for testing the Parsoid round trip conversions: WT -> HTML -> WT
3 * in both SelSer and non-SelSer modes.
4 */
5
6 'use strict';
7
8 const { REST, assert, action, utils } = require("api-testing");
9
10 const url = require('url');
11 const rt = require('../../bin/roundtrip-test');
12 function status200( res ) {
13 assert.strictEqual( res.status, 200, res.text );
14 }
15
16 describe( 'Parsoid round-trip e2e testing with MW REST endpoints', function () {
17 this.timeout( 30000 );
18 const client = new REST();
19 const parsedUrl = new url.URL(client.req.app);
20 client.pathPrefix = 'rest.php';
21 const page = utils.title( 'RoundTrip ' );
22 let revid;
23 const httpClient = {
24 request: function (httpOptions) {
25 return client.request(
26 httpOptions.uri,
27 httpOptions.method,
28 httpOptions.body || httpOptions.params,
29 httpOptions.headers
30 )
31 .redirects(1) // roundtrip-test.js executes at least one redirect per request
32 .expect(status200)
33 .then((res) => [
34 { request: res.req, headers: res.headers },
35 Object.keys(res.body).length !== 0 ? res.body : res.text
36 ]);
37 }
38 };
39
40 before( async function () {
41 const alice = await action.alice();
42
43 // Create pages
44 const edit = await alice.edit( page, { text: '{|\nhi\n|ho\n|}' } );
45 assert.strictEqual(edit.result, 'Success');
46 revid = edit.newrevid;
47 } );
48
49 it( 'rt-testing e2e', async function () {
50 const result = await rt.runTests(page, {
51 httpClient,
52 domain: parsedUrl.hostname,
53 parsoidURLOpts: {
54 baseUrl: '',
55 }
56 }, rt.jsonFormat);
57 assert.strictEqual(result.output.error, undefined, result.output.error);
58 assert.strictEqual(result.exitCode, 0, result.output.error);
59 } );
60 } );