Permalink
Browse files

Switch from JsTestDriver to QUnit.

  • Loading branch information...
1 parent 0c151e1 commit 0fe596c1907a8f0296548168ef0726b76de0fa38 @zachleat committed Nov 14, 2012
Showing with 2,360 additions and 140 deletions.
  1. +0 −4 test.bat
  2. +0 −5 test.sh
  3. +0 −6 test/bigtext.conf
  4. +132 −121 test/bigtextTest.js
  5. BIN test/lib/JsTestDriver-1.2.2-custom.jar
  6. +0 −4 test/lib/launch-safari.sh
  7. +235 −0 test/lib/qunit-1.10.0.css
  8. +1,977 −0 test/lib/qunit-1.10.0.js
  9. +16 −0 test/test.html
View
@@ -1,4 +0,0 @@
-rem Usage: JsTestDriver.bat TestName
-rem where TestName is a directory and TestName.conf in the root.
-
-java -jar test/lib/JsTestDriver-1.2.2-custom.jar --config "test/bigtext.conf" --browser "C:\Program Files\Internet Explorer\iexplore.exe" --tests all --port 8081
View
@@ -1,5 +0,0 @@
-# Usage: ./JsTestDriver.sh TestName
-# where TestName is a directory and TestName.conf in the root.
-
-java -jar test/lib/JsTestDriver-1.2.2-custom.jar --config "test/bigtext.conf" --browser "test/lib/launch-safari.sh" --tests all --port 8081
-osascript -e 'tell application "Safari" to quit' > /dev/null 2>&1
View
@@ -1,6 +0,0 @@
-server: http://localhost:8081
-
-load:
- - lib/jquery-1.4.2.js
- - ../bigtext.js
- - bigtextTest.js
View
@@ -1,68 +1,37 @@
-BigTextTest = TestCase('BigTextTest');
-
-BigTextTest.prototype.tolerance = 6;
+var BigTextTest = {};
+BigTextTest.tolerance = 6;
// If the lines of text are blocks, testing their width will tell us nothing.
-BigTextTest.prototype.init = function() {
+BigTextTest.init = function()
+{
return this.css({
float: 'left',
clear: 'left'
});
};
-BigTextTest.prototype.testExists = function(){
- assertTrue(!!BigText);
- assertTrue(!!$.fn.bigtext);
-};
-
-BigTextTest.prototype.testStyleInjection = function()
-{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
- $('#test').bigtext();
-
- assertTrue('Test to make sure the style tag was inserted.', $('#' + BigText.getStyleId('test')).length === 1);
-};
-
-BigTextTest.prototype.testDoubleStyleInjection = function()
-{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
- $('#test').bigtext().bigtext();
-
- // FIXME this jQuery result won't return more than one element.
- assertTrue('Test to make sure the style tag wasn\'t inserted twice.', $('#' + BigText.getStyleId('test')).length === 1);
-};
-
-
-BigTextTest.prototype.testCleanup = function()
-{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
- $('#test').bigtext();
-
- assertTrue('Clone should be deleted.', $('.bigtext-cloned').length === 0);
-};
-
-BigTextTest.prototype.linesTest = function(selector, expectedWidth, options)
+BigTextTest.linesTest = function(selector, expectedWidth, options)
{
- var tolerance = this.tolerance,
+ var tolerance = BigTextTest.tolerance,
minWidth = expectedWidth - tolerance,
maxWidth = expectedWidth + tolerance,
options = options || {},
$test = $(selector),
$lines = $test.find(options.childSelector || '> *'),
startingFontSize = parseInt($lines.eq(0).css('font-size'), 10);
- this.init.call($lines);
+ BigTextTest.init.call($lines);
$lines.each(function(j)
{
var width = $(this).width();
- assertFalse('Line ' + j + ' is not max width (' + minWidth + ' < ' + width + ' < ' + maxWidth + ')', minWidth < width && width < maxWidth);
+ ok(!(minWidth < width && width < maxWidth), 'Line ' + j + ' is not max width (' + minWidth + ' < ' + width + ' < ' + maxWidth + ')');
});
$test.bigtext(options);
- assertTrue('Class added.', $test.is('.bigtext'));
+ ok('Class added.', $test.is('.bigtext'));
$lines.each(function(j)
{
@@ -78,129 +47,171 @@ BigTextTest.prototype.linesTest = function(selector, expectedWidth, options)
minHeight = expectedHeight - tolerance,
maxHeight = expectedHeight + tolerance;
- assertTrue('Line ' + j + ' class added.', $t.is('.bigtext-line' + j));
+ ok('Line ' + j + ' class added.', $t.is('.bigtext-line' + j));
if($t.hasClass(BigText.EXEMPT_CLASS)) {
// must be added to document to get font-size
var defaultDocumentFontSize = parseInt($('<div/>').appendTo(document.body).css('font-size'), 10);
- assertEquals('Line ' + j + ' Font size must be unchanged', defaultDocumentFontSize, fontSize);
+ equal(defaultDocumentFontSize, fontSize, 'Line ' + j + ' Font size must be unchanged');
} else {
- assertTrue('Line ' + j + ' Font size must be larger than the starting pixel size', fontSize > startingFontSize);
- assertTrue('Line ' + j + ' width should be about ' + expectedWidth + 'px (' + width + ')', minWidth < width && width < maxWidth);
- assertTrue('Line ' + j + ' height should be about ' + expectedHeight + 'px (' + minHeight + ' < ' + height + ' < ' + maxHeight + ')', minHeight < height && height < maxHeight);
+ ok(fontSize > startingFontSize, 'Line ' + j + ' Font size must be larger than the starting pixel size');
+ ok(minWidth < width && width < maxWidth, 'Line ' + j + ' width should be about ' + expectedWidth + 'px (' + width + ')');
+ ok(minHeight < height && height < maxHeight, 'Line ' + j + ' height should be about ' + expectedHeight + 'px (' + minHeight + ' < ' + height + ' < ' + maxHeight + ')');
}
$heightElement.remove();
});
};
-BigTextTest.prototype.testOneLine = function()
+test('testExists', function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a single line.</div></div>');
+ ok(!!BigText);
+ ok(!!$.fn.bigtext);
+});
- this.linesTest('#test', 600);
-};
+test('testStyleInjection', function()
+{
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
+ $('#test').bigtext();
+
+ equal($('#' + BigText.getStyleId('test')).length, 1, 'Test to make sure the style tag was inserted.');
+});
-BigTextTest.prototype.testTwoLines = function()
+test('testDoubleStyleInjection', function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
+ $('#test').bigtext().bigtext();
- this.linesTest('#test', 600);
-};
+ // FIXME this jQuery result won't return more than one element.
+ ok($('#' + BigText.getStyleId('test')).length === 1, 'Test to make sure the style tag wasn\'t inserted twice.');
+});
-BigTextTest.prototype.testThreeLines = function()
+
+test('testCleanup', function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div><div>An even longer third line.</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>This is a simple test.</div></div>');
+ $('#test').bigtext();
- this.linesTest('#test', 600);
-};
+ ok($('.bigtext-cloned').length === 0, 'Clone should be deleted.');
+});
-BigTextTest.prototype.testThreeLinesWithAList = function()
+test('testOneLine', function()
{
- $(document.body).append('<ol id="test" style="width:600px"><li>This is</li><li>a longer second line</li><li>An even longer third line.</li></ol>');
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>This is a single line.</div></div>');
- this.linesTest('#test', 600);
-};
+ BigTextTest.linesTest('#test', 600);
+});
-BigTextTest.prototype.testTwoElements = function()
+test('testTwoLines', function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div></div><div id="test2" style="width:400px"><div>This is</div><div>a longer second line</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div></div>');
- this.linesTest('#test', 600);
- this.linesTest('#test2', 400);
+ BigTextTest.linesTest('#test', 600);
+});
- assertNotEquals('Line 1 of each is a different size.',
- $('#test').find('> div').eq(0).css('font-size'),
- $('#test2').find('> div').eq(0).css('font-size'));
+test('testThreeLines', function()
+{
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div><div>An even longer third line.</div></div>');
- assertNotEquals('Line 2 of each is a different size.',
- $('#test').find('> div').eq(1).css('font-size'),
- $('#test2').find('> div').eq(1).css('font-size'));
-};
+ BigTextTest.linesTest('#test', 600);
+});
-BigTextTest.prototype.testPercentageWidth = function()
+test('testThreeLinesWithAList', function()
{
- $(document.body).append('<div style="width: 600px"><div id="test" style="width: 50%"><div>This is a single line.</div></div></div>');
+ $('#qunit-fixture').append('<ol id="test" style="width:600px"><li>This is</li><li>a longer second line</li><li>An even longer third line.</li></ol>');
- this.linesTest('#test', 300);
-};
+ BigTextTest.linesTest('#test', 600);
+});
-BigTextTest.prototype.testNoChildren = function()
+test('testTwoElements', function()
{
- $(document.body).append('<div id="test" style="width: 600px">This is a single line.</div>');
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>This is</div><div>a longer second line</div></div><div id="test2" style="width:400px"><div>This is</div><div>a longer second line</div></div>');
- this.linesTest('#test', 300);
-};
+ BigTextTest.linesTest('#test', 600);
+ BigTextTest.linesTest('#test2', 400);
+
+ notEqual($('#test').find('> div').eq(0).css('font-size'),
+ $('#test2').find('> div').eq(0).css('font-size'),
+ 'Line 1 of each is a different size.');
+
+ notEqual($('#test').find('> div').eq(1).css('font-size'),
+ $('#test2').find('> div').eq(1).css('font-size'),
+ 'Line 2 of each is a different size.');
+});
+
+test('testPercentageWidth', function()
+{
+ $('#qunit-fixture').append('<div style="width: 600px"><div id="test" style="width: 50%"><div>This is a single line.</div></div></div>');
+
+ BigTextTest.linesTest('#test', 300);
+});
+
+test('testNoChildren', function()
+{
+ $('#qunit-fixture').append('<div id="test" style="width: 600px">This is a single line.</div>');
+
+ BigTextTest.linesTest('#test', 300);
+});
-BigTextTest.prototype.testMaxFontSize = function()
+test('testMaxFontSize', function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>1</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>1</div></div>');
$('#test').bigtext();
- assertEquals('Font size should equal the maximum.', BigText.DEFAULT_MAX_FONT_SIZE_PX + 'px', $('#test > div').css('font-size'));
-};
+ equal(BigText.DEFAULT_MAX_FONT_SIZE_PX + 'px',
+ $('#test > div').css('font-size'),
+ 'Font size should equal the maximum.');
+});
-BigTextTest.prototype.testUnbrokenSingleWord = function()
+test('testUnbrokenSingleWord', function()
{
- $(document.body).append('<div id="test" style="width:300px"><div>This</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="width:300px"><div>This</div></div>');
var startingFontSize = parseInt($('#test > div').css('font-size'), 10);
$('#test').bigtext();
- assertTrue('Font size must be larger than the starting pixel size.', parseInt($('#test > div').css('font-size'), 10) > startingFontSize);
-};
+ ok(parseInt($('#test > div').css('font-size'), 10) > startingFontSize, 'Font size must be larger than the starting pixel size.');
+});
-BigTextTest.prototype.testTwoLinesButOneExempt = function()
+test('testTwoLinesButOneExempt', function()
{
- $(document.body).append('<div id="test" style="width:400px"><div>This is</div><div class="bigtext-exempt">a longer second line</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="width:400px"><div>This is</div><div class="bigtext-exempt">a longer second line</div></div>');
- this.linesTest('#test', 400);
-};
+ BigTextTest.linesTest('#test', 400);
+});
-BigTextTest.prototype.testExemptLineWithChild = function()
+test('testExemptLineWithChild', function()
{
- $(document.body).append('<div id="test" style="width:400px"><div>This is</div><div class="bigtext-exempt">a longer <span>second</span> line</div></div>');
+ var defaultExemptLineFontSize,
+ childFontSize,
+ $test = $('#test'),
+ $exempt;
- var defaultDocumentFontSize = $('<div/>').appendTo(document.body).css('font-size'),
- childFontSize = $('span').css('font-size');
- assertEquals('Exempt line\'s child font size must be unchanged', defaultDocumentFontSize, childFontSize);
-};
+ $('#qunit-fixture').append('<div id="test" style="width:400px"><div>This is</div><div class="bigtext-exempt">a longer <span>second</span> line</div></div>');
+ $exempt = $test.find('.bigtext-exempt');
-BigTextTest.prototype.testIdCssSelectorStyle = function()
+ defaultExemptLineFontSize = $exempt.css('font-size');
+ $test.bigtext();
+ childFontSize = $exempt.css('font-size');
+
+ equal(defaultExemptLineFontSize, childFontSize, 'Exempt line\'s child font size must be unchanged');
+});
+
+test('testIdCssSelectorStyle', function()
{
- $(document.body).append('<style>#test { width: 600px; font-weight: bold; }</style><div id="test"><div>This is a single line.</div></div>');
+ $('#qunit-fixture').append('<style>#test { width: 600px; font-weight: bold; }</style><div id="test"><div>This is a single line.</div></div>');
- this.linesTest('#test', 600);
-};
+ BigTextTest.linesTest('#test', 600);
+});
-BigTextTest.prototype.testMaxWidth = function()
+test('testMaxWidth', function()
{
- $(document.body).append('<div id="test" style="max-width:600px"><div>This is a single line.</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="max-width:600px"><div>This is a single line.</div></div>');
- this.linesTest('#test', 600);
-};
+ BigTextTest.linesTest('#test', 600);
+});
-BigTextTest.prototype.testNoConflict = function()
+test('testNoConflict', function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a single line.</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>This is a single line.</div></div>');
var BT = BigText.noConflict();
$.fn.bt = BT.jQueryMethod;
@@ -210,25 +221,25 @@ BigTextTest.prototype.testNoConflict = function()
var defaultDocumentFontSize = $('<div/>').appendTo(document.body).css('font-size'),
childFontSize = $('#test > div').css('font-size');
- assertNotEquals('Font size must not equal the default.', defaultDocumentFontSize, childFontSize);
-};
+ notEqual(defaultDocumentFontSize, childFontSize, 'Font size must not equal the default.');
+});
-BigTextTest.prototype.testMinFontSize = function()
+test('testMinFontSize', function()
{
- $(document.body).append('<div id="test" style="width:600px"><div>This is a super long line that will probably be too long for this single line. This is a super long line that will probably be too long for this single line.</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div>This is a super long line that will probably be too long for this single line. This is a super long line that will probably be too long for this single line.</div></div>');
$('#test').bigtext({
minfontsize: 16
});
- assertEquals('Font size should equal the minimum.', '16px', $('#test > div').css('font-size'));
- assertEquals('When minimum is set, word wrap should re-enable.', 'normal', $('#test > div').css('white-space'));
-};
+ equal('16px', $('#test > div').css('font-size'), 'Font size should equal the minimum.');
+ equal('normal', $('#test > div').css('white-space'), 'When minimum is set, word wrap should re-enable.');
+});
-BigTextTest.prototype.testChildClassReplace = function()
+test('testChildClassReplace', function()
{
- $(document.body).append('<div id="test" style="width:600px"><div class="testbigtext-line1">This is a single line.</div></div>');
+ $('#qunit-fixture').append('<div id="test" style="width:600px"><div class="testbigtext-line1">This is a single line.</div></div>');
- this.linesTest('#test', 600);
- assertTrue('First line should still have testbigtext-line1 class', $('#test > div').hasClass('testbigtext-line1'));
- assertFalse('First line should not have test class', $('#test > div').hasClass('test'));
-};
+ BigTextTest.linesTest('#test', 600);
+ ok($('#test > div').hasClass('testbigtext-line1'), 'First line should still have testbigtext-line1 class');
+ ok(!$('#test > div').hasClass('test'), 'First line should not have test class');
+});
Binary file not shown.
@@ -1,4 +0,0 @@
-#SAFARI="/Applications/Safari.app/Contents/MacOS/Safari"
-#exec "$SAFARI" $1
-
-open -W -a Safari $1
Oops, something went wrong.

0 comments on commit 0fe596c

Please sign in to comment.