Skip to content

Commit

Permalink
Revert "switched from mocha to ava"
Browse files Browse the repository at this point in the history
This reverts commit 10c859c.
  • Loading branch information
BenjaminEckardt committed Jun 10, 2017
1 parent 10c859c commit 71cc9f0
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 195 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -5,7 +5,7 @@
"main": "dom-processor.js",
"scripts": {
"pretest": "jshint **/*.js",
"test": "ava"
"test": "mocha test/**/*.test.js"
},
"repository": {
"type": "git",
Expand All @@ -24,9 +24,9 @@
"cheerio": "0.22.0"
},
"devDependencies": {
"ava": "~0.19.1",
"coveralls": "~2.11.12",
"istanbul": "~0.4.5",
"jshint": "~2.9.3"
"jshint": "~2.9.3",
"mocha": "~3.0.2"
}
}
3 changes: 2 additions & 1 deletion test/.jshintrc
@@ -1,9 +1,10 @@
{
"esversion": 6,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"mocha": true,
"node": true,
"strict": true,
"unused": true,
"undef": true
}
50 changes: 27 additions & 23 deletions test/basic.test.js
@@ -1,27 +1,31 @@
import test from 'ava';
import DomProcessor from '../dom-processor';
'use strict';
var assert = console.assert;
var DomProcessor = require('../dom-processor');

test('replacement of div with span', t => {
const processor = createDivToSpanProcessor();
const result = processor.process('<div></div>');
t.is(result, '<span></span>');
});

test('unchanged non-matching elements', t => {
const processor = createDivToSpanProcessor();
const result = processor.process('<p></p>');
t.is(result, '<p></p>');
});
describe('basic configuration', function() {

const createDivToSpanProcessor = () => {
const configLoader = {
load: () => {
return [{
selector: 'div',
replace: () => { return '<span></span>'; }
}];
var configLoader = {
load: function() {
return [{
selector: 'div',
replace: function() {
return '<span></span>';
}
};
}];
}
};

var processor = new DomProcessor(configLoader);

return new DomProcessor(configLoader);
};
it('should replace <div> with <span>', function() {
var result = processor.process('<div></div>');

assert(result === '<span></span>');
});

it('should leave unmatched elements unchanged', function() {
var result = processor.process('<p></p>');

assert(result === '<p></p>');
});
});
62 changes: 32 additions & 30 deletions test/current-path.test.js
@@ -1,36 +1,38 @@
import test from 'ava';
import DomProcessor from '../dom-processor';
'use strict';
var assert = console.assert;
var DomProcessor = require('../dom-processor');

const A_PATH = 'aPath';
const ANOTHER_PATH = 'anotherPath';
describe('configuration using current path', function() {
var FILE = 'aFile';
var ANOTHER_FILE = 'anotherFile';

test('replacement of path dependent configuration', t => {
t.plan(2);
var configLoader = {
load: function(currentPath) {
if(currentPath === FILE) {
return [{
selector: 'div',
replace: function() { return '<span></span>'; }
}];
} else {
return [{
selector: 'div',
replace: function() { return '<p></p>'; }
}];
}
}
};

const processor = createPathDependentProcessor();
let result = processor.process('<div></div>', A_PATH);
t.is(result, '<span></span>');
var processor = new DomProcessor(configLoader);

result = processor.process('<div></div>', ANOTHER_PATH);
t.is(result, '<p></p>');
});
it('should replace <div> with <span>', function() {
var result = processor.process('<div></div>', FILE);

assert(result === '<span></span>');
});

const createPathDependentProcessor = () => {
const configLoader = {
load: (currentPath) => {
if(currentPath === A_PATH) {
return [{
selector: 'div',
replace: () => { return '<span></span>'; }
}];
} else {
return [{
selector: 'div',
replace: () => { return '<p></p>'; }
}];
}
}
};
it('should replace <div> with <p>', function() {
var result = processor.process('<div></div>', ANOTHER_FILE);

return new DomProcessor(configLoader);
};
assert(result === '<p></p>');
});
});
42 changes: 22 additions & 20 deletions test/element-attribute.test.js
@@ -1,24 +1,26 @@
import test from 'ava';
import DomProcessor from '../dom-processor';
'use strict';
var assert = console.assert;
var DomProcessor = require('../dom-processor');

test('replacement using attributes of input element', t => {
const processor = createAttributeUsingProcessor();
const result = processor.process('<div id="foo"></div>');
t.is(result, '<span id="foo"></span>');
});
describe('configuration using attributes of selected elements', function() {

const createAttributeUsingProcessor = () => {
const configLoader = {
load: () => {
return [{
selector: 'div',
replace: ($element) => {
const id = $element.attr('id');
return `<span id=${id}></span`;
}
}];
var configLoader = {
load: function() {
return [{
selector: 'div',
replace: function($element) {
var id = $element.attr('id');
return '<span id="' + id + '"></span>';
}
};
}];
}
};

var processor = new DomProcessor(configLoader);

return new DomProcessor(configLoader);
};
it('should replace <div> with <span> and keep the `id`', function() {
var result = processor.process('<div id="foo"></div>');

assert(result === '<span id="foo"></span>');
});
});
117 changes: 58 additions & 59 deletions test/load-configuration.test.js
@@ -1,60 +1,59 @@
import test from 'ava';
import DomProcessor from '../dom-processor';

test('decode entities (replace & with &amp;)', t => {
const processor = createDecodingProcessor();
const result = processor.process('&&');
t.is(result, '&amp;&amp;');
});

test('not decode entities (not replace & with &amp;)', t => {
const processor = createNonDecodingProcessor();
const result = processor.process('&&');
t.is(result, '&&');
});

test('replace <div> with <span> and decode entities', t => {
const processor = createDecodingProcessor();
const result = processor.process('<div></div>');
t.is(result, '<span>&amp;&amp;</span>');
});

test('replace <div> with <span> and not decode entities', t => {
const processor = createNonDecodingProcessor();
const result = processor.process('<div></div>');
t.is(result, '<span>&&</span>');
});

test('leave unmatched elements unchanged and decode entities', t => {
const processor = createDecodingProcessor();
const result = processor.process('<p>&&</p>');
t.is(result, '<p>&amp;&amp;</p>');
'use strict';
var assert = console.assert;
var DomProcessor = require('../dom-processor');

describe('load configuration', function() {

var configLoader = {
load: function() {
return [{
selector: 'div',
replace: function() {
return '<span>&&</span>';
}
}];
}
};

var processor = new DomProcessor(configLoader);

it('should decode entities (replace & with &amp;)', function() {
configLoader.loadConfigurations = {decodeEntities: true};
var result = processor.process('&&');
assert(result === '&amp;&amp;');
});

it('should not decode entities (not replace & with &amp;)', function() {
configLoader.loadConfigurations = {decodeEntities: false};
var result = processor.process('&&');
assert(result === '&&');
});

it('should replace <div> with <span> and decode entities', function() {
configLoader.loadConfigurations = {decodeEntities: true};
var result = processor.process('<div></div>');

assert(result === '<span>&amp;&amp;</span>');
});

it('should replace <div> with <span> and not decode entities', function() {
configLoader.loadConfigurations = {decodeEntities: false};
var result = processor.process('<div></div>');

assert(result === '<span>&&</span>');
});

it('should leave unmatched elements unchanged and decode entities', function() {
configLoader.loadConfigurations = {decodeEntities: true};
var result = processor.process('<p>&&</p>');

assert(result === '<p>&amp;&amp;</p>');
});

it('should leave unmatched elements unchanged and not decode entities', function() {
configLoader.loadConfigurations = {decodeEntities: false};
var result = processor.process('<p>&&</p>');

assert(result === '<p>&&</p>');
});
});

test('leave unmatched elements unchanged and not decode entities', t => {
const processor = createNonDecodingProcessor();
const result = processor.process('<p>&&</p>');
t.is(result, '<p>&&</p>');
});

const createDecodingProcessor = () => {
return createProcessor(true);
};

const createNonDecodingProcessor = () => {
return createProcessor(false);
};

const createProcessor = (decodeEntities) => {
const configLoader = {
load: () => {
return [{
selector: 'div',
replace: () => { return '<span>&&</span>'; }
}];
},
loadConfigurations: { decodeEntities }
};

return new DomProcessor(configLoader);
};
41 changes: 22 additions & 19 deletions test/multiple-element.test.js
@@ -1,27 +1,30 @@
import test from 'ava';
import DomProcessor from '../dom-processor';
'use strict';
var assert = console.assert;
var DomProcessor = require('../dom-processor');

test('replace `<div text="test">` with `test`', t => {
const processor = createAttributeExtractingProcessor();
const result = processor.process('<div text="test">');
t.is(result, 'test');
});
describe('multiple element test (replace function should get the corresponding element)', function() {

test('replace multiple matching elements with corresponding attribute content', t => {
const processor = createAttributeExtractingProcessor();
const result = processor.process('<div text="first"></div><div text="second"></div>');
t.is(result, 'firstsecond');
});

const createAttributeExtractingProcessor = () => {
const configLoader = {
load: () => {
var configLoader = {
load: function() {
return [{
selector: 'div',
replace: ($element) => { return $element.attr('text'); }
replace: function($element) {
return $element.attr('text');
}
}];
}
};

return new DomProcessor(configLoader);
};
var processor = new DomProcessor(configLoader);

it('should replace <div text="test"> with test', function() {
var result = processor.process('<div text="test"></div>');

assert(result === 'test');
});

it('should replace <div text="test"></div><div text="-secondtest"></div> with test-secondtest', function() {
var result = processor.process('<div text="test"></div><div text="-secondtest"></div>');
assert(result === 'test-secondtest');
});
});

0 comments on commit 71cc9f0

Please sign in to comment.