<commit_before>var ORIGINAL_TITLE = document.title;
var current_mode;

function unreadNotifications() {
    var chats_url;
    if (type=="None") {
        chats_url = '/chats.json';
    } else {
        chats_url = '/chats/'+type+'.json';
    }
    $.getJSON(chats_url, function(data) {
        chats = data.chats;
        chatsUpdate(true);
    }).complete(function() {
        window.setTimeout(unreadNotifications, 10000);
    });
}

function chatsUpdate(first) {
    if ($('body').prop('class')) {
        mode = $('body').prop('class');
    } else {
        mode = 'none';
    }

    unread_chats = 0;
    for (i in chats) {
        chat = chats[i];
        if (chat.unread) {
            unread_chats++;
        }
    }
    if (unread_chats > 0) {
        document.title = unread_chats+" unread - "+ORIGINAL_TITLE;
    } else {
        document.title = ORIGINAL_TITLE;
    }

    if (current_mode == mode || first) {
        $('#under-page').empty();
        if ($('body.mobile').length>0) {
            $('<div>').addClass('section').prop('id', 'column-1').appendTo('#under-page');
            for(i in chats) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-1');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
        } else if ($('body.nobile').length>0) {
            $('<div>').addClass('section').prop('id', 'column-1').appendTo('#under-page');
            $('<div>').addClass('section').prop('id', 'column-2').appendTo('#under-page');
            for (var i=0; i<chats.length; i+=2) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-1');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
            for (var i=1; i<chats.length; i+=2) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-2');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
        } else {
            $('<div>').addClass('section').prop('id', 'column-1').appendTo('#under-page');
            $('<div>').addClass('section').prop('id', 'column-2').appendTo('#under-page');
            $('<div>').addClass('section').prop('id', 'column-3').appendTo('#under-page');
            for (var i=0; i<chats.length; i+=3) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-1');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
            for (var i=1; i<chats.length; i+=3) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-2');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
            for (var i=2; i<chats.length; i+=3) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-3');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
        }
    }
    current_mode = mode;
}

$(function(){
    screenCheck();

    if ($('body').prop('class')) {
        current_mode = $('body').prop('class');
    } else {
        current_mode = 'none';
    }

    chatsUpdate(true);
});

$(window).resize(function () {
    screenCheck();
    chatsUpdate();
    setTimeout(unreadNotifications, 10000);
});<commit_msg>chat.css<commit_after>var ORIGINAL_TITLE = document.title;
var current_mode;

function unreadNotifications() {
    console.log('1');
    var chats_url;
    if (type=="None") {
        chats_url = '/chats.json';
    } else {
        chats_url = '/chats/'+type+'.json';
    }
    $.getJSON(chats_url, function(data) {
        chats = data.chats;
        chatsUpdate(true);
    }).complete(function() {
        window.setTimeout(unreadNotifications, 10000);
    });
}

function chatsUpdate(first) {
    if ($('body').prop('class')) {
        mode = $('body').prop('class');
    } else {
        mode = 'none';
    }

    unread_chats = 0;
    for (i in chats) {
        chat = chats[i];
        if (chat.unread) {
            unread_chats++;
        }
    }
    if (unread_chats > 0) {
        document.title = unread_chats+" unread - "+ORIGINAL_TITLE;
    } else {
        document.title = ORIGINAL_TITLE;
    }

    if (current_mode == mode || first) {
        $('#under-page').empty();
        if ($('body.mobile').length>0) {
            $('<div>').addClass('section').prop('id', 'column-1').appendTo('#under-page');
            for(i in chats) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-1');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
        } else if ($('body.nobile').length>0) {
            $('<div>').addClass('section').prop('id', 'column-1').appendTo('#under-page');
            $('<div>').addClass('section').prop('id', 'column-2').appendTo('#under-page');
            for (var i=0; i<chats.length; i+=2) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-1');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
            for (var i=1; i<chats.length; i+=2) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-2');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
        } else {
            $('<div>').addClass('section').prop('id', 'column-1').appendTo('#under-page');
            $('<div>').addClass('section').prop('id', 'column-2').appendTo('#under-page');
            $('<div>').addClass('section').prop('id', 'column-3').appendTo('#under-page');
            for (var i=0; i<chats.length; i+=3) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-1');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
            for (var i=1; i<chats.length; i+=3) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-2');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
            for (var i=2; i<chats.length; i+=3) {
                chat = chats[i];
                $('<div>').addClass('card chat').prop('id', 'chat-'+chat.url.replace(/\//g,'-')).appendTo('#column-3');
                $('<a>').addClass('title').prop('href','/'+chat.url).text(chat.title+(chat.unread ? ' (unread)' : '')).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                if (chat.online > 0) {
                    $('<div>').addClass('users-online').text(chat.online+' online').appendTo('#chat-'+chat.url.replace(/\//g,'-').replace(/\//g,'-'));
                }
                if (chat.type == 'group') {
                    $('<div>').addClass('topic').text(chat.topic).appendTo('#chat-'+chat.url.replace(/\//g,'-'));
                }
            }
        }
    }
    current_mode = mode;
}

$(function(){
    screenCheck();

    if ($('body').prop('class')) {
        current_mode = $('body').prop('class');
    } else {
        current_mode = 'none';
    }

    chatsUpdate(true);
});

$(window).resize(function () {
    screenCheck();
    chatsUpdate();
    setTimeout(unreadNotifications, 10000);
});<|endoftext|>


<commit_before>'use strict'

var assert = require('assert')
var run = require('test').run

exports['test:pass'] = function(test) {
  run(
    { 'test:pass': function() {
      assert.equal(1, 1, 'Must be equal')
    }}
  , function(result) {
      test(assert.equal, result.passes.length, 1, 'Must pass one test')
      test(assert.equal, result.fails.length, 0, 'Must not fail any test')
      test(assert.equal, result.errors.length, 0, 'Must not contain any errors')
      return false
    }
  )
}

exports['test:failure'] = function(test) {
  run(
    { 'test:must fail': function() {
      assert.equal(1, 2, 'Must be two')
    }}
  , function(result) {
      test(assert.equal, result.passes.length, 0, 'Must not pass any test')
      test(assert.equal, result.fails.length, 1, 'Must fail one test')
      test(assert.equal, result.errors.length, 0, 'Must not contain any errors')
      return false
    }
  )
}

exports['test:error'] = function(test) {
  run(
    { 'test:must throw': function() {
      throw new Error('Sorry, but you have to see error & it is not a failure')
    }}
  , function(result) {
      test(assert.equal, result.passes.length, 0, 'Must not pass any test')
      test(assert.equal, result.fails.length, 0, 'Must not fail any test')
      test(assert.equal, result.errors.length, 1, 'Must contain one error')
      return false
    }
  )
}

run(exports)

<commit_msg>adding few more tests<commit_after>'use strict'

var assert = require('assert')
var run = require('test').run

exports['test:pass'] = function(test) {
  run(
    { 'test:pass': function() {
      assert.equal(1, 1, 'Must be equal')
    }}
  , function(result) {
      test(assert.equal, result.passes.length, 1, 'Must pass one test')
      test(assert.equal, result.fails.length, 0, 'Must not fail any test')
      test(assert.equal, result.errors.length, 0, 'Must not contain any errors')
      return false
    }
  )
}

exports['test:failure'] = function(test) {
  run(
    { 'test:must fail': function() {
      assert.equal(1, 2, 'Must be two')
    }}
  , function(result) {
      test(assert.equal, result.passes.length, 0, 'Must not pass any test')
      test(assert.equal, result.fails.length, 1, 'Must fail one test')
      test(assert.equal, result.errors.length, 0, 'Must not contain any errors')
      return false
    }
  )
}

exports['test:error'] = function(test) {
  run(
    { 'test:must throw': function() {
      throw new Error('Sorry, but you have to see error & it is not a failure')
    }}
  , function(result) {
      test(assert.equal, result.passes.length, 0, 'Must not pass any test')
      test(assert.equal, result.fails.length, 0, 'Must not fail any test')
      test(assert.equal, result.errors.length, 1, 'Must contain one error')
      return false
    }
  )
}

exports['test:pseudo async throws'] = function(test, done) {
  run(
    { 'test:must throw': function() {
      throw new Error('Sorry, but you have to see error & it is not a failure')
    }}
  , function(result) {
      test(assert.equal, result.passes.length, 0, 'Must not pass any test')
      test(assert.equal, result.fails.length, 0, 'Must not fail any test')
      test(assert.equal, result.errors.length, 1, 'Must contain one error')
      done()
      return false
    }
  )
}

 exports['test:pseudo async throws'] = function(test, done) {
  run(
    { 'test:must throw': function() {
      throw new Error('Sorry, but you have to see error & it is not a failure')
    }}
  , function(result) {
      test(assert.equal, result.passes.length, 0, 'Must not pass any test')
      test(assert.equal, result.fails.length, 0, 'Must not fail any test')
      test(assert.equal, result.errors.length, 1, 'Must contain one error')
      done()
      return false
    }
  )
}

exports['test:async throws'] = function(test, done) {
  run(
    { 'test:must throw': function() {
      throw new Error('Sorry, but you have to see error & it is not a failure')
    }}
  , function(result) {
      setTimeout(function() {
        test(assert.equal, result.passes.length, 0, 'Must not pass any test')
        test(assert.equal, result.fails.length, 0, 'Must not fail any test')
        test(assert.equal, result.errors.length, 1, 'Must contain one error')
        done()
      })
      return false
    }
  )
}

 run(exports)

<|endoftext|>


<commit_before>/*
 * Alloy JavaScript Library v0.1
 * http://alloyui.com/
 *
 * Copyright (c) 2009 Liferay Inc.
 * Licensed under the MIT license.
 * http://alloyui.com/License
 *
 * Date: @DATE
 * Revision: @REVISION
 */

;(function() {
	var PATH_BASE = YUI.config.base + '../../../';
	var PATH_JAVASCRIPT = PATH_BASE + 'src/javascript/';
	var PATH_THEME_ROOT = PATH_BASE + 'themes/base/css/';
	var PATH_THEME_IMAGES = PATH_THEME_ROOT + '../images/';

	window.AUI = {
		defaults: {
			classNamePrefix: 'aui',

			//base: '',

			defaultModules: [ 'aui-base' ],

			filter: 'raw',

			modules: {

				/*
				* AUI Base modules
				*/
				'aui-base': {
					fullpath: PATH_JAVASCRIPT + 'base.js',
					requires: [ 'event', 'oop', 'component', 'aui-node', 'collection' ]
				},

				/*
				* Data Set
				*/
				'data-set': {
					fullpath: PATH_JAVASCRIPT + 'data-set.js',
					requires: [ 'oop', 'collection', 'base' ]
				},

				/*
				* AutoComplete
				*/
				'autocomplete': {
					fullpath: PATH_JAVASCRIPT + 'autocomplete.js',
					requires: [ 'aui-base', 'component-overlay', 'datasource', 'dataschema', 'autocomplete-css', 'combobox' ]
				},
				'autocomplete-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'autocomplete.css',
					type: 'css'
				},

				/*
				* Editable
				*/
				'editable': {
					fullpath: PATH_JAVASCRIPT + 'editable.js',
					requires: [ 'aui-base', 'editable-css', 'combobox', 'textarea' ]
				},
				'editable-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'editable.css',
					type: 'css'
				},

				/*
				* Paginator
				*/
				'paginator': {
					fullpath: PATH_JAVASCRIPT + 'paginator.js',
					requires: [ 'aui-base', 'substitute', 'paginator-css' ]
				},
				'paginator-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'paginator.css',
					type: 'css'
				},

				/*
				* Rating
				*/
				'rating': {
					fullpath: PATH_JAVASCRIPT + 'rating.js',
					requires: [ 'aui-base', 'rating-css' ]
				},
				'rating-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'rating.css',
					type: 'css'
				},

				/*
				* Tool Item
				*/
				'tool-item': {
					fullpath: PATH_JAVASCRIPT + 'tool-item.js',
					requires: [ 'aui-base', 'state-interaction', 'tool-item-css' ]
				},
				'tool-item-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tool-item.css',
					type: 'css'
				},

				/*
				* Tool Set
				*/
				'tool-set': {
					fullpath: PATH_JAVASCRIPT + 'tool-set.js',
					requires: [ 'data-set', 'tool-item', 'tool-set-css' ]
				},
				'tool-set-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tool-set.css',
					type: 'css'
				},

				/*
				* Calendar
				*/
				'calendar': {
					fullpath: PATH_JAVASCRIPT + 'calendar.js',
					requires: [ 'aui-base', 'context-overlay', 'overlay-manager', 'datatype-date', 'calendar-css' ]
				},
				'calendar-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'calendar.css',
					type: 'css'
				},

				/*
				* Calendar
				*/
				'char-counter': {
					fullpath: PATH_JAVASCRIPT + 'char-counter.js',
					requires: [ 'aui-base', 'input-handler' ]
				},

				/*
				* DatePickerSelect
				*/
				'date-picker-select': {
					fullpath: PATH_JAVASCRIPT + 'date-picker-select.js',
					requires: [ 'calendar', 'tool-item', 'date-picker-select-css' ]
				},
				'date-picker-select-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'date-picker-select.css',
					type: 'css'
				},

				/*
				* ContextPanel
				*/
				'context-panel': {
					fullpath: PATH_JAVASCRIPT + 'context-panel.js',
					requires: [ 'context-overlay', 'anim', 'context-panel-css' ]
				},
				'context-panel-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'context-panel.css',
					type: 'css'
				},

				/*
				* ColorPicker
				*/
				'color-picker': {
					fullpath: PATH_JAVASCRIPT + 'color-picker.js',
					requires: [ 'context-overlay', 'dd', 'slider', 'substitute', 'tool-item', 'color-picker-css', 'form', 'panel' ]
				},
				'color-picker-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'color-picker.css',
					type: 'css'
				},

				/*
				* Tooltip
				*/
				'tooltip': {
					fullpath: PATH_JAVASCRIPT + 'tooltip.js',
					requires: [ 'context-panel', 'tooltip-css' ]
				},
				'tooltip-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tooltip.css',
					type: 'css'
				},

				/*
				* TreeData
				*/
				'tree-data': {
					fullpath: PATH_JAVASCRIPT + 'tree-data.js',
					requires: [ 'aui-base' ]
				},

				/*
				* TreeNode
				*/
				'tree-node': {
					fullpath: PATH_JAVASCRIPT + 'tree-node.js',
					requires: [ 'tree-data', 'io', 'json', 'tree-css' ]
				},

				/*
				* TreeView
				*/
				'tree-view': {
					fullpath: PATH_JAVASCRIPT + 'tree-view.js',
					requires: [ 'tree-node', 'dd', 'tree-css' ]
				},

				'tree-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tree.css',
					type: 'css'
				},

				/*
				* TextboxList
				*/
				'textboxlist': {
					fullpath: PATH_JAVASCRIPT + 'textboxlist.js',
					requires: [ 'anim-node-plugin', 'aui-base', 'autocomplete', 'node-focusmanager', 'textboxlist-css' ]
				},

				'textboxlist-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'textboxlist.css',
					type: 'css'
				},

				/*
				* Dialog
				*/
				'dialog': {
					fullpath: PATH_JAVASCRIPT + 'dialog.js',
					requires: [ 'plugin', 'panel', 'dd-constrain', 'aui-base', 'tool-item', 'overlay-manager', 'overlay-mask', 'io-stdmod', 'dialog-css' ]
				},
				'dialog-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'dialog.css',
					type: 'css'
				},

				/*
				* Component Overlay
				*/
				'component-overlay': {
					fullpath: PATH_JAVASCRIPT + 'component-overlay.js',
					requires: [ 'component', 'widget-position', 'widget-stack', 'widget-position-ext', 'widget-stdmod' ]
				},

				/*
				* Tabs
				*/
				'tabs': {
					fullpath: PATH_JAVASCRIPT + 'tabs.js',
					requires: ['component', 'state-interaction', 'tabs-css']
				},
				'tabs-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tabs.css',
					type: 'css'
				},

				/*
				* Resize
				*/
				'resize': {
					fullpath: PATH_JAVASCRIPT + 'resize.js',
					requires: [ 'aui-base', 'dd', 'resize-css' ]
				},
				'resize-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'resize.css',
					type: 'css'
				},
				'resize-plugin': {
					fullpath: PATH_JAVASCRIPT + 'resize.js',
					requires: [ 'resize' ]
				},

				/*
				* Sortable
				*/
				'sortable': {
					fullpath: PATH_JAVASCRIPT + 'sortable.js',
					requires: [ 'aui-base', 'dd', 'sortable-css' ]
				},
				'sortable-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'sortable.css',
					type: 'css'
				},

				/*
				* LiveSearch
				*/
				'live-search': {
					fullpath: PATH_JAVASCRIPT + 'live-search.js',
					requires: [ 'aui-base' ]
				},

				/*
				* Nested list
				*/
				'nested-list': {
					fullpath: PATH_JAVASCRIPT + 'nested-list.js',
					requires: [ 'aui-base', 'dd' ]
				},

				/*
				* ContextOverlay
				*/
				'context-overlay': {
					fullpath: PATH_JAVASCRIPT + 'context-overlay.js',
					requires: [ 'aui-base', 'component-overlay', 'overlay-manager', 'delayed-task' ]
				},

				/*
				* OverlayManager
				*/
				'overlay-manager': {
					fullpath: PATH_JAVASCRIPT + 'overlay-manager.js',
					requires: [ 'aui-base', 'component', 'component-overlay', 'overlay', 'plugin' ]
				},

				/*
				* OverlayMask
				*/
				'overlay-mask': {
					fullpath: PATH_JAVASCRIPT + 'overlay-mask.js',
					requires: [ 'aui-base', 'component-overlay', 'event-resize' ]
				},

				/*
				* Module
				*/
				'panel': {
					fullpath: PATH_JAVASCRIPT + 'panel.js',
					requires: [ 'panel-css', 'component', 'widget-stdmod', 'tool-set' ]
				},
				'panel-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'panel.css',
					type: 'css'
				},

				/*
				* Form
				*/
				'form': {
					fullpath: PATH_JAVASCRIPT + 'form.js',
					requires: [ 'aui-base', 'data-set', 'io-form', 'field' ]
				},

				/*
				* Fieldset
				*/
				'fieldset': {
					fullpath: PATH_JAVASCRIPT + 'fieldset.js',
					requires: [ 'panel' ]
				},

				/*
				* Field
				*/
				'field': {
					fullpath: PATH_JAVASCRIPT + 'field.js',
					requires: [ 'substitute' ]
				},

				/*
				* Textfield
				*/
				'textfield': {
					fullpath: PATH_JAVASCRIPT + 'textfield.js',
					requires: [ 'field' ]
				},

				/*
				* Textarea
				*/
				'textarea': {
					fullpath: PATH_JAVASCRIPT + 'textarea.js',
					requires: [ 'textfield', 'textarea-css' ]
				},
				'textarea-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'textarea.css',
					type: 'css'
				},

				/*
				* Combobox
				*/
				'combobox': {
					fullpath: PATH_JAVASCRIPT + 'combobox.js',
					requires: [ 'textarea', 'combobox-css', 'tool-set' ]
				},
				'combobox-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'combobox.css',
					type: 'css'
				},

				/*
				* Component
				*/
				'component': {
					fullpath: PATH_JAVASCRIPT + 'component.js',
					requires: [ 'widget' ]
				},

				/*
				* StdModIOPlugin
				*/
				'io-stdmod': {
					fullpath: PATH_JAVASCRIPT + 'io-stdmod.js',
					requires: [ 'aui-base', 'component-overlay', 'io', 'plugin' ]
				},

				/*
				* Input Event Handler
				*/
				'input-handler': {
					fullpath: PATH_JAVASCRIPT + 'input-handler.js'
				},

				/*
				* Image Viewer
				*/
				'image-viewer': {
					fullpath: PATH_JAVASCRIPT + 'image-viewer.js',
					requires: [ 'aui-base', 'anim', 'overlay-mask', 'substitute', 'image-viewer-css' ]
				},

				'image-viewer-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'image-viewer.css',
					type: 'css'
				},

				/*
				* ImageGallery
				*/
				'image-gallery': {
					fullpath: PATH_JAVASCRIPT + 'image-gallery.js',
					requires: [ 'image-viewer', 'paginator', 'image-gallery-css' ]
				},

				'image-gallery-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'image-gallery.css',
					type: 'css'
				},

				/*
				* State Interaction plugin
				*/
				'state-interaction': {
					fullpath: PATH_JAVASCRIPT + 'state-interaction.js',
					requires: [ 'aui-base', 'plugin' ]
				}
			},

			paths: {
				images: PATH_THEME_IMAGES,
				javascript: PATH_JAVASCRIPT,
				theme: PATH_THEME_ROOT
			}
		}
	}
})();<commit_msg>-css module requires must be last in list<commit_after>/*
 * Alloy JavaScript Library v0.1
 * http://alloyui.com/
 *
 * Copyright (c) 2009 Liferay Inc.
 * Licensed under the MIT license.
 * http://alloyui.com/License
 *
 * Date: @DATE
 * Revision: @REVISION
 */

;(function() {
	var PATH_BASE = YUI.config.base + '../../../';
	var PATH_JAVASCRIPT = PATH_BASE + 'src/javascript/';
	var PATH_THEME_ROOT = PATH_BASE + 'themes/base/css/';
	var PATH_THEME_IMAGES = PATH_THEME_ROOT + '../images/';

	window.AUI = {
		defaults: {
			classNamePrefix: 'aui',

			//base: '',

			defaultModules: [ 'aui-base' ],

			filter: 'raw',

			modules: {

				/*
				* AUI Base modules
				*/
				'aui-base': {
					fullpath: PATH_JAVASCRIPT + 'base.js',
					requires: [ 'event', 'oop', 'component', 'aui-node', 'collection' ]
				},

				/*
				* Data Set
				*/
				'data-set': {
					fullpath: PATH_JAVASCRIPT + 'data-set.js',
					requires: [ 'oop', 'collection', 'base' ]
				},

				/*
				* AutoComplete
				*/
				'autocomplete': {
					fullpath: PATH_JAVASCRIPT + 'autocomplete.js',
					requires: [ 'aui-base', 'component-overlay', 'datasource', 'dataschema', 'combobox', 'autocomplete-css' ]
				},
				'autocomplete-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'autocomplete.css',
					type: 'css'
				},

				/*
				* Editable
				*/
				'editable': {
					fullpath: PATH_JAVASCRIPT + 'editable.js',
					requires: [ 'aui-base', 'combobox', 'textarea', 'editable-css' ]
				},
				'editable-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'editable.css',
					type: 'css'
				},

				/*
				* Paginator
				*/
				'paginator': {
					fullpath: PATH_JAVASCRIPT + 'paginator.js',
					requires: [ 'aui-base', 'substitute', 'paginator-css' ]
				},
				'paginator-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'paginator.css',
					type: 'css'
				},

				/*
				* Rating
				*/
				'rating': {
					fullpath: PATH_JAVASCRIPT + 'rating.js',
					requires: [ 'aui-base', 'rating-css' ]
				},
				'rating-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'rating.css',
					type: 'css'
				},

				/*
				* Tool Item
				*/
				'tool-item': {
					fullpath: PATH_JAVASCRIPT + 'tool-item.js',
					requires: [ 'aui-base', 'state-interaction', 'tool-item-css' ]
				},
				'tool-item-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tool-item.css',
					type: 'css'
				},

				/*
				* Tool Set
				*/
				'tool-set': {
					fullpath: PATH_JAVASCRIPT + 'tool-set.js',
					requires: [ 'data-set', 'tool-item', 'tool-set-css' ]
				},
				'tool-set-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tool-set.css',
					type: 'css'
				},

				/*
				* Calendar
				*/
				'calendar': {
					fullpath: PATH_JAVASCRIPT + 'calendar.js',
					requires: [ 'aui-base', 'context-overlay', 'overlay-manager', 'datatype-date', 'calendar-css' ]
				},
				'calendar-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'calendar.css',
					type: 'css'
				},

				/*
				* Calendar
				*/
				'char-counter': {
					fullpath: PATH_JAVASCRIPT + 'char-counter.js',
					requires: [ 'aui-base', 'input-handler' ]
				},

				/*
				* DatePickerSelect
				*/
				'date-picker-select': {
					fullpath: PATH_JAVASCRIPT + 'date-picker-select.js',
					requires: [ 'calendar', 'tool-item', 'date-picker-select-css' ]
				},
				'date-picker-select-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'date-picker-select.css',
					type: 'css'
				},

				/*
				* ContextPanel
				*/
				'context-panel': {
					fullpath: PATH_JAVASCRIPT + 'context-panel.js',
					requires: [ 'context-overlay', 'anim', 'context-panel-css' ]
				},
				'context-panel-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'context-panel.css',
					type: 'css'
				},

				/*
				* ColorPicker
				*/
				'color-picker': {
					fullpath: PATH_JAVASCRIPT + 'color-picker.js',
					requires: [ 'context-overlay', 'dd', 'slider', 'substitute', 'tool-item', 'form', 'panel', 'color-picker-css' ]
				},
				'color-picker-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'color-picker.css',
					type: 'css'
				},

				/*
				* Tooltip
				*/
				'tooltip': {
					fullpath: PATH_JAVASCRIPT + 'tooltip.js',
					requires: [ 'context-panel', 'tooltip-css' ]
				},
				'tooltip-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tooltip.css',
					type: 'css'
				},

				/*
				* TreeData
				*/
				'tree-data': {
					fullpath: PATH_JAVASCRIPT + 'tree-data.js',
					requires: [ 'aui-base' ]
				},

				/*
				* TreeNode
				*/
				'tree-node': {
					fullpath: PATH_JAVASCRIPT + 'tree-node.js',
					requires: [ 'tree-data', 'io', 'json', 'tree-css' ]
				},

				/*
				* TreeView
				*/
				'tree-view': {
					fullpath: PATH_JAVASCRIPT + 'tree-view.js',
					requires: [ 'tree-node', 'dd', 'tree-css' ]
				},

				'tree-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tree.css',
					type: 'css'
				},

				/*
				* TextboxList
				*/
				'textboxlist': {
					fullpath: PATH_JAVASCRIPT + 'textboxlist.js',
					requires: [ 'anim-node-plugin', 'aui-base', 'autocomplete', 'node-focusmanager', 'textboxlist-css' ]
				},

				'textboxlist-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'textboxlist.css',
					type: 'css'
				},

				/*
				* Dialog
				*/
				'dialog': {
					fullpath: PATH_JAVASCRIPT + 'dialog.js',
					requires: [ 'plugin', 'panel', 'dd-constrain', 'aui-base', 'tool-item', 'overlay-manager', 'overlay-mask', 'io-stdmod', 'dialog-css' ]
				},
				'dialog-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'dialog.css',
					type: 'css'
				},

				/*
				* Component Overlay
				*/
				'component-overlay': {
					fullpath: PATH_JAVASCRIPT + 'component-overlay.js',
					requires: [ 'component', 'widget-position', 'widget-stack', 'widget-position-ext', 'widget-stdmod' ]
				},

				/*
				* Tabs
				*/
				'tabs': {
					fullpath: PATH_JAVASCRIPT + 'tabs.js',
					requires: ['component', 'state-interaction', 'tabs-css']
				},
				'tabs-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'tabs.css',
					type: 'css'
				},

				/*
				* Resize
				*/
				'resize': {
					fullpath: PATH_JAVASCRIPT + 'resize.js',
					requires: [ 'aui-base', 'dd', 'resize-css' ]
				},
				'resize-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'resize.css',
					type: 'css'
				},
				'resize-plugin': {
					fullpath: PATH_JAVASCRIPT + 'resize.js',
					requires: [ 'resize' ]
				},

				/*
				* Sortable
				*/
				'sortable': {
					fullpath: PATH_JAVASCRIPT + 'sortable.js',
					requires: [ 'aui-base', 'dd', 'sortable-css' ]
				},
				'sortable-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'sortable.css',
					type: 'css'
				},

				/*
				* LiveSearch
				*/
				'live-search': {
					fullpath: PATH_JAVASCRIPT + 'live-search.js',
					requires: [ 'aui-base' ]
				},

				/*
				* Nested list
				*/
				'nested-list': {
					fullpath: PATH_JAVASCRIPT + 'nested-list.js',
					requires: [ 'aui-base', 'dd' ]
				},

				/*
				* ContextOverlay
				*/
				'context-overlay': {
					fullpath: PATH_JAVASCRIPT + 'context-overlay.js',
					requires: [ 'aui-base', 'component-overlay', 'overlay-manager', 'delayed-task' ]
				},

				/*
				* OverlayManager
				*/
				'overlay-manager': {
					fullpath: PATH_JAVASCRIPT + 'overlay-manager.js',
					requires: [ 'aui-base', 'component', 'component-overlay', 'overlay', 'plugin' ]
				},

				/*
				* OverlayMask
				*/
				'overlay-mask': {
					fullpath: PATH_JAVASCRIPT + 'overlay-mask.js',
					requires: [ 'aui-base', 'component-overlay', 'event-resize' ]
				},

				/*
				* Module
				*/
				'panel': {
					fullpath: PATH_JAVASCRIPT + 'panel.js',
					requires: [ 'component', 'widget-stdmod', 'tool-set', 'panel-css' ]
				},
				'panel-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'panel.css',
					type: 'css'
				},

				/*
				* Form
				*/
				'form': {
					fullpath: PATH_JAVASCRIPT + 'form.js',
					requires: [ 'aui-base', 'data-set', 'io-form', 'field' ]
				},

				/*
				* Fieldset
				*/
				'fieldset': {
					fullpath: PATH_JAVASCRIPT + 'fieldset.js',
					requires: [ 'panel' ]
				},

				/*
				* Field
				*/
				'field': {
					fullpath: PATH_JAVASCRIPT + 'field.js',
					requires: [ 'substitute' ]
				},

				/*
				* Textfield
				*/
				'textfield': {
					fullpath: PATH_JAVASCRIPT + 'textfield.js',
					requires: [ 'field' ]
				},

				/*
				* Textarea
				*/
				'textarea': {
					fullpath: PATH_JAVASCRIPT + 'textarea.js',
					requires: [ 'textfield', 'textarea-css' ]
				},
				'textarea-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'textarea.css',
					type: 'css'
				},

				/*
				* Combobox
				*/
				'combobox': {
					fullpath: PATH_JAVASCRIPT + 'combobox.js',
					requires: [ 'textarea', 'tool-set', 'combobox-css' ]
				},
				'combobox-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'combobox.css',
					type: 'css'
				},

				/*
				* Component
				*/
				'component': {
					fullpath: PATH_JAVASCRIPT + 'component.js',
					requires: [ 'widget' ]
				},

				/*
				* StdModIOPlugin
				*/
				'io-stdmod': {
					fullpath: PATH_JAVASCRIPT + 'io-stdmod.js',
					requires: [ 'aui-base', 'component-overlay', 'io', 'plugin' ]
				},

				/*
				* Input Event Handler
				*/
				'input-handler': {
					fullpath: PATH_JAVASCRIPT + 'input-handler.js'
				},

				/*
				* Image Viewer
				*/
				'image-viewer': {
					fullpath: PATH_JAVASCRIPT + 'image-viewer.js',
					requires: [ 'aui-base', 'anim', 'overlay-mask', 'substitute', 'image-viewer-css' ]
				},

				'image-viewer-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'image-viewer.css',
					type: 'css'
				},

				/*
				* ImageGallery
				*/
				'image-gallery': {
					fullpath: PATH_JAVASCRIPT + 'image-gallery.js',
					requires: [ 'image-viewer', 'paginator', 'image-gallery-css' ]
				},

				'image-gallery-css': {
					ext: false,
					fullpath: PATH_THEME_ROOT + 'image-gallery.css',
					type: 'css'
				},

				/*
				* State Interaction plugin
				*/
				'state-interaction': {
					fullpath: PATH_JAVASCRIPT + 'state-interaction.js',
					requires: [ 'aui-base', 'plugin' ]
				}
			},

			paths: {
				images: PATH_THEME_IMAGES,
				javascript: PATH_JAVASCRIPT,
				theme: PATH_THEME_ROOT
			}
		}
	}
})();<|endoftext|>


<commit_before>var assert = require('assert');
var utils = require('./utils.js');

require('../index.js');

describe('API basic tests', function() {

	it('basic', function() {

		assert.strictEqual(require('module'), module.constructor);
		assert.equal(typeof module.constructor._cache, 'object');
		assert.equal(typeof module.constructor._pathCache, 'object');
	});

	it('module.invalidateByPath()', function() {

		var foo = 1;
		var mod = new utils.TmpModule().set(_ => `
			module.invalidable = true;
			module.exports = {
				foo: ${foo}
			}
		`);

		assert.equal(mod.module.exports.foo, 1);
		foo++;
		mod.set();
		assert.equal(mod.module.exports.foo, 1);
		module.invalidateByPath(mod.module.filename);
		assert.equal(mod.module.exports.foo, 2);
	});

	it('Module.invalidateByExports()', function() {

		var foo = 1;

		var mod = new utils.TmpModule().set(_ =>`
			module.invalidable = true;
			module.exports = {
				foo: ${foo}
			}
		`);

		assert.equal(mod.module.exports.foo, 1);
		foo++;
		mod.set();
		mod.module.constructor.invalidateByExports(mod.module.exports);
		assert.equal(mod.module.exports.foo, 2);
	});

	it('module.invalidate()', function() {

		var foo = 1;

		var mod = new utils.TmpModule(_ =>`
			module.invalidable = true;
			module.exports = {
				foo: ${foo}
			}
		`);

		assert.equal(mod.module.exports.foo, 1);
		foo++;
		mod.set();
		mod.module.invalidate();
		assert.equal(mod.module.exports.foo, 2);
	});

	it('exports access level', function() {

		var count = 1;

		var mod = new utils.TmpModule(_ =>`
			module.invalidable = true;
			module.exports = {
				a: {
					b: {
						c: ${count}
					}
				}
			}
		`);

		var b = mod.module.exports.a.b;

		assert.equal(mod.module.exports.a.b.c, 1);
		assert.equal(b.c, 1);

		count++;
		mod.set();
		mod.module.invalidate();

		assert.equal(mod.module.exports.a.b.c, 2);
		assert.equal(b.c, 1);
	});

	it('selective reload', function() {

		var mB = new utils.TmpModule(_ =>`
			module.invalidable = true;
			var val = 0;
			module.exports = function() {

				return (val++);
			}
		`);

		var mA = new utils.TmpModule(_ =>`
			module.invalidable = true;
			const m = require(${utils.quoteString(mB.filename)});
			var val = 0;
			module.exports = function() {

				return (val++)+','+m();
			}
		`);

		assert.equal(mA.module.exports(), '0,0');
		assert.equal(mA.module.exports(), '1,1');
		mA.module.invalidate();
		assert.equal(mA.module.exports(), '0,2');
		assert.equal(mA.module.exports(), '1,3');
		mB.module.invalidate();
		assert.equal(mA.module.exports(), '2,0');
		assert.equal(mA.module.exports(), '3,1');
	});

	it('selective reload nested', function() {

		global.report = '';

		var mC = new utils.TmpModule(_ =>`
			global.report += 'c';
			module.invalidable = true;
		`, { autoLoad: false });

		var mB = new utils.TmpModule(_ =>`
			global.report += 'b';
			module.invalidable = true;
			require(${utils.quoteString(mC.filename)});
		`, { autoLoad: false });

		var mA = new utils.TmpModule(_ =>`
			global.report += 'a';
			module.invalidable = true;
			require(${utils.quoteString(mB.filename)});
		`);

		mA.load();

		assert.equal(global.report, 'abc');

		mB.module.invalidate();

		mA.module.exports.foobar;
		mB.module.exports.foobar;
		mC.module.exports.foobar;

		assert.equal(global.report, 'abcb');

		delete global.report;

	});

	it('invalidateByExports unique', function() {

		global.report = '';

		var mB = new utils.TmpModule(_ =>`
			global.report += 'b';
			module.invalidable = true;
			module.exports = { foo: 'bar' };
		`, { autoLoad: false });

		var mA = new utils.TmpModule(_ =>`
			global.report += 'a';
			module.invalidable = true;
			module.exports = require(${utils.quoteString(mB.filename)});
		`);

		mA.load();

		assert.equal(global.report, 'ab');

		module.constructor.invalidateByExports(mA.module.exports);
		mA.module.exports.foo;
		mB.module.exports.foo;

		assert.equal(global.report, 'aba');

		module.constructor.invalidateByExports(mB.module.exports);
		mA.module.exports.foo;
		mB.module.exports.foo;

		assert.equal(global.report, 'abab');

		delete global.report;

	});

});
<commit_msg>- test proxy behavior<commit_after>var assert = require('assert');
var utils = require('./utils.js');

require('../index.js');

describe('API basic tests', function() {

	it('basic', function() {

		assert.strictEqual(require('module'), module.constructor);
		assert.equal(typeof module.constructor._cache, 'object');
		assert.equal(typeof module.constructor._pathCache, 'object');
	});

	it('export proxy', function() {

		var foo = 1;
		var mod = new utils.TmpModule().set(_ => `
			module.invalidable = true;
			module.exports = {
				foo: ${foo}
			}
		`, { autoload: false });

		var exp = require(mod.module.filename);

		assert.equal(exp.foo, 1);
		foo++;
		mod.set();
		module.invalidateByPath(mod.module.filename);
		assert.equal(exp.foo, 2);
	});

	it('module.invalidateByPath()', function() {

		var foo = 1;
		var mod = new utils.TmpModule().set(_ => `
			module.invalidable = true;
			module.exports = {
				foo: ${foo}
			}
		`);

		assert.equal(mod.module.exports.foo, 1);
		foo++;
		mod.set();
		assert.equal(mod.module.exports.foo, 1);
		module.invalidateByPath(mod.module.filename);
		assert.equal(mod.module.exports.foo, 2);
	});

	it('Module.invalidateByExports()', function() {

		var foo = 1;

		var mod = new utils.TmpModule().set(_ =>`
			module.invalidable = true;
			module.exports = {
				foo: ${foo}
			}
		`);

		assert.equal(mod.module.exports.foo, 1);
		foo++;
		mod.set();
		mod.module.constructor.invalidateByExports(mod.module.exports);
		assert.equal(mod.module.exports.foo, 2);
	});

	it('module.invalidate()', function() {

		var foo = 1;

		var mod = new utils.TmpModule(_ =>`
			module.invalidable = true;
			module.exports = {
				foo: ${foo}
			}
		`);

		assert.equal(mod.module.exports.foo, 1);
		foo++;
		mod.set();
		mod.module.invalidate();
		assert.equal(mod.module.exports.foo, 2);
	});

	it('exports access level', function() {

		var count = 1;

		var mod = new utils.TmpModule(_ =>`
			module.invalidable = true;
			module.exports = {
				a: {
					b: {
						c: ${count}
					}
				}
			}
		`);

		var b = mod.module.exports.a.b;

		assert.equal(mod.module.exports.a.b.c, 1);
		assert.equal(b.c, 1);

		count++;
		mod.set();
		mod.module.invalidate();

		assert.equal(mod.module.exports.a.b.c, 2);
		assert.equal(b.c, 1);
	});

	it('selective reload', function() {

		var mB = new utils.TmpModule(_ =>`
			module.invalidable = true;
			var val = 0;
			module.exports = function() {

				return (val++);
			}
		`);

		var mA = new utils.TmpModule(_ =>`
			module.invalidable = true;
			const m = require(${utils.quoteString(mB.filename)});
			var val = 0;
			module.exports = function() {

				return (val++)+','+m();
			}
		`);

		assert.equal(mA.module.exports(), '0,0');
		assert.equal(mA.module.exports(), '1,1');
		mA.module.invalidate();
		assert.equal(mA.module.exports(), '0,2');
		assert.equal(mA.module.exports(), '1,3');
		mB.module.invalidate();
		assert.equal(mA.module.exports(), '2,0');
		assert.equal(mA.module.exports(), '3,1');
	});

	it('selective reload nested', function() {

		global.report = '';

		var mC = new utils.TmpModule(_ =>`
			global.report += 'c';
			module.invalidable = true;
		`, { autoLoad: false });

		var mB = new utils.TmpModule(_ =>`
			global.report += 'b';
			module.invalidable = true;
			require(${utils.quoteString(mC.filename)});
		`, { autoLoad: false });

		var mA = new utils.TmpModule(_ =>`
			global.report += 'a';
			module.invalidable = true;
			require(${utils.quoteString(mB.filename)});
		`);

		mA.load();

		assert.equal(global.report, 'abc');

		mB.module.invalidate();

		mA.module.exports.foobar;
		mB.module.exports.foobar;
		mC.module.exports.foobar;

		assert.equal(global.report, 'abcb');

		delete global.report;

	});

	it('invalidateByExports unique', function() {

		global.report = '';

		var mB = new utils.TmpModule(_ =>`
			global.report += 'b';
			module.invalidable = true;
			module.exports = { foo: 'bar' };
		`, { autoLoad: false });

		var mA = new utils.TmpModule(_ =>`
			global.report += 'a';
			module.invalidable = true;
			module.exports = require(${utils.quoteString(mB.filename)});
		`);

		mA.load();

		assert.equal(global.report, 'ab');

		module.constructor.invalidateByExports(mA.module.exports);
		mA.module.exports.foo;
		mB.module.exports.foo;

		assert.equal(global.report, 'aba');

		module.constructor.invalidateByExports(mB.module.exports);
		mA.module.exports.foo;
		mB.module.exports.foo;

		assert.equal(global.report, 'abab');

		delete global.report;

	});

});
<|endoftext|>


<commit_before>var request = require('supertest');
var assert = require('assert');
var app = require('../server');

// Sets tests config
app.set('app.config', {
    app: {
        verbose: true,
        port: process.env.PORT || 3000,
        allowed_domains: ["*"]
    },
    es: {
        host: "127.0.0.1:9200",
        name: "tests",
        collection: "cities",
        size: 30
    },
    mongo: {
        url: "tests",
        countrynames: "countrynames",
        admincodes: "admincodes"
    },
    geo: {
        geolitepath: './resources/data/GeoLiteCity.dat',
        default_lon: 0,
        default_lat: 0
    }
});

describe('Tests accepted content types', function() {
    describe('GET /city', function() {
        it('responds with a XML file', function(done) {
            request(app)
                    .get('/city/')
                    .set('Accept', 'text/xml')
                    .expect('Content-Type', "text/xml; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city', function() {
        it('responds with a JSON file', function(done) {
            request(app)
                    .get('/city')
                    .set('Accept', 'application/json')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/city')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/city')
                    .set('Accept', 'text/html')
                    .expect(406, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('responds with a XML file', function(done) {
            request(app)
                    .get('/city/2988507')
                    .set('Accept', 'text/xml')
                    .expect('Content-Type', "text/xml; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('responds with a JSON file', function(done) {
            request(app)
                    .get('/city/2988507')
                    .set('Accept', 'application/json')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/city/2988507')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/city/2988507')
                    .set('Accept', 'text/html')
                    .expect(406, done);
        });
    });

    describe('GET /ip', function() {
        it('responds with a XML file', function(done) {
            request(app)
                    .get('/ip')
                    .set('Accept', 'text/xml')
                    .expect('Content-Type', "text/xml; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /ip', function() {
        it('responds with a JSON file', function(done) {
            request(app)
                    .get('/ip')
                    .set('Accept', 'application/json')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /ip', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/ip')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /ip', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/ip')
                    .set('Accept', 'text/html')
                    .expect(406, done);
        });
    });
});

describe('Tests / route', function() {
    describe('GET /', function() {
        it('Return a 200 code', function(done) {
            request(app)
                    .get('/')
                    .expect(200,done);
        });
    });
});

describe('Tests functionnal', function() {
    describe('GET /random_url', function() {
        it('accesses non-existing URL', function(done) {
            request(app)
                    .get('/random_url')
                    .expect(404, done);
        });
    });
});

describe('Tests /city route', function() {

    describe('GET /city?name=paris', function() {
        it('Returns a collection when providing a full name', function(done) {
            request(app)
                    .get('/city?name=paris')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount,30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&limit=1', function() {
        it('Returns a collection with one result', function(done) {
            request(app)
                    .get('/city?name=paris&limit=1')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount,1, "Expecting 1 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=pa', function() {
        it('Returns a collection when providing an incomplete name', function(done) {
            request(app)
                    .get('/city?name=pa')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city', function() {
        it('Returns a collection', function(done) {
            request(app)
                    .get('/city')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=%20paris%20', function() {
        it('Returns a response when providing a name with space chars', function(done) {
            request(app)
                    .get('/city?name=%20paris%20')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=population', function() {
        it('Returns a response when sorting by population', function(done) {
            request(app)
                    .get('/city?name=paris&sort=population')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        var first = result.geonames.geoname.shift();
                        var second = result.geonames.geoname.shift();
                        var third = result.geonames.geoname.shift();
                        assert(first.population > second.population);
                        assert(second.population > third.population);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=closeness', function() {
        it('Returns a collection when sorting by closeness', function(done) {
            request(app)
                    .get('/city?name=paris')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=closeness&sortParams[ip]=173.194.40.162&limit=1', function() {
        it('Returns a collection when sorting by closeness and providing an ip', function(done) {
            request(app)
                    .get('/city?name=paris&sort=closeness&sortParams[ip]=173.194.40.162&limit=1')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 1, "Expecting 1 got " + result.geonames.totalResultsCount);
                        var result = result.geonames.geoname.pop();
                        assert(result.country.indexOf("United") !== -1, "Expecting to find 'United' in " + result.country);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=closeness&sortParams[ip]=invalid-ip', function() {
        it('Returns 400 when ip is not valid', function(done) {
            request(app)
                    .get('/city?name=paris&sort=closeness&sortParams[ip]=invalid-ip')
                    .expect(400, done);
        });
    });

    describe('GET /city?name=paris&sort=unknown', function() {
        it('Returns 400 when sort is not valid', function(done) {
            request(app)
                    .get('/city?name=paris&sort=unknown')
                    .expect(400, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('Find Paris by geonameid', function(done) {
            request(app)
                    .get('/city/2988507')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 1, "Expecting 1 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city/0000000', function() {
        it('Returns nothing when city can not be found', function(done) {
            request(app)
                    .get('/city/0000000')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 0, "Expecting 0 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&country=aaaaaaaaaa', function() {
        it('Cant find paris in a non-existing country', function(done) {
            request(app)
                    .get('/city?name=paris&country=aaaaaaaaaa')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 0, "Expecting 0 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&country=fr', function() {
        it('Find paris in a france', function(done) {
            request(app)
                    .get('/city?name=paris&country=fr')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 2, "Expecting 2 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=avg', function() {
        it('Returns collection when sorting', function(done) {
            request(app)
                    .get('/city?name=paris&sort=asc')
                    .expect(400, done);
        });
    });

    describe('GET /city?name=paris&order=asc', function() {
        it('Returns collection when sorting', function(done) {
            request(app)
                    .get('/city?name=paris&order=asc')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=population&order=desc', function() {
        it('Returns collection when sorting', function(done) {
            request(app)
                    .get('/city?name=paris&order=desc')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });
});
<commit_msg>Add unit tests<commit_after>var request = require('supertest');
var assert = require('assert');
var app = require('../server');

// Sets tests config
app.set('app.config', {
    app: {
        verbose: true,
        port: process.env.PORT || 3000,
        allowed_domains: ["*"]
    },
    es: {
        host: "127.0.0.1:9200",
        name: "tests",
        collection: "cities",
        size: 30
    },
    mongo: {
        url: "tests",
        countrynames: "countrynames",
        admincodes: "admincodes"
    },
    geo: {
        geolitepath: './resources/data/GeoLiteCity.dat',
        default_lon: 0,
        default_lat: 0
    }
});

describe('Tests accepted content types', function() {
    describe('GET /city', function() {
        it('responds with a XML file', function(done) {
            request(app)
                    .get('/city/')
                    .set('Accept', 'text/xml')
                    .expect('Content-Type', "text/xml; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city', function() {
        it('responds with a JSON file', function(done) {
            request(app)
                    .get('/city')
                    .set('Accept', 'application/json')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/city')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/city')
                    .set('Accept', 'text/html')
                    .expect(406, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('responds with a XML file', function(done) {
            request(app)
                    .get('/city/2988507')
                    .set('Accept', 'text/xml')
                    .expect('Content-Type', "text/xml; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('responds with a JSON file', function(done) {
            request(app)
                    .get('/city/2988507')
                    .set('Accept', 'application/json')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/city/2988507')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/city/2988507')
                    .set('Accept', 'text/html')
                    .expect(406, done);
        });
    });

    describe('GET /ip', function() {
        it('responds with a XML file', function(done) {
            request(app)
                    .get('/ip')
                    .set('Accept', 'text/xml')
                    .expect('Content-Type', "text/xml; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /ip', function() {
        it('responds with a JSON file', function(done) {
            request(app)
                    .get('/ip')
                    .set('Accept', 'application/json')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /ip', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/ip')
                    .expect('Content-Type', "application/json; charset=utf-8")
                    .expect(200, done);
        });
    });

    describe('GET /ip', function() {
        it('by default responds with a JSON file', function(done) {
            request(app)
                    .get('/ip')
                    .set('Accept', 'text/html')
                    .expect(406, done);
        });
    });
});

describe('Tests / route', function() {
    describe('GET /', function() {
        it('Return a 200 code', function(done) {
            request(app)
                    .get('/')
                    .expect(200,done);
        });
    });
});

describe('Tests functionnal', function() {
    describe('GET /random_url', function() {
        it('accesses non-existing URL', function(done) {
            request(app)
                    .get('/random_url')
                    .expect(404, done);
        });
    });
});

describe('Tests /city route', function() {

    describe('GET /city?name=paris', function() {
        it('Returns a collection when providing a full name', function(done) {
            request(app)
                    .get('/city?name=paris')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount,30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&limit=1', function() {
        it('Returns a collection with one result', function(done) {
            request(app)
                    .get('/city?name=paris&limit=1')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount,1, "Expecting 1 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=pa', function() {
        it('Returns a collection when providing an incomplete name', function(done) {
            request(app)
                    .get('/city?name=pa')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city', function() {
        it('Returns a collection', function(done) {
            request(app)
                    .get('/city')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=%20paris%20', function() {
        it('Returns a response when providing a name with space chars', function(done) {
            request(app)
                    .get('/city?name=%20paris%20')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=population', function() {
        it('Returns a response when sorting by population', function(done) {
            request(app)
                    .get('/city?name=paris&sort=population')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        var first = result.geonames.geoname.shift();
                        var second = result.geonames.geoname.shift();
                        var third = result.geonames.geoname.shift();
                        assert(first.population > second.population);
                        assert(second.population > third.population);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=closeness', function() {
        it('Returns a collection when sorting by closeness', function(done) {
            request(app)
                    .get('/city?name=paris')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=closeness&sortParams[ip]=173.194.40.162&limit=1', function() {
        it('Returns a collection when sorting by closeness and providing an ip', function(done) {
            request(app)
                    .get('/city?name=paris&sort=closeness&sortParams[ip]=173.194.40.162&limit=1')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 1, "Expecting 1 got " + result.geonames.totalResultsCount);
                        var result = result.geonames.geoname.pop();
                        assert(result.country.indexOf("United") !== -1, "Expecting to find 'United' in " + result.country);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=closeness&sortParams[ip]=invalid-ip', function() {
        it('Returns 400 when ip is not valid', function(done) {
            request(app)
                    .get('/city?name=paris&sort=closeness&sortParams[ip]=invalid-ip')
                    .expect(400, done);
        });
    });

    describe('GET /city?name=paris&sort=closeness&sortParams[ip]=127.0.0.1', function() {
        it('Test fallback to sort by population if geo ip failed', function(done) {
            request(app)
                    .get('/city?name=paris&sort=closeness&sortParams[ip]=127.0.0.1')
                    .expect(200).
                    end(function(err, res) {
                        if (err) return done(err);
                        assert.equal(res.header['x-geonames-sortby'], 'population');
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=unknown', function() {
        it('Returns 400 when sort is not valid', function(done) {
            request(app)
                    .get('/city?name=paris&sort=unknown')
                    .expect(400, done);
        });
    });

    describe('GET /city/2988507', function() {
        it('Find Paris by geonameid', function(done) {
            request(app)
                    .get('/city/2988507')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 1, "Expecting 1 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city/0000000', function() {
        it('Returns nothing when city can not be found', function(done) {
            request(app)
                    .get('/city/0000000')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 0, "Expecting 0 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&country=aaaaaaaaaa', function() {
        it('Cant find paris in a non-existing country', function(done) {
            request(app)
                    .get('/city?name=paris&country=aaaaaaaaaa')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 0, "Expecting 0 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&country=fr', function() {
        it('Find paris in a france', function(done) {
            request(app)
                    .get('/city?name=paris&country=fr')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 2, "Expecting 2 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=avg', function() {
        it('Returns collection when sorting', function(done) {
            request(app)
                    .get('/city?name=paris&sort=asc')
                    .expect(400, done);
        });
    });

    describe('GET /city?name=paris&order=asc', function() {
        it('Returns collection when sorting', function(done) {
            request(app)
                    .get('/city?name=paris&order=asc')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });

    describe('GET /city?name=paris&sort=population&order=desc', function() {
        it('Returns collection when sorting', function(done) {
            request(app)
                    .get('/city?name=paris&order=desc')
                    .expect(200)
                    .end(function(err, res) {
                        if (err) return done(err);
                        var result = JSON.parse(res.text);
                        assert.equal(result.geonames.totalResultsCount, 30, "Expecting 30 got " + result.geonames.totalResultsCount);
                        done();
                    });
        });
    });
});
<|endoftext|>


<commit_before>var readdir = require("fs-readdir-recursive");
var assert  = require("assert");
var rimraf  = require("rimraf");
var mkdirp  = require("mkdirp");
var child   = require("child_process");
var path    = require("path");
var fs      = require("fs");
var _       = require("lodash");

var fixtureLoc = __dirname + "/fixtures/bin";
var tmpLoc = __dirname + "/tmp";

var readFile = function (filename) {
  return fs.readFileSync(filename, "utf8").trim();
};

var readDir = function (loc) {
  var files = {};
  if (fs.existsSync(loc)) {
    _.each(readdir(loc), function (filename) {
      var contents = readFile(loc + "/" + filename);
      files[filename] = contents;
    });
  }
  return files;
};

var saveInFiles = function (files) {
  _.each(files, function (content, filename) {
    var up = path.normalize(filename + "/..");
    mkdirp.sync(up);

    fs.writeFileSync(filename, content);
  });
};

var assertTest = function (stdout, stderr, opts) {
  var expectStderr = opts.stderr.trim();
  stderr = stderr.trim();

  if (opts.stderr) {
    if (opts.stderrContains) {
      assert.ok(_.contains(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
    } else {
      assert.equal(stderr, expectStderr, "stderr didn't match");
    }
  } else if (stderr) {
    throw new Error("stderr: " + JSON.stringify(stderr));
  }

  var expectStdout = opts.stdout.trim();
  stdout = stdout.trim();

  if (opts.stdout) {
    if (opts.stdoutContains) {
      assert.ok(_.contains(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
    } else {
      assert.equal(stdout, expectStdout, "stdout didn't match");
    }
  } else if (stdout) {
    throw new Error("stdout: " + JSON.stringify(stdout));
  }

  _.each(opts.outFiles, function (expect, filename) {
    var actual = readFile(filename);
    assert.equal(actual, expect, "out-file " + filename);
  });
};

var build = function (binName, testName, opts) {
  var binLoc = path.normalize(__dirname + "/../bin/" + binName);

  return function (callback) {
    saveInFiles(opts.inFiles);

    var args  = [binLoc].concat(opts.args);
    var spawn = child.spawn(process.execPath, args);

    var stderr = "";
    var stdout = "";

    spawn.stderr.on("data", function (chunk) {
      stderr += chunk;
    });

    spawn.stdout.on("data", function (chunk) {
      stdout += chunk;
    });

    spawn.on("close", function () {
      var err;

      try {
        assertTest(stdout, stderr, opts);
      } catch (e) {
        err = e;
      }

      if (err) {
        err.message = args.join(" ") + ": " + err.message;
      }

      callback(err);
    });

    if (opts.stdin) {
      spawn.stdin.write(opts.stdin);
      spawn.stdin.end();
    }
  };
};

before(function () {
  if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
  fs.mkdirSync(tmpLoc);
  process.chdir(tmpLoc);
});

_.each(fs.readdirSync(fixtureLoc), function (binName) {
  if (binName[0] === ".") return;

  var suiteLoc = fixtureLoc + "/" + binName;
  suite("bin/" + binName, function () {
    _.each(fs.readdirSync(fixtureLoc + "/" + binName), function (testName) {
      if (testName[0] === ".") return;

      var testLoc = suiteLoc + "/" + testName;

      var opts = {
        args: []
      };

      var optionsLoc = testLoc + "/options.json"
      if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));

      _.each(["stdout", "stdin", "stderr"], function (key) {
        var loc = testLoc + "/" + key + ".txt";
        if (fs.existsSync(loc)) {
          opts[key] = readFile(loc);
        } else {
          opts[key] = opts[key] || "";
        }
      });

      opts.outFiles = readDir(testLoc + "/out-files");
      opts.inFiles  = readDir(testLoc + "/in-files");

      test(testName, build(binName, testName, opts));
    });
  });
});

after(function () {
  rimraf.sync(tmpLoc);
});
<commit_msg>add longer timeout to bin tests<commit_after>var readdir = require("fs-readdir-recursive");
var assert  = require("assert");
var rimraf  = require("rimraf");
var mkdirp  = require("mkdirp");
var child   = require("child_process");
var path    = require("path");
var fs      = require("fs");
var _       = require("lodash");

var fixtureLoc = __dirname + "/fixtures/bin";
var tmpLoc = __dirname + "/tmp";

var readFile = function (filename) {
  return fs.readFileSync(filename, "utf8").trim();
};

var readDir = function (loc) {
  var files = {};
  if (fs.existsSync(loc)) {
    _.each(readdir(loc), function (filename) {
      var contents = readFile(loc + "/" + filename);
      files[filename] = contents;
    });
  }
  return files;
};

var saveInFiles = function (files) {
  _.each(files, function (content, filename) {
    var up = path.normalize(filename + "/..");
    mkdirp.sync(up);

    fs.writeFileSync(filename, content);
  });
};

var assertTest = function (stdout, stderr, opts) {
  var expectStderr = opts.stderr.trim();
  stderr = stderr.trim();

  if (opts.stderr) {
    if (opts.stderrContains) {
      assert.ok(_.contains(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
    } else {
      assert.equal(stderr, expectStderr, "stderr didn't match");
    }
  } else if (stderr) {
    throw new Error("stderr: " + JSON.stringify(stderr));
  }

  var expectStdout = opts.stdout.trim();
  stdout = stdout.trim();

  if (opts.stdout) {
    if (opts.stdoutContains) {
      assert.ok(_.contains(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
    } else {
      assert.equal(stdout, expectStdout, "stdout didn't match");
    }
  } else if (stdout) {
    throw new Error("stdout: " + JSON.stringify(stdout));
  }

  _.each(opts.outFiles, function (expect, filename) {
    var actual = readFile(filename);
    assert.equal(actual, expect, "out-file " + filename);
  });
};

var build = function (binName, testName, opts) {
  var binLoc = path.normalize(__dirname + "/../bin/" + binName);

  return function (callback) {
    this.timeout(5000);
    saveInFiles(opts.inFiles);

    var args  = [binLoc].concat(opts.args);
    var spawn = child.spawn(process.execPath, args);

    var stderr = "";
    var stdout = "";

    spawn.stderr.on("data", function (chunk) {
      stderr += chunk;
    });

    spawn.stdout.on("data", function (chunk) {
      stdout += chunk;
    });

    spawn.on("close", function () {
      var err;

      try {
        assertTest(stdout, stderr, opts);
      } catch (e) {
        err = e;
      }

      if (err) {
        err.message = args.join(" ") + ": " + err.message;
      }

      callback(err);
    });

    if (opts.stdin) {
      spawn.stdin.write(opts.stdin);
      spawn.stdin.end();
    }
  };
};

before(function () {
  if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
  fs.mkdirSync(tmpLoc);
  process.chdir(tmpLoc);
});

_.each(fs.readdirSync(fixtureLoc), function (binName) {
  if (binName[0] === ".") return;

  var suiteLoc = fixtureLoc + "/" + binName;
  suite("bin/" + binName, function () {
    _.each(fs.readdirSync(fixtureLoc + "/" + binName), function (testName) {
      if (testName[0] === ".") return;

      var testLoc = suiteLoc + "/" + testName;

      var opts = {
        args: []
      };

      var optionsLoc = testLoc + "/options.json"
      if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));

      _.each(["stdout", "stdin", "stderr"], function (key) {
        var loc = testLoc + "/" + key + ".txt";
        if (fs.existsSync(loc)) {
          opts[key] = readFile(loc);
        } else {
          opts[key] = opts[key] || "";
        }
      });

      opts.outFiles = readDir(testLoc + "/out-files");
      opts.inFiles  = readDir(testLoc + "/in-files");

      test(testName, build(binName, testName, opts));
    });
  });
});

after(function () {
  rimraf.sync(tmpLoc);
});
<|endoftext|>


<commit_before>var assert = require('assert'),
  bag = require('bagofholding'),
  mocha = require('mocha'),
  sandbox = require('sandboxed-module'),
  cli,
  checks;

describe('cli', function () {

  beforeEach(function () {
    checks = {};
    cli = sandbox.require('../lib/cli', {
      requires: {
        commander: {

        }
      },
      globals: {
        console: bag.mock.console(checks),
        process: bag.mock.process(checks)
      }
    });
  });

  describe('exit', function () {

    it('should exit with status code 0 when error does not exist', function () {
      cli.exit(null);
      assert.equal(checks.process_exit_code, 0);
    });

    it('should exit with status code 1 and logs the error message when error exists', function () {
      cli.exit(new Error('some error'));
      assert.equal(checks.console_error_messages.length, 1);
      assert.equal(checks.console_error_messages[0], 'some error');
      assert.equal(checks.process_exit_code, 1);
    });
  });

  describe('exit_cb', function () {

    it('should exit with status code 0 and logs the result when error does not exist and no success callback is specified', function () {
      cli.exit_cb()(null, 'some success');
      assert.equal(checks.console_log_messages.length, 1);
      assert.equal(checks.console_log_messages[0], 'some success');
      assert.equal(checks.process_exit_code, 0);
    });

    it('should exit with status code 1 and logs the error message when error exists and no error callback is specified', function () {
      cli.exit_cb()(new Error('some error'));
      assert.equal(checks.console_error_messages.length, 1);
      assert.equal(checks.console_error_messages[0], 'some error');
      assert.equal(checks.process_exit_code, 1);
    });

    it('should exit with status code 0 and call success callback when error does not exist and success callback is specified', function () {
      function successCb(result) {
        checks.success_result = result;
      }
      cli.exit_cb(null, successCb)(null, 'some success');
      assert.equal(checks.success_result, 'some success');
      assert.equal(checks.process_exit_code, 0);
    });

    it('should exit with status code 1 and call error callback when error exists and error callback is specified', function () {
      function errorCb(err) {
        checks.error_err = err;
      }
      cli.exit_cb(errorCb)(new Error('some error'));
      assert.equal(checks.error_err.message, 'some error');
      assert.equal(checks.process_exit_code, 1);
    });
  });
});<commit_msg>Replace assert with should.<commit_after>var assert = require('assert'),
  bag = require('bagofholding'),
  mocha = require('mocha'),
  sandbox = require('sandboxed-module'),
  should = require('should'),
  cli,
  checks;

describe('cli', function () {

  beforeEach(function () {
    checks = {};
    cli = sandbox.require('../lib/cli', {
      requires: {
        commander: {

        }
      },
      globals: {
        console: bag.mock.console(checks),
        process: bag.mock.process(checks)
      }
    });
  });

  describe('exit', function () {

    it('should exit with status code 0 when error does not exist', function () {
      cli.exit(null);
      checks.process_exit_code.should.equal(0);
    });

    it('should exit with status code 1 and logs the error message when error exists', function () {
      cli.exit(new Error('some error'));
      checks.console_error_messages.length.should.equal(1);
      checks.console_error_messages[0].should.equal('some error');
      checks.process_exit_code.should.equal(1);
    });
  });

  describe('exit_cb', function () {

    it('should exit with status code 0 and logs the result when error does not exist and no success callback is specified', function () {
      cli.exit_cb()(null, 'some success');
      checks.console_log_messages.length.should.equal(1);
      checks.console_log_messages[0].should.equal('some success');
      checks.process_exit_code.should.equal(0);
    });

    it('should exit with status code 1 and logs the error message when error exists and no error callback is specified', function () {
      cli.exit_cb()(new Error('some error'));
      checks.console_error_messages.length.should.equal(1);
      checks.console_error_messages[0].should.equal('some error');
      checks.process_exit_code.should.equal(1);
    });

    it('should exit with status code 0 and call success callback when error does not exist and success callback is specified', function () {
      function successCb(result) {
        checks.success_result = result;
      }
      cli.exit_cb(null, successCb)(null, 'some success');
      checks.success_result.should.equal('some success');
      checks.process_exit_code.should.equal(0);
    });

    it('should exit with status code 1 and call error callback when error exists and error callback is specified', function () {
      function errorCb(err) {
        checks.error_err = err;
      }
      cli.exit_cb(errorCb)(new Error('some error'));
      checks.error_err.message.should.equal('some error');
      checks.process_exit_code.should.equal(1);
    });
  });
});<|endoftext|>


<commit_before>'use strict';

require('angular-resource');

module.exports = angular.module(
  'flickrDupFinderServices',
  ['ngResource', require('./config').name, require('./oauth-shim').name])
  .service(
    'Flickr',
    ['$window', '$log', '$resource', '$http', '$q', '$location', 'OAuth', 'OAUTHD_URL', 'APP_PUBLIC_KEY',
     function($window, $log, $resource, $http, $q, $location, OAuth, OAUTHD_URL, APP_PUBLIC_KEY) {
       OAuth.initialize(APP_PUBLIC_KEY, {cache: true});
       OAuth.setOAuthdURL(OAUTHD_URL);
       var resource = $q.defer();
       function doneHandler(result) {
         var key = APP_PUBLIC_KEY;
         var oauthio = 'k=' + key;
         oauthio += '&oauthv=1';
         function kv_result(key) { return '&'+key+'='+encodeURIComponent(result[key]); }
         oauthio += kv_result('oauth_token');
         oauthio += kv_result('oauth_token_secret');
         oauthio += kv_result('code');
         $http.defaults.headers.common = {oauthio: oauthio};
         resource.resolve(
           $resource(
             OAUTHD_URL + '/request/flickr/services/rest/',
             {
               method: "flickr.photos.search",
               format: "json",
               user_id: "me",
               per_page: 10,
               //text: "vision:outdoor",
               //tags: "vision:outdoor,vision:outdoor=099",
               //machine_tags: "outdoor",
               extras: "date_upload,date_taken,tags",
               nojsoncallback: 1
             }));
       }

       if (OAuth.callback('flickr')) {
         OAuth.callback('flickr').done(doneHandler).fail(function(callbackError) {
           $log.log('OAuth.callback error: ', callbackError);
         });
       } else {
         var dest_url = $location.absUrl();
         $window.console.log(dest_url);
         //OAuth.redirect('flickr', dest_url);

         $window.console.log('oauth: ', OAuth);
         OAuth.popup('flickr').done(doneHandler).fail(function(error) {
           $log.log('OAuth.popup error: ', error);
           resource.reject('OAuth.popup error: ' + error);
         });
       }
       return resource.promise;
     }]);
<commit_msg>remove $window, reindent<commit_after>'use strict';

require('angular-resource');

module.exports = angular.module(
  'flickrDupFinderServices',
  ['ngResource', require('./config').name, require('./oauth-shim').name])
  .service(
    'Flickr',
    ['$log', '$resource', '$http', '$q', '$location', 'OAuth', 'OAUTHD_URL', 'APP_PUBLIC_KEY',
     function(
       $log, $resource, $http, $q, $location, OAuth, OAUTHD_URL, APP_PUBLIC_KEY) {
       OAuth.initialize(APP_PUBLIC_KEY, {cache: true});
       OAuth.setOAuthdURL(OAUTHD_URL);
       var resource = $q.defer();
       function doneHandler(result) {
         var key = APP_PUBLIC_KEY;
         var oauthio = 'k=' + key;
         oauthio += '&oauthv=1';
         function kv_result(key) {
           return '&'+key+'='+encodeURIComponent(result[key]);
         }
         oauthio += kv_result('oauth_token');
         oauthio += kv_result('oauth_token_secret');
         oauthio += kv_result('code');
         $http.defaults.headers.common = {oauthio: oauthio};
         resource.resolve(
           $resource(
             OAUTHD_URL + '/request/flickr/services/rest/',
             {
               method: "flickr.photos.search",
               format: "json",
               user_id: "me",
               per_page: 10,
               //text: "vision:outdoor",
               //tags: "vision:outdoor,vision:outdoor=099",
               //machine_tags: "outdoor",
               extras: "date_upload,date_taken,tags",
               nojsoncallback: 1
             }));
       }

       if (OAuth.callback('flickr')) {
         OAuth.callback('flickr').done(doneHandler).fail(function(callbackError) {
           $log.log('OAuth.callback error: ', callbackError);
         });
       } else {
         var dest_url = $location.absUrl();
         $log.debug(dest_url);
         //OAuth.redirect('flickr', dest_url);

         $log.debug('oauth: ', OAuth);
         OAuth.popup('flickr').done(doneHandler).fail(function(error) {
           $log.debug('OAuth.popup error: ', error);
           resource.reject('OAuth.popup error: ' + error);
         });
       }
       return resource.promise;
     }]);
<|endoftext|>