Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 008607014d13140b0535e49f8aefd9643b1820c4 Miki Leskinen committed Jan 12, 2011
@@ -0,0 +1,2 @@
+.idea
+*.iml
@@ -0,0 +1,34 @@
+var express = require('express')
+
+var options = (function() {
+ var _options = {
+ port: '8002'
+ }
+
+ function resolveArgument(name, arg) {
+ var fullPrefix = name + '='
+ if (arg.substring(0, fullPrefix.length) === fullPrefix) {
+ _options[name] = arg.substring(fullPrefix.length)
+ }
+ }
+
+ process.argv.forEach(function(arg) {
+ resolveArgument('port', arg)
+ })
+
+ return _options
+}())
+
+var app = express.createServer()
+
+app.set('view engine', 'jade')
+app.set('view options', {layout: false})
+app.use(express.staticProvider(__dirname + '/public'))
+
+app.get('/', function(req, res){
+ res.render('index')
+})
+
+console.log('Using port ' + options.port + '...')
+app.listen(options.port)
+console.log('Server running at http://localhost:' + options.port)
@@ -0,0 +1,3 @@
+.main {
+ background-color: green;
+}
@@ -0,0 +1,13 @@
+$(document).ready(function() {
+ $.ajax({
+ url: 'http://api.twitter.com/1/trends/current.json',
+ type: 'GET',
+ dataType: 'jsonp',
+ success: function(data) {
+ var trends = _(data.trends).chain().map(function(v, k){ return v }).first().flatten().value()
+ _.forEach(trends, function(t) {
+ $('.trends').append('<li class="trend">' + t.name + '</li>')
+ })
+ }
+ })
+})

Large diffs are not rendered by default.

Oops, something went wrong.

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

Oops, something went wrong.
@@ -0,0 +1,15 @@
+!!! 5
+html(lang="en")
+ head
+ title='Foo Twitter Client'
+ link(href='/css/application.css', media='screen', rel='stylesheet', type='text/css')
+ script(src='/js/jquery-1.4.4.min.js', type='application/javascript')
+ script(src='/js/underscore-min.js', type='application/javascript')
+ script(src='/js/application.js', type='application/javascript')
+ body
+ div.main
+ h3 Foo Twitter Client
+ div.actions
+ a.showTrends
+ div.trendsScrollContainer
+ ol.trends
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+echo "Starting application..."
+./start-application.sh
+/usr/bin/env node spec/lib/jasmine-node/specs.js --specs-dir=$PWD/spec/js/ $@
+echo "Stopping application..."
+./stop-application.sh
@@ -0,0 +1,22 @@
+describe('twitter client', function() {
+ var zombie = require('zombie')
+ var browser = new zombie.Browser()
+
+ describe('initial', function() {
+ it('has correct title', function() {
+ browser.visit('http://localhost:8003/', function(error, browser) {
+ expect(browser.text('title')).toEqual('Foo Twitter Client')
+ asyncSpecDone()
+ })
+ asyncSpecWait()
+ })
+
+ it('shows latest trends', function() {
+ browser.visit('http://localhost:8003/', function(error, browser) {
+ expect(browser.querySelectorAll('.trends .trend').length).toEqual(10)
+ asyncSpecDone()
+ })
+ asyncSpecWait()
+ })
+ })
+})
@@ -0,0 +1,34 @@
+var jasmine = require('jasmine-node');
+var sys = require('sys'),
+ Path= require('path');
+
+var SPEC_FOLDER= Path.join(process.cwd(), 'spec'),
+ SPEC_MATCHER_REGEX= "^.+[-_]spec\.(js|coffee)$",
+ HELPER_MATCHER_REGEX= "^.+[-_]helper\.(js|coffee)$";
+
+for (var key in jasmine)
+ global[key] = jasmine[key];
+
+var isVerbose = false;
+var showColors = true;
+
+process.argv.forEach(function(arg){
+ switch(arg)
+ {
+ case '--color':
+ showColors = true;
+ break;
+ case '--noColor':
+ showColors = false;
+ break;
+ case '--verbose':
+ isVerbose = true;
+ break;
+
+ }
+});
+
+jasmine.loadHelpersInFolder(SPEC_FOLDER, HELPER_MATCHER_REGEX);
+jasmine.executeSpecsInFolder(SPEC_FOLDER, function(runner, log){
+ process.exit(runner.results().failedCount);
+}, isVerbose, showColors, SPEC_MATCHER_REGEX);
@@ -0,0 +1,191 @@
+var fs = require('fs');
+var sys = require('sys');
+var path = require('path');
+
+var filename = __dirname + '/jasmine-1.0.1.js';
+global.window = {
+ setTimeout: setTimeout,
+ clearTimeout: clearTimeout,
+ setInterval: setInterval,
+ clearInterval: clearInterval
+};
+
+var src = fs.readFileSync(filename);
+var jasmine;
+var minorVersion = process.version.match(/\d\.(\d)\.\d/)[1];
+switch (minorVersion) {
+ case "1":
+ case "2":
+ jasmine = process.compile(src + '\njasmine;', filename);
+ break;
+ default:
+ jasmine = require('vm').runInThisContext(src + "\njasmine;", filename);
+}
+
+delete global.window;
+
+function noop(){}
+
+jasmine.executeSpecsInFolder = function(folder, done, isVerbose, showColors, matcher){
+ var log = [];
+ var columnCounter = 0;
+ var start = 0;
+ var elapsed = 0;
+ var verbose = isVerbose || false;
+ var fileMatcher = new RegExp(matcher || "^.+\.(js|coffee)$");
+ var colors = showColors || false;
+ var specs = jasmine.getAllSpecFiles(folder, fileMatcher);
+
+ var ansi = {
+ green: '\033[32m',
+ red: '\033[31m',
+ yellow: '\033[33m',
+ none: '\033[0m'
+ };
+
+ for (var i = 0, len = specs.length; i < len; ++i){
+ var filename = specs[i];
+ require(filename.replace(/\.*$/, ""));
+ }
+
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.reporter = {
+ log: function(str){
+ },
+
+ reportSpecStarting: function(runner) {
+ },
+
+ reportRunnerStarting: function(runner) {
+ sys.puts('Started');
+ start = Number(new Date);
+ },
+
+ reportSuiteResults: function(suite) {
+ var specResults = suite.results();
+ var path = [];
+ while(suite) {
+ path.unshift(suite.description);
+ suite = suite.parentSuite;
+ }
+ var description = path.join(' ');
+
+ if (verbose)
+ log.push('Spec ' + description);
+
+ specResults.items_.forEach(function(spec){
+ if (spec.failedCount > 0 && spec.description) {
+ if (!verbose)
+ log.push(description);
+ log.push(' it ' + spec.description);
+ spec.items_.forEach(function(result){
+ log.push(' ' + result.trace.stack + '\n');
+ });
+ }
+ });
+ },
+
+ reportSpecResults: function(spec) {
+ var result = spec.results();
+ var msg = '';
+ if (result.passed())
+ {
+ msg = (colors) ? (ansi.green + '.' + ansi.none) : '.';
+// } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec?
+// msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*';
+ } else {
+ msg = (colors) ? (ansi.red + 'F' + ansi.none) : 'F';
+ }
+ sys.print(msg);
+ if (columnCounter++ < 50) return;
+ columnCounter = 0;
+ sys.print('\n');
+ },
+
+
+ reportRunnerResults: function(runner) {
+ elapsed = (Number(new Date) - start) / 1000;
+ sys.puts('\n');
+ log.forEach(function(log){
+ sys.puts(log);
+ });
+ sys.puts('Finished in ' + elapsed + ' seconds');
+
+ var summary = jasmine.printRunnerResults(runner);
+ if(colors)
+ {
+ if(runner.results().failedCount === 0 )
+ sys.puts(ansi.green + summary + ansi.none);
+ else
+ sys.puts(ansi.red + summary + ansi.none);
+ } else {
+ sys.puts(summary);
+ }
+ (done||noop)(runner, log);
+ }
+ };
+ jasmineEnv.execute();
+};
+
+jasmine.getAllSpecFiles = function(dir, matcher){
+ var specs = [];
+
+ if (fs.statSync(dir).isFile() && dir.match(matcher)) {
+ specs.push(dir);
+ } else {
+ var files = fs.readdirSync(dir);
+ for (var i = 0, len = files.length; i < len; ++i){
+ var filename = dir + '/' + files[i];
+ if (fs.statSync(filename).isFile() && filename.match(matcher)){
+ specs.push(filename);
+ }else if (fs.statSync(filename).isDirectory()){
+ var subfiles = this.getAllSpecFiles(filename, matcher);
+ subfiles.forEach(function(result){
+ specs.push(result);
+ });
+ }
+ }
+ }
+
+ return specs;
+};
+
+jasmine.printRunnerResults = function(runner){
+ var results = runner.results();
+ var suites = runner.suites();
+ var msg = '';
+ msg += suites.length + ' test' + ((suites.length === 1) ? '' : 's') + ', ';
+ msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', ';
+ msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n';
+ return msg;
+};
+
+function now(){
+ return new Date().getTime();
+}
+
+jasmine.asyncSpecWait = function(){
+ var wait = jasmine.asyncSpecWait;
+ wait.start = now();
+ wait.done = false;
+ (function innerWait(){
+ waits(10);
+ runs(function() {
+ if (wait.start + wait.timeout < now()) {
+ expect('timeout waiting for spec').toBeNull();
+ } else if (wait.done) {
+ wait.done = false;
+ } else {
+ innerWait();
+ }
+ });
+ })();
+};
+jasmine.asyncSpecWait.timeout = 4 * 1000;
+jasmine.asyncSpecDone = function(){
+ jasmine.asyncSpecWait.done = true;
+};
+
+for ( var key in jasmine) {
+ exports[key] = jasmine[key];
+}
Oops, something went wrong.

0 comments on commit 0086070

Please sign in to comment.