Permalink
Browse files

added browser tests, removed minification since google seems to mangl…

…e it
  • Loading branch information...
1 parent eb78f5a commit 23d26d0880d41ed0bbe84aeae38f1479de264542 @hunterloftis committed Jan 3, 2013
Showing with 8,971 additions and 22 deletions.
  1. 0 build/cryo-0.0.1.min.js
  2. +0 −7 build/cryo-0.0.2.min.js
  3. +11 −7 build/cryo-0.0.3.js
  4. +0 −7 build/cryo-0.0.3.min.js
  5. +1 −1 makefile
  6. +24 −0 test/browser.html
  7. +47 −0 test/browser.test.js
  8. +3,649 −0 vendor/chai.js
  9. +227 −0 vendor/mocha.css
  10. +5,012 −0 vendor/mocha.js
View
No changes.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -71,16 +71,20 @@
return rebuildFromReferences(json.root, json.references);
}
- function rebuildFromReferences(item, references) {
+ function rebuildFromReferences(item, references, restoredItems) {
+ restoredItems = restoredItems || [];
if (starts(item, REFERENCE_FLAG)) {
var referenceIndex = parseInt(item.slice(REFERENCE_FLAG.length), 10);
- var ref = references[referenceIndex];
- var container = unwrap(ref.value);
- var contents = ref.contents;
- for (var key in contents) {
- container[key] = rebuildFromReferences(contents[key], references);
+ if (!restoredItems.hasOwnProperty(referenceIndex)) {
+ var ref = references[referenceIndex];
+ var container = unwrap(ref.value);
+ var contents = ref.contents;
+ for (var key in contents) {
+ container[key] = rebuildFromReferences(contents[key], references, restoredItems);
+ }
+ restoredItems[referenceIndex] = container;
}
- return container;
+ return restoredItems[referenceIndex];
}
return unwrap(item);
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -17,7 +17,7 @@ build:
@echo "Building with closure compiler..."
@curl -s \
- -d compilation_level=SIMPLE_OPTIMIZATIONS \
+ -d compilation_level=WHITESPACE_ONLY \
-d output_format=text \
-d output_info=compiled_code \
--data-urlencode "js_code@${DEV}" \
View
@@ -0,0 +1,24 @@
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Cryo-browser Test Suite</title>
+ <link rel="stylesheet" href="../vendor/mocha.css" />
+</head>
+<body>
+ <div id="mocha"></div>
+ <!-- mocha -->
+ <script src="../vendor/chai.js"></script>
+ <script>
+ assert = chai.assert;
+ expect = chai.expect;
+ </script>
+ <script src="../vendor/mocha.js"></script>
+ <script>mocha.setup('bdd')</script>
+ <!-- src -->
+ <script src="../build/cryo-0.0.3.js"></script>
+ <!-- tests -->
+ <script src="browser.test.js"></script>
+
+ <script>mocha.run();</script>
+</body>
+</html>
View
@@ -0,0 +1,47 @@
+describe('Cryo - Browser', function() {
+
+ it('should be able to hydrate itself', function() {
+ var stringified = Cryo.stringify(Cryo);
+ var hydrated = Cryo.parse(stringified);
+
+ assert.isFunction(hydrated.parse);
+ assert.isFunction(hydrated.stringify);
+ });
+
+ it('should hydrate several objects referring to each other', function() {
+ var user1 = {
+ name: 'Hunter',
+ destroy: function() {
+ return 'destroyed ' + this.name;
+ }
+ };
+ var user2 = {
+ name: 'Jim'
+ };
+ var project = {
+ maintainers: [user1, user2],
+ title: 'Cryo'
+ };
+ var test = {
+ subject: project,
+ passing: true,
+ hooks: {
+ subscribed_users: [user1]
+ }
+ };
+ var stringified = Cryo.stringify(test);
+ var hydrated = Cryo.parse(stringified);
+
+ var result1 = test.hooks.subscribed_users[0].destroy();
+ var result2 = hydrated.hooks.subscribed_users[0].destroy();
+
+ hydrated.hooks.subscribed_users[0].name = 'Newname';
+ var result3 = hydrated.hooks.subscribed_users[0].destroy();
+
+ assert.strictEqual(result1, result2);
+ assert.strictEqual(result3, 'destroyed Newname');
+ assert.strictEqual(test.passing, hydrated.passing);
+ assert.strictEqual(test.subject.title, hydrated.subject.title);
+ });
+
+});
Oops, something went wrong.

0 comments on commit 23d26d0

Please sign in to comment.