Skip to content

Commit de55d85

Browse files
committed
Replace QUnit with Jasmine http://nv.github.com/CSSOM/spec/
QUnit is hardly configurable. It doesn’t support custom matchers such as equalOwnProperties that I wrote for Jasmine. QUnit objects diff is a bullshit. qunitjs/qunit#10 The diff is based on JSON.stringify shows that {a:1, b:1} and {b:1, a:1} aren’t the same objects. QUnit reporter is ugly. I wrote my own https://github.com/NV/qunit but it’s hard to maintain since QUnit keeps everything in one file in one closure. Jasmine, in the other hand, has a nice API for reporters so I’ve made https://github.com/NV/jasmine-html-reporter Why not Mocha? Mocha looks promising but it doesn’t yet let me integrate objectDiff into it mochajs/mocha#18
1 parent 74e921b commit de55d85

27 files changed

Lines changed: 2947 additions & 1943 deletions

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "spec/vendor/objectDiff"]
2+
path = spec/vendor/objectDiff
3+
url = git://github.com/NV/objectDiff.js.git
4+
[submodule "spec/vendor/jasmine-html-reporter"]
5+
path = spec/vendor/jasmine-html-reporter
6+
url = git://github.com/NV/jasmine-html-reporter.git

README.mdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ To use it with Node.js:
3131

3232
npm install cssom
3333

34-
## [Tests](http://nv.github.com/CSSOM/test/)
34+
## [Specs](http://nv.github.com/CSSOM/spec/)

spec/CSSImportRule.spec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
describe('CSSOM', function() {
2+
describe('CSSImportRule', function() {
3+
4+
given('@import url(button.css);', function(cssText) {
5+
var rule = new CSSOM.CSSImportRule;
6+
rule.cssText = cssText;
7+
expect(rule.href).toBe('button.css');
8+
expect([].join.call(rule.media, ', ')).toBe('');
9+
});
10+
11+
given('@import url("button.css");', function(cssText) {
12+
var rule = new CSSOM.CSSImportRule;
13+
rule.cssText = cssText;
14+
expect(rule.href).toBe('button.css');
15+
expect([].join.call(rule.media, ', ')).toBe('');
16+
});
17+
18+
given("@import url('button.css');", function(cssText) {
19+
var rule = new CSSOM.CSSImportRule;
20+
rule.cssText = cssText;
21+
expect(rule.href).toBe('button.css');
22+
expect([].join.call(rule.media, ', ')).toBe('');
23+
});
24+
25+
given('@import "button.css";', function(cssText) {
26+
var rule = new CSSOM.CSSImportRule;
27+
rule.cssText = cssText;
28+
expect(rule.href).toBe('button.css');
29+
expect([].join.call(rule.media, ', ')).toBe('');
30+
});
31+
32+
given("@import 'button.css';", function(cssText) {
33+
var rule = new CSSOM.CSSImportRule;
34+
rule.cssText = cssText;
35+
expect(rule.href).toBe('button.css');
36+
expect([].join.call(rule.media, ', ')).toBe('');
37+
});
38+
39+
given('@import url(size/medium.css) all;', function(cssText) {
40+
var rule = new CSSOM.CSSImportRule;
41+
rule.cssText = '@import url(size/medium.css) all;';
42+
expect(rule.href).toBe('size/medium.css');
43+
expect([].join.call(rule.media, ', ')).toBe("all");
44+
expect(rule.media.mediaText).toBe("all");
45+
});
46+
47+
given('@import url(old.css) screen and (color), projection and (min-color: 256);', function(cssText) {
48+
var rule = new CSSOM.CSSImportRule;
49+
rule.cssText = '@import url(old.css) screen and (color), projection and (min-color: 256);';
50+
expect(rule.href).toBe('old.css');
51+
expect([].join.call(rule.media, ', ')).toBe('screen and (color), projection and (min-color: 256)');
52+
expect(rule.media.mediaText).toBe('screen and (color), projection and (min-color: 256)');
53+
});
54+
});
55+
});

spec/CSSProperty.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
describe('CSSOM', function() {
2+
describe('CSSProperty', function() {
3+
4+
given('letter-spacing: -0.1em !important', function(cssText) {
5+
var property = new CSSOM.CSSProperty;
6+
property.name = 'letter-spacing';
7+
property.value = '-0.1em';
8+
property.important = true;
9+
expect(property.toString()).toBe('letter-spacing: -0.1em !important');
10+
expect(property).toEqualOwnProperties({
11+
name: 'letter-spacing',
12+
value: '-0.1em',
13+
important: true,
14+
__original: ''
15+
});
16+
});
17+
18+
});
19+
});

spec/CSSStyleDeclaration.spec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
describe('CSSOM', function() {
2+
describe('CSSStyleDeclaration', function() {
3+
4+
it('setProperty, removeProperty, cssText, getPropertyValue, getPropertyPriority', function() {
5+
var d = new CSSOM.CSSStyleDeclaration;
6+
7+
d.setProperty('color', 'purple');
8+
expect(d).toEqualOwnProperties({
9+
0: 'color',
10+
length: 1,
11+
parentRule: null,
12+
color: 'purple',
13+
_importants: {
14+
color: undefined
15+
}
16+
});
17+
18+
d.setProperty('width', '128px', 'important');
19+
expect(d).toEqualOwnProperties({
20+
0: 'color',
21+
1: 'width',
22+
length: 2,
23+
parentRule: null,
24+
color: 'purple',
25+
width: '128px',
26+
_importants: {
27+
color: undefined,
28+
width: 'important'
29+
}
30+
});
31+
32+
expect(d.cssText).toBe('color: purple; width: 128px !important;');
33+
34+
expect(d.getPropertyValue('color')).toBe('purple');
35+
expect(d.getPropertyValue('width')).toBe('128px');
36+
expect(d.getPropertyValue('position')).toBe('');
37+
38+
expect(d.getPropertyPriority('color')).toBe('');
39+
expect(d.getPropertyPriority('width')).toBe('important');
40+
expect(d.getPropertyPriority('position')).toBe('');
41+
42+
d.setProperty('color', 'green');
43+
d.removeProperty('width');
44+
45+
expect(d.cssText).toBe('color: green;');
46+
});
47+
48+
given('color: pink; outline: 2px solid red;', function(cssText) {
49+
var d = new CSSOM.CSSStyleDeclaration;
50+
d.cssText = cssText;
51+
expect(d.cssText).toBe(cssText);
52+
});
53+
54+
});
55+
});

spec/CSSStyleRule.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
describe('CSSOM', function() {
2+
describe('CSSStyleRule', function() {
3+
4+
given('h1:first-of-type {\n\tfont-size: 3em\n}', function(cssText) {
5+
var rule = new CSSOM.CSSStyleRule;
6+
rule.cssText = cssText;
7+
8+
expect(rule.cssText).toBe('h1:first-of-type {font-size: 3em;}');
9+
expect(rule.selectorText).toBe('h1:first-of-type');
10+
11+
rule.selectorText = 'h1.title';
12+
expect(rule.selectorText).toBe('h1.title');
13+
expect(rule.cssText).toBe('h1.title {font-size: 3em;}');
14+
});
15+
16+
});
17+
});

spec/CSSStyleSheet.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
describe('CSSOM', function() {
2+
describe('CSSStyleSheet', function() {
3+
4+
it('insertRule, deleteRule', function() {
5+
var s = new CSSOM.CSSStyleSheet;
6+
expect(s.cssRules).toEqual([]);
7+
8+
s.insertRule("a {color: blue}", 0);
9+
expect(s.cssRules.length).toBe(1);
10+
11+
s.insertRule("a *:first-child, a img {border: none}", 1);
12+
expect(s.cssRules.length).toBe(2);
13+
14+
s.deleteRule(1);
15+
expect(s.cssRules.length).toBe(1);
16+
17+
s.deleteRule(0);
18+
expect(s.cssRules).toEqual([]);
19+
});
20+
21+
});
22+
});

spec/MediaList.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
describe('CSSOM', function() {
2+
describe('MediaList', function() {
3+
4+
it('appendMedium, deleteMedium, mediaText', function() {
5+
var m = new CSSOM.MediaList;
6+
expect(m.length).toBe(0);
7+
8+
m.appendMedium("handheld");
9+
m.appendMedium("screen");
10+
m.appendMedium("only screen and (max-device-width: 480px)");
11+
12+
m.deleteMedium("screen");
13+
14+
expect(m[2]).toBeUndefined();
15+
16+
var expected = {
17+
0: "handheld",
18+
1: "only screen and (max-device-width: 480px)",
19+
length: 2
20+
};
21+
22+
expect(m).toEqualOwnProperties(expected);
23+
expect(m.mediaText).toBe([].join.call(expected, ", "));
24+
});
25+
26+
});
27+
});

spec/helper.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function given(str, fn) {
2+
var args = [].slice.call(arguments, 0, -1);
3+
return jasmine.getEnv().it(str.toString(), function() {
4+
fn.apply(this, args);
5+
});
6+
}
7+
8+
beforeEach(function() {
9+
this.addMatchers(objectDiff.jasmine);
10+
});

spec/index.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype HTML>
2+
<html>
3+
<head>
4+
<title>CSSOM specs</title>
5+
6+
<link rel="stylesheet" href="vendor/objectDiff/objectDiff.css">
7+
<script src="vendor/objectDiff/objectDiff.js"></script>
8+
<script src="vendor/objectDiff/jasmine-objectDiff.js"></script>
9+
10+
<link rel="stylesheet" href="vendor/jasmine/jasmine.css">
11+
<script src="vendor/jasmine/jasmine.js"></script>
12+
<link rel="stylesheet" href="vendor/jasmine-html-reporter/HtmlReporter.css">
13+
<script src="vendor/jasmine-html-reporter/HtmlReporter.js"></script>
14+
15+
<script src="../src/loader.js"></script>
16+
17+
<script src="helper.js"></script>
18+
<script src="utils.js"></script>
19+
<script src="parse.spec.js"></script>
20+
<script src="MediaList.spec.js"></script>
21+
<script src="CSSStyleRule.spec.js"></script>
22+
<script src="CSSStyleDeclaration.spec.js"></script>
23+
<script src="CSSStyleSheet.spec.js"></script>
24+
<script>
25+
var htmlReporter = new jasmine.HtmlReporter();
26+
var jasmineEnv = jasmine.getEnv();
27+
jasmineEnv.updateInterval = 1000;
28+
jasmineEnv.addReporter(htmlReporter);
29+
jasmineEnv.specFilter = htmlReporter.specFilter;
30+
window.onload = function() {
31+
jasmineEnv.execute();
32+
};
33+
</script>
34+
<link id="favicon_pass" href="vendor/jasmine-html-reporter/pass.png"/>
35+
<link id="favicon_fail" href="vendor/jasmine-html-reporter/fail.png"/>
36+
</head>
37+
<body></body>
38+
</html>

0 commit comments

Comments
 (0)