Skip to content

Commit

Permalink
Transform test clean-up
Browse files Browse the repository at this point in the history
Remove request/response pairs and associated loading logic.
  • Loading branch information
gwicke committed Feb 13, 2015
1 parent 4ebe2d5 commit ebc31e2
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,9 @@
// mocha defines to avoid JSHint breakage
/* global describe, it, before, beforeEach, after, afterEach */

var assert = require('../../../utils/assert.js');
var server = require('../../../utils/server.js');
var assert = require('../../utils/assert.js');
var server = require('../../utils/server.js');
var preq = require('preq');
var fs = require('fs');

// read the contents of a spec file as JSON or raw HTML
function readFile(filename) {
var contents = fs.readFileSync(filename, { encoding: 'utf8' });

// readFileSync seems to append a line feed
contents = contents.replace(/\n$/, "");

if (/\.json$/.test(filename)) {
return JSON.parse(contents);
} else {
return contents;
}
}

// find dirs matching the pattern "{foo}2{bar}"
function findSpecDirs() {
var specDirs = [];
var specDirPattern = /^(.+)2(.+)$/;
function isDir(x) {
return fs.statSync(x).isDirectory();
}
function isSpecDir(x) {
return isDir(__dirname + '/' + x) && specDirPattern.test(x);
}
var dirs = fs.readdirSync(__dirname);
dirs.forEach(function(dir) {
if (isSpecDir(dir)) {
var match = specDirPattern.exec(dir);
var fromFormat = match[1];
var toFormat = match[2];
specDirs.push({
name: fromFormat + '2' + toFormat,
fromFormat: fromFormat,
toFormat: toFormat,
src: __dirname + '/' + dir
});
}
});
return specDirs;
}

// for each dir that looks like it contains req/res specs, find the specs
function findSpecs() {
var specs = [];
findSpecDirs().forEach(function (specDir) {
var files = fs.readdirSync(specDir.src);
var request = null;
var response = null;
files.forEach(function(file2) {
if (/^request\./.test(file2)) {
request = specDir.src + '/' + file2;
} else if (/^response\./.test(file2)) {
response = specDir.src + '/' + file2;
}
});
if (request !== null && response !== null) {
specs.push({
name: specDir.name,
from: { format: specDir.fromFormat, src: request },
to: { format: specDir.toFormat, src: response }
});
}

});
return specs;
}

function x2y(spec) {
function test() {
return preq.post({
uri: server.config.baseURL + '/transform/' + spec.from.format + '/to/' + spec.to.format,
headers: {
'content-type': /\.html$/.test(spec.from.src) ?
'text/html' : 'application/json'
},
body: {
// FIXME: use format name
content: readFile(spec.from.src)
}
})
.then(function(res) {
assert.deepEqual(res.status, 200);
assert.deepEqual(res.body, readFile(spec.to.src));
});
}
describe('transform api: ' + spec.name, function() {
this.timeout(20000);
before(function () { return server.start(); });
it('should directly convert ' + spec.from.format + ' to ' + spec.to.format, test);
});
}

var testPage = {
title: 'User:GWicke%2F_restbase_test',
Expand Down
31 changes: 0 additions & 31 deletions test/features/parsoid/transform/html2html/request.json

This file was deleted.

2 changes: 0 additions & 2 deletions test/features/parsoid/transform/html2html/response.html

This file was deleted.

31 changes: 0 additions & 31 deletions test/features/parsoid/transform/html2wikitext/request.json

This file was deleted.

8 changes: 0 additions & 8 deletions test/features/parsoid/transform/html2wikitext/response.json

This file was deleted.

8 changes: 0 additions & 8 deletions test/features/parsoid/transform/wikitext2html/request.json

This file was deleted.

2 changes: 0 additions & 2 deletions test/features/parsoid/transform/wikitext2html/response.html

This file was deleted.

0 comments on commit ebc31e2

Please sign in to comment.