From 0cdc7a73eb4f8a09d8e3441eafc8c6bb66d1473e Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 8 Jul 2022 13:36:14 +0200 Subject: [PATCH] Transform e2e test: Move data into separate files Move HTML and other complex input and output data from giant strings into files. This makes them easier to read, modify, and compare. Change-Id: Iafe2638e4eda903e1064b05adaa80a39ff5028f9 --- tests/api-testing/REST/Transform.js | 121 ++++++------------ .../data/Transform/Image-data-mw.html | 1 + tests/api-testing/data/Transform/Image.html | 1 + .../data/Transform/JsonConfig.html | 2 + .../MainPage-data-parsoid-1.1.1.html | 10 ++ .../data/Transform/MainPage-data-parsoid.html | 10 ++ .../Transform/MainPage-original.data-parsoid | 20 +++ .../data/Transform/MainPage-original.html | 10 ++ .../data/Transform/Minimal-2222.html | 2 + tests/api-testing/data/Transform/Minimal.html | 2 + 10 files changed, 97 insertions(+), 82 deletions(-) create mode 100644 tests/api-testing/data/Transform/Image-data-mw.html create mode 100644 tests/api-testing/data/Transform/Image.html create mode 100644 tests/api-testing/data/Transform/JsonConfig.html create mode 100644 tests/api-testing/data/Transform/MainPage-data-parsoid-1.1.1.html create mode 100644 tests/api-testing/data/Transform/MainPage-data-parsoid.html create mode 100644 tests/api-testing/data/Transform/MainPage-original.data-parsoid create mode 100644 tests/api-testing/data/Transform/MainPage-original.html create mode 100644 tests/api-testing/data/Transform/Minimal-2222.html create mode 100644 tests/api-testing/data/Transform/Minimal.html diff --git a/tests/api-testing/REST/Transform.js b/tests/api-testing/REST/Transform.js index cb498dd8859..b0b37f94767 100644 --- a/tests/api-testing/REST/Transform.js +++ b/tests/api-testing/REST/Transform.js @@ -8,6 +8,7 @@ const domino = require( 'domino' ); const should = require( 'chai' ).should(); const semver = require( 'semver' ); const url = require( 'url' ); +const fs = require( 'fs' ); const parsoidOptions = { limits: { @@ -1078,7 +1079,17 @@ describe( '/transform/ endpoint', function () { } ); // end wt2html + const getTextFromFile = function ( name ) { + return fs.readFileSync( __dirname + '/../data/Transform/' + name, 'utf-8' ).trim(); + }; + describe( 'html2wt', function () { + const htmlOfMainPageWithDataParsoid = getTextFromFile( 'MainPage-data-parsoid.html' ); + const htmlOfMainPageWithDataParsoid_1_1_1 = getTextFromFile( 'MainPage-data-parsoid-1.1.1.html' ); + const htmlOfMainPageOriginal = getTextFromFile( 'MainPage-original.html' ); + const dataParsoidOfMainPageOriginal = JSON.parse( getTextFromFile( 'MainPage-original.data-parsoid' ) ); + const htmlOfImage = getTextFromFile( 'Image.html' ); + const htmlOfImageWithDataMW = getTextFromFile( 'Image-data-mw.html' ); it( 'should require html when serializing', function ( done ) { client.req @@ -1112,17 +1123,18 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/html/to/wikitext/' ) .send( { - html: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n' + html: htmlOfMainPageWithDataParsoid } ) .expect( validWikitextResponse() ) .end( done ); } ); + const htmlOfJsonConfig = getTextFromFile( 'JsonConfig.html' ); it( 'should accept html for json contentmodel as a string', function ( done ) { client.req .post( endpointPrefix + '/transform/html/to/wikitext/' ) .send( { - html: '\n
a4
b3
', + html: htmlOfJsonConfig, contentmodel: 'json' } ) .expect( validWikitextResponse( '{"a":4,"b":3}' ) ) @@ -1137,7 +1149,7 @@ describe( '/transform/ endpoint', function () { headers: { 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"' }, - body: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n' + body: htmlOfMainPageWithDataParsoid } } ) .expect( validWikitextResponse() ) @@ -1148,7 +1160,7 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/html/to/wikitext/Main_Page' ) .send( { - html: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n' + html: htmlOfMainPageWithDataParsoid } ) .expect( validWikitextResponse() ) .end( done ); @@ -1158,7 +1170,7 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/html/to/wikitext/' ) .send( { - html: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n', + html: htmlOfMainPageWithDataParsoid, original: { title: 'Main_Page' } @@ -1171,7 +1183,7 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/html/to/wikitext/Main_Page/1' ) .send( { - html: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n' + html: htmlOfMainPageWithDataParsoid } ) .expect( validWikitextResponse() ) .end( done ); @@ -1181,7 +1193,7 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/html/to/wikitext/' ) .send( { - html: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n', + html: htmlOfMainPageWithDataParsoid, original: { revid: 1 } @@ -1194,7 +1206,7 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/html/to/wikitext/' ) .send( { - html: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n', + html: htmlOfMainPageWithDataParsoid, original: { wikitext: { headers: { @@ -1213,38 +1225,19 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/pagebundle/to/wikitext/' ) .send( { - html: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n', + html: htmlOfMainPageWithDataParsoid, original: { html: { headers: { 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/' + defaultContentVersion + '"' }, - body: "\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User's Guide for information on using the wiki software.

\n\n

Getting started

\n" + body: htmlOfMainPageOriginal }, 'data-parsoid': { headers: { 'content-type': 'application/json;profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/' + defaultContentVersion + '"' }, - body: { - counter: 14, - ids: { - mwAA: { dsr: [ 0, 592, 0, 0 ] }, - mwAQ: { dsr: [ 0, 59, 0, 0 ] }, - mwAg: { stx: 'html', dsr: [ 0, 59, 8, 9 ] }, - mwAw: { dsr: [ 61, 171, 0, 0 ] }, - mwBA: { dsr: [ 73, 127, 41, 1 ] }, - mwBQ: { dsr: [ 173, 194, 2, 2 ] }, - mwBg: { dsr: [ 195, 592, 0, 0 ] }, - mwBw: { dsr: [ 195, 300, 1, 0 ] }, - mwCA: { dsr: [ 197, 300, 75, 1 ] }, - mwCQ: { dsr: [ 301, 373, 1, 0 ] }, - mwCg: { dsr: [ 303, 373, 56, 1 ] }, - mwCw: { dsr: [ 374, 472, 1, 0 ] }, - mwDA: { dsr: [ 376, 472, 65, 1 ] }, - mwDQ: { dsr: [ 473, 592, 1, 0 ] }, - mwDg: { dsr: [ 475, 592, 80, 1 ] } - } - } + body: dataParsoidOfMainPageOriginal } } } ) @@ -1257,38 +1250,19 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/pagebundle/to/wikitext/' ) .send( { - html: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n', + html: htmlOfMainPageWithDataParsoid_1_1_1, original: { html: { headers: { 'content-type': 'text/html; profile="mediawiki.org/specs/html/1.1.1"' }, - body: "\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User's Guide for information on using the wiki software.

\n\n

Getting started

\n" + body: htmlOfMainPageOriginal }, 'data-parsoid': { headers: { 'content-type': 'application/json;profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/0.0.1"' }, - body: { - counter: 14, - ids: { - mwAA: { dsr: [ 0, 592, 0, 0 ] }, - mwAQ: { dsr: [ 0, 59, 0, 0 ] }, - mwAg: { stx: 'html', dsr: [ 0, 59, 8, 9 ] }, - mwAw: { dsr: [ 61, 171, 0, 0 ] }, - mwBA: { dsr: [ 73, 127, 41, 1 ] }, - mwBQ: { dsr: [ 173, 194, 2, 2 ] }, - mwBg: { dsr: [ 195, 592, 0, 0 ] }, - mwBw: { dsr: [ 195, 300, 1, 0 ] }, - mwCA: { dsr: [ 197, 300, 75, 1 ] }, - mwCQ: { dsr: [ 301, 373, 1, 0 ] }, - mwCg: { dsr: [ 303, 373, 56, 1 ] }, - mwCw: { dsr: [ 374, 472, 1, 0 ] }, - mwDA: { dsr: [ 376, 472, 65, 1 ] }, - mwDQ: { dsr: [ 473, 592, 1, 0 ] }, - mwDg: { dsr: [ 475, 592, 80, 1 ] } - } - } + body: dataParsoidOfMainPageOriginal } } } ) @@ -1302,38 +1276,19 @@ describe( '/transform/ endpoint', function () { .post( endpointPrefix + '/transform/pagebundle/to/wikitext/' ) .send( { // Don't set the mw:html:version so that we get it from the original/headers - html: '\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User\'s Guide for information on using the wiki software.

\n\n

Getting started

\n', + html: htmlOfMainPageWithDataParsoid, original: { html: { headers: { 'content-type': 'text/html; profile="mediawiki.org/specs/html/1.1.1"' }, - body: "\nMain_Page

MediaWiki has been successfully installed.

\n\n

Consult the User's Guide for information on using the wiki software.

\n\n

Getting started

\n" + body: htmlOfMainPageOriginal }, 'data-parsoid': { headers: { 'content-type': 'application/json;profile="https://www.mediawiki.org/wiki/Specs/data-parsoid/0.0.1"' }, - body: { - counter: 14, - ids: { - mwAA: { dsr: [ 0, 592, 0, 0 ] }, - mwAQ: { dsr: [ 0, 59, 0, 0 ] }, - mwAg: { stx: 'html', dsr: [ 0, 59, 8, 9 ] }, - mwAw: { dsr: [ 61, 171, 0, 0 ] }, - mwBA: { dsr: [ 73, 127, 41, 1 ] }, - mwBQ: { dsr: [ 173, 194, 2, 2 ] }, - mwBg: { dsr: [ 195, 592, 0, 0 ] }, - mwBw: { dsr: [ 195, 300, 1, 0 ] }, - mwCA: { dsr: [ 197, 300, 75, 1 ] }, - mwCQ: { dsr: [ 301, 373, 1, 0 ] }, - mwCg: { dsr: [ 303, 373, 56, 1 ] }, - mwCw: { dsr: [ 374, 472, 1, 0 ] }, - mwDA: { dsr: [ 376, 472, 65, 1 ] }, - mwDQ: { dsr: [ 473, 592, 1, 0 ] }, - mwDg: { dsr: [ 475, 592, 80, 1 ] } - } - } + body: dataParsoidOfMainPageOriginal } } } ) @@ -1747,7 +1702,7 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/pagebundle/to/wikitext/' ) .send( { - html: '

', + html: htmlOfImage, original: { title: 'Doesnotexist', 'data-parsoid': { @@ -1773,7 +1728,7 @@ describe( '/transform/ endpoint', function () { headers: { 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"' }, - body: '

' + body: htmlOfImage } } } ) @@ -1786,7 +1741,7 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/pagebundle/to/wikitext/' ) .send( { - html: '

', + html: htmlOfImageWithDataMW, 'data-mw': { body: { ids: { @@ -1819,7 +1774,7 @@ describe( '/transform/ endpoint', function () { headers: { 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"' }, - body: '

' + body: htmlOfImage } } } ) @@ -1832,7 +1787,7 @@ describe( '/transform/ endpoint', function () { client.req .post( endpointPrefix + '/transform/pagebundle/to/wikitext/' ) .send( { - html: '

', + html: htmlOfImage, 'data-mw': { body: { ids: { @@ -1865,7 +1820,7 @@ describe( '/transform/ endpoint', function () { headers: { 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/999.0.0"' }, - body: '

' + body: htmlOfImage } } } ) @@ -1904,10 +1859,12 @@ describe( '/transform/ endpoint', function () { // Support for transforming from/to pagebundle is disabled in production. it.skip( 'should fail to downgrade the original version for an unknown transition', function ( done ) { + const htmlOfMinimal = getTextFromFile( 'Minimal.html' ); + const htmlOfMinimal2222 = getTextFromFile( 'Minimal-2222.html' ); client.req .post( endpointPrefix + '/transform/pagebundle/to/wikitext/' ) .send( { - html: '\n123', + html: htmlOfMinimal, original: { title: 'Doesnotexist', 'data-parsoid': { body: { ids: {} } }, @@ -1915,7 +1872,7 @@ describe( '/transform/ endpoint', function () { headers: { 'content-type': 'text/html;profile="https://www.mediawiki.org/wiki/Specs/HTML/2222.0.0"' }, - body: '\n123' + body: htmlOfMinimal2222 } } } ) diff --git a/tests/api-testing/data/Transform/Image-data-mw.html b/tests/api-testing/data/Transform/Image-data-mw.html new file mode 100644 index 00000000000..e2051582de4 --- /dev/null +++ b/tests/api-testing/data/Transform/Image-data-mw.html @@ -0,0 +1 @@ +

diff --git a/tests/api-testing/data/Transform/Image.html b/tests/api-testing/data/Transform/Image.html new file mode 100644 index 00000000000..e1ef31aef1f --- /dev/null +++ b/tests/api-testing/data/Transform/Image.html @@ -0,0 +1 @@ +

diff --git a/tests/api-testing/data/Transform/JsonConfig.html b/tests/api-testing/data/Transform/JsonConfig.html new file mode 100644 index 00000000000..13479319177 --- /dev/null +++ b/tests/api-testing/data/Transform/JsonConfig.html @@ -0,0 +1,2 @@ + +
a4
b3
\ No newline at end of file diff --git a/tests/api-testing/data/Transform/MainPage-data-parsoid-1.1.1.html b/tests/api-testing/data/Transform/MainPage-data-parsoid-1.1.1.html new file mode 100644 index 00000000000..815618b4d19 --- /dev/null +++ b/tests/api-testing/data/Transform/MainPage-data-parsoid-1.1.1.html @@ -0,0 +1,10 @@ + +Main_Page

MediaWiki has been successfully installed.

+ +

Consult the User's Guide for information on using the wiki software.

+ +

Getting started

+ \ No newline at end of file diff --git a/tests/api-testing/data/Transform/MainPage-data-parsoid.html b/tests/api-testing/data/Transform/MainPage-data-parsoid.html new file mode 100644 index 00000000000..1dfcba04a60 --- /dev/null +++ b/tests/api-testing/data/Transform/MainPage-data-parsoid.html @@ -0,0 +1,10 @@ + +Main_Page

MediaWiki has been successfully installed.

+ +

Consult the User's Guide for information on using the wiki software.

+ +

Getting started

+ \ No newline at end of file diff --git a/tests/api-testing/data/Transform/MainPage-original.data-parsoid b/tests/api-testing/data/Transform/MainPage-original.data-parsoid new file mode 100644 index 00000000000..7b0c85ceed9 --- /dev/null +++ b/tests/api-testing/data/Transform/MainPage-original.data-parsoid @@ -0,0 +1,20 @@ +{ + "counter": 14, + "ids": { + "mwAA": { "dsr": [ 0, 592, 0, 0 ] }, + "mwAQ": { "dsr": [ 0, 59, 0, 0 ] }, + "mwAg": { "stx": "html", "dsr": [ 0, 59, 8, 9 ] }, + "mwAw": { "dsr": [ 61, 171, 0, 0 ] }, + "mwBA": { "dsr": [ 73, 127, 41, 1 ] }, + "mwBQ": { "dsr": [ 173, 194, 2, 2 ] }, + "mwBg": { "dsr": [ 195, 592, 0, 0 ] }, + "mwBw": { "dsr": [ 195, 300, 1, 0 ] }, + "mwCA": { "dsr": [ 197, 300, 75, 1 ] }, + "mwCQ": { "dsr": [ 301, 373, 1, 0 ] }, + "mwCg": { "dsr": [ 303, 373, 56, 1 ] }, + "mwCw": { "dsr": [ 374, 472, 1, 0 ] }, + "mwDA": { "dsr": [ 376, 472, 65, 1 ] }, + "mwDQ": { "dsr": [ 473, 592, 1, 0 ] }, + "mwDg": { "dsr": [ 475, 592, 80, 1 ] } + } +} diff --git a/tests/api-testing/data/Transform/MainPage-original.html b/tests/api-testing/data/Transform/MainPage-original.html new file mode 100644 index 00000000000..b81a19f5caf --- /dev/null +++ b/tests/api-testing/data/Transform/MainPage-original.html @@ -0,0 +1,10 @@ + +Main_Page

MediaWiki has been successfully installed.

+ +

Consult the User's Guide for information on using the wiki software.

+ +

Getting started

+ \ No newline at end of file diff --git a/tests/api-testing/data/Transform/Minimal-2222.html b/tests/api-testing/data/Transform/Minimal-2222.html new file mode 100644 index 00000000000..4fc1f5a5aa6 --- /dev/null +++ b/tests/api-testing/data/Transform/Minimal-2222.html @@ -0,0 +1,2 @@ + +123 \ No newline at end of file diff --git a/tests/api-testing/data/Transform/Minimal.html b/tests/api-testing/data/Transform/Minimal.html new file mode 100644 index 00000000000..2725aca3d3b --- /dev/null +++ b/tests/api-testing/data/Transform/Minimal.html @@ -0,0 +1,2 @@ + +123 \ No newline at end of file