morphdom
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -6,4 +6,9 @@ { | ||
"scripts": { | ||
"test": "npm run test-browser && node_modules/.bin/jshint lib/", | ||
"test-browser": "node test/mocha-phantomjs/run.js", | ||
"test": "npm run test-browser && npm run lint", | ||
"benchmark": "npm run benchmark-browser", | ||
"all": "npm run all-browser && npm run lint", | ||
"lint": "jshint lib/", | ||
"test-browser": "node test/mocha-phantomjs/run.js test", | ||
"benchmark-browser": "node test/mocha-phantomjs/run.js benchmark", | ||
"all-browser": "node test/mocha-phantomjs/run.js test benchmark", | ||
"mocha-phantomjs": "node test/mocha-phantomjs/run.js", | ||
@@ -30,3 +35,3 @@ "mocha-phantomjs-run": "mocha-phantomjs ./test/mocha-phantomjs/generated/test-page.html" | ||
"dependencies": {}, | ||
"version": "0.1.6" | ||
"version": "0.1.7" | ||
} |
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var morphdom = require('../../lib/index'); | ||
var resultTemplate = require('./result.marko'); | ||
var resultTemplate = require('./test-result.marko'); | ||
@@ -12,3 +12,2 @@ function parseHtml(html) { | ||
function serializeNode(node) { | ||
@@ -192,3 +191,3 @@ var html = ''; | ||
containerEl.innerHTML = resultHtml; | ||
document.getElementById('test').appendChild(containerEl); | ||
document.getElementById('test-results').appendChild(containerEl); | ||
// console.log('elLookupBefore: ', elLookupBefore); | ||
@@ -253,116 +252,121 @@ | ||
describe('morphdom' , function() { | ||
this.timeout(0); | ||
function addTests() { | ||
describe('morphdom' , function() { | ||
this.timeout(0); | ||
beforeEach(function() { | ||
}); | ||
beforeEach(function() { | ||
}); | ||
describe('auto tests', function() { | ||
var autoTests = require('../mocha-phantomjs/generated/auto-tests'); | ||
describe('auto tests', function() { | ||
var autoTests = require('../mocha-phantomjs/generated/auto-tests'); | ||
Object.keys(autoTests).forEach(function(name) { | ||
var test = autoTests[name]; | ||
var itFunc = test.only ? it.only : it; | ||
Object.keys(autoTests).forEach(function(name) { | ||
var test = autoTests[name]; | ||
var itFunc = test.only ? it.only : it; | ||
itFunc(name, function() { | ||
runTest(name, test); | ||
itFunc(name, function() { | ||
runTest(name, test); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('should transform a simple el', function() { | ||
var el1 = document.createElement('div'); | ||
el1.className = 'foo'; | ||
it('should transform a simple el', function() { | ||
var el1 = document.createElement('div'); | ||
el1.className = 'foo'; | ||
var el2 = document.createElement('div'); | ||
el2.className = 'bar'; | ||
var el2 = document.createElement('div'); | ||
el2.className = 'bar'; | ||
morphdom(el1, el2); | ||
morphdom(el1, el2); | ||
expect(el1.className).to.equal('bar'); | ||
}); | ||
expect(el1.className).to.equal('bar'); | ||
}); | ||
it('should transform an text input el', function() { | ||
var el1 = document.createElement('input'); | ||
el1.type = 'text'; | ||
el1.value = 'Hello World'; | ||
it('should transform an text input el', function() { | ||
var el1 = document.createElement('input'); | ||
el1.type = 'text'; | ||
el1.value = 'Hello World'; | ||
var el2 = document.createElement('input'); | ||
el2.setAttribute('type', 'text'); | ||
el2.setAttribute('value', 'Hello World 2'); | ||
var el2 = document.createElement('input'); | ||
el2.setAttribute('type', 'text'); | ||
el2.setAttribute('value', 'Hello World 2'); | ||
morphdom(el1, el2); | ||
morphdom(el1, el2); | ||
expect(el1.value).to.equal('Hello World 2'); | ||
}); | ||
expect(el1.value).to.equal('Hello World 2'); | ||
}); | ||
it('should transform a checkbox input el', function() { | ||
var el1 = document.createElement('input'); | ||
el1.type = 'checkbox'; | ||
el1.setAttribute('checked', ''); | ||
el1.checked = false; | ||
it('should transform a checkbox input el', function() { | ||
var el1 = document.createElement('input'); | ||
el1.type = 'checkbox'; | ||
el1.setAttribute('checked', ''); | ||
el1.checked = false; | ||
var el2 = document.createElement('input'); | ||
el2.setAttribute('type', 'text'); | ||
el2.setAttribute('checked', ''); | ||
var el2 = document.createElement('input'); | ||
el2.setAttribute('type', 'text'); | ||
el2.setAttribute('checked', ''); | ||
morphdom(el1, el2); | ||
morphdom(el1, el2); | ||
expect(el1.checked).to.equal(true); | ||
}); | ||
expect(el1.checked).to.equal(true); | ||
}); | ||
it('should transform an incompatible node and maintain the same parent', function() { | ||
var parentEl = document.createElement('div'); | ||
it('should transform an incompatible node and maintain the same parent', function() { | ||
var parentEl = document.createElement('div'); | ||
var el1 = document.createElement('input'); | ||
el1.type = 'text'; | ||
el1.value = 'Hello World'; | ||
parentEl.appendChild(el1); | ||
var el1 = document.createElement('input'); | ||
el1.type = 'text'; | ||
el1.value = 'Hello World'; | ||
parentEl.appendChild(el1); | ||
var el2 = document.createElement('p'); | ||
var morphedNode = morphdom(el1, el2); | ||
var el2 = document.createElement('p'); | ||
var morphedNode = morphdom(el1, el2); | ||
expect(morphedNode.parentNode).to.equal(parentEl); | ||
}); | ||
expect(morphedNode.parentNode).to.equal(parentEl); | ||
}); | ||
it('should handle the "disabled" attribute correctly', function() { | ||
var el1 = document.createElement('input'); | ||
el1.disabled = true; | ||
it('should handle the "disabled" attribute correctly', function() { | ||
var el1 = document.createElement('input'); | ||
el1.disabled = true; | ||
el1.value = 'Hello World'; | ||
el1.value = 'Hello World'; | ||
var el2 = document.createElement('input'); | ||
el2.setAttribute('value', 'Hello World 2'); | ||
var el2 = document.createElement('input'); | ||
el2.setAttribute('value', 'Hello World 2'); | ||
morphdom(el1, el2); | ||
morphdom(el1, el2); | ||
expect(el2.disabled).to.equal(false); | ||
}); | ||
expect(el2.disabled).to.equal(false); | ||
}); | ||
it('should allow morphing to be skipped for a node', function() { | ||
var el1a = document.createElement('div'); | ||
var el1b = document.createElement('b'); | ||
el1b.setAttribute('class', 'foo'); | ||
el1a.appendChild(el1b); | ||
it('should allow morphing to be skipped for a node', function() { | ||
var el1a = document.createElement('div'); | ||
var el1b = document.createElement('b'); | ||
el1b.setAttribute('class', 'foo'); | ||
el1a.appendChild(el1b); | ||
var el2a = document.createElement('div'); | ||
var el2b = document.createElement('b'); | ||
el2b.setAttribute('class', 'bar'); | ||
el2a.appendChild(el2b); | ||
var el2a = document.createElement('div'); | ||
var el2b = document.createElement('b'); | ||
el2b.setAttribute('class', 'bar'); | ||
el2a.appendChild(el2b); | ||
morphdom(el1a, el2a, { | ||
onBeforeMorphEl: function(el) { | ||
if (el.tagName === 'B') { | ||
return false; | ||
morphdom(el1a, el2a, { | ||
onBeforeMorphEl: function(el) { | ||
if (el.tagName === 'B') { | ||
return false; | ||
} | ||
} | ||
} | ||
}); | ||
expect(el1a.childNodes[0].className).to.equal('foo'); | ||
}); | ||
expect(el1a.childNodes[0].className).to.equal('foo'); | ||
}); | ||
}); | ||
} | ||
if (require('../mocha-phantomjs/generated/config').runTests === true) { | ||
addTests(); | ||
} | ||
@@ -5,6 +5,6 @@ { | ||
"mocha/mocha.css", | ||
"require-run: ./client-setup", | ||
"require-run: ../browser/*.js", | ||
"require-run: ./client" | ||
"require-run: ./mocha-browser-setup", | ||
"require-run: ../browser/test.js", | ||
"require-run: ../browser/benchmark.js" | ||
] | ||
} |
@@ -41,2 +41,15 @@ require('marko/node-require').install(); | ||
var testConfig = { | ||
runBenchmarks: false, | ||
runTests: false, | ||
}; | ||
for (var i=2; i<process.argv.length; i++) { | ||
if (process.argv[i] === 'test') { | ||
testConfig.runTests = true; | ||
} else if (process.argv[i] === 'benchmark') { | ||
testConfig.runBenchmarks = true; | ||
} | ||
} | ||
function generateHtmlStringsFile() { | ||
@@ -73,6 +86,16 @@ | ||
function run() { | ||
var isBenchmark = process.argv[2] === 'benchmark'; | ||
console.log('Preparing client-side tests...'); | ||
console.log('Config:', testConfig); | ||
generateHtmlStringsFile(); | ||
fs.writeFileSync( | ||
path.join(outputDir, 'config.js'), | ||
'module.exports=' + JSON.stringify(testConfig, null, 4) + ';\n', | ||
{encoding: 'utf8' }); | ||
running = true; | ||
@@ -82,2 +105,3 @@ fileModified = false; | ||
var pageTemplate = require('./test-page.marko'); | ||
var pageHtmlFile = path.join(outputDir, 'test-page.html'); | ||
@@ -92,3 +116,6 @@ | ||
'npm', | ||
['run', 'mocha-phantomjs-run', '--loglevel=silent'], | ||
[ | ||
'run', | ||
'mocha-phantomjs-run', | ||
'--loglevel=silent'], | ||
{ | ||
@@ -95,0 +122,0 @@ cwd: rootDir, |
Sorry, the diff of this file is not supported yet
103873
73
789