test('[ Connection ] ::_pollForPort', function (t) {
  t.plan(1);
  var ConnectionTest = proxyquire.noCallThru().load('../lib/connection', { serialport: {
    list: function (callback) {
      callback(null, [
        { comName: '/dev/cu.sierravsp', manufacturer: '', serialNumber: '',
          pnpId: '', locationId: '', vendorId: '', productId: '' },
        { comName: '/dev/cu.Bluetooth-Incoming-Port', manufacturer: '',
          serialNumber: '', pnpId: '', locationId: '', vendorId: '',
          productId: '' },
        { comName: '/dev/cu.usbmodem1421', manufacturer: 'Arduino (www.arduino.cc)',
          serialNumber: '55432333038351F03170', pnpId: '', locationId: '0x14200000',
          vendorId: '0x2341', productId: '0x0043' }
      ]);
    },

    SerialPort: require('./helpers/mockSerial').SerialPort
  } });

  var options = {
    debug: false,
    board: 'uno',
    port: '/dev/cu.usbmodem1421'
  };

  var c = new ConnectionTest(options);
  c._pollForPort(function (error) {
    t.error(error, 'no error on polling result');
  });
});
test('[ Connection ] ::_sniffPort (UNIX)', function(t) {
  t.plan(3);
  var ConnectionTest = proxyquire.noCallThru().load('../lib/connection', { serialport: {
      list: function(callback) {
        callback(null, [
          { comName: '/dev/cu.sierravsp', manufacturer: '', serialNumber: '',
            pnpId: '', locationId: '', vendorId: '', productId: '' },
          { comName: '/dev/cu.Bluetooth-Incoming-Port', manufacturer: '',
            serialNumber: '', pnpId: '', locationId: '', vendorId: '',
            productId: '' },
          { comName: '/dev/cu.usbmodem1421', manufacturer: 'Arduino (www.arduino.cc)',
            serialNumber: '55432333038351F03170', pnpId: '', locationId: '0x14200000',
            vendorId: '0x2341', productId: '0x0043' }
        ]);
      },

      SerialPort: mockSerial.SerialPort
    } });

  // nodejs 0.10.x race condition needs this
  setTimeout(function() {
    var c = new ConnectionTest(DEF_OPTS1);
    c._sniffPort(function(error, match) {
      t.ok(match.length, 'board was detected');
      t.equal(match[0].comName, '/dev/cu.usbmodem1421', 'correct comName to match against');
      t.error(error, 'no error on return');
    });
  }, 200);
});
test('[ Connection ] ::_listPorts (UNIX)', function(t) {
  t.plan(3);
  var ConnectionTest = proxyquire.noCallThru().load('../lib/connection', { serialport: {
      list: function(callback) {
        callback(null, [
          { comName: '/dev/cu.sierravsp', manufacturer: '', serialNumber: '',
            pnpId: '', locationId: '', vendorId: '', productId: '' },
          { comName: '/dev/cu.Bluetooth-Incoming-Port', manufacturer: '',
            serialNumber: '', pnpId: '', locationId: '', vendorId: '',
            productId: '' },
          { comName: '/dev/cu.usbmodem1421', manufacturer: 'Arduino (www.arduino.cc)',
            serialNumber: '55432333038351F03170', pnpId: '', locationId: '0x14200000',
            vendorId: '0x2341', productId: '0x0043' }
        ]);
      },

      SerialPort: mockSerial.SerialPort
    } });

  // nodejs 0.10.x race condition needs this
  setTimeout(function() {
    var c = new ConnectionTest(DEF_OPTS1);
    c._listPorts(function(error, ports) {
      t.ok(ports.length, 'got a list of ports');
      t.ok(ports[2]._standardPid, 'added _standardPid property');
      t.error(error, 'no error on listing');
    });
  }, 200);
});
		setup(function() {
			app = proxyquire.noCallThru().load(
							'../../applications-data', {
								'./utils': mockUtils,
								'./webapp-manifests': mockWebappManifests
							});
			config = {
				search_page: {
					enabled: true
				},
				tap_threshold: 111,
				tap_effect_delay: 122,
				move_collection_threshold: 133,
				swipe: {
					threshold: 1,
					friction: 3,
					transition_duration: 4
				},
				homescreens: [[]],
				bookmarks: 'test'
			};
			mockUtils.getDistributionFileContent = function() {
				return JSON.stringify(config);
			};
		});
Example #5
0
 setup(function() {
     app = proxyquire.noCallThru().load(
             '../../install-gaia', {
               './utils': mockUtils
             });
     mockUtils.getFileContent = function(file) {
       return file;
     };
 });
Example #6
0
 setup(function() {
     app = proxyquire.noCallThru().load(
             '../../push-to-device', {
               './utils': mockUtils
             });
     mockUtils.getFileContent = function(file) {
       return file;
     };
 });
  it ('can be required', function() {
    let GeocoderPkg = proxyquire
      .noCallThru()
      .load('../../', {
        './js/geocoder.js': { valid: true },
      }).default;

    expect(GeocoderPkg.valid).to.be.ok;
  });
Example #8
0
    beforeEach(function() {
        this.foobarPlugin = sinon.spy();
        this.gemini = sinon.spy();

        plugins = proxyquire
            .noCallThru()
            .load('lib/plugins', {
                'gemini-foobar': this.foobarPlugin
            });
    });
Example #9
0
File: watcher.js Project: avajs/ava
	function proxyWatcher(opts) {
		return proxyquire.noCallThru().load('../lib/watcher', opts ||
			{
				chokidar,
				debug(name) {
					return (...args) => {
						debug(...[name, ...args]);
					};
				}
			});
	}
Example #10
0
  before(() => {

    proxyquire.noCallThru();

    const mocks = {

      './homeController': stubHomeControllerClass
    };

    homeIndex = proxyquire('./../../src/server/modules/home', mocks).default;
  });
 beforeEach(function() {
     loadCallbackArgs = [];
     repositoryStub = {
         filterBySerialNumber: sinon.spy(function filterBySerialNumberStub(id, callback) { callback.apply(null, loadCallbackArgs); }),
         addOrReplace: sinon.spy(function addOrReplaceStub(item, callback) { callback.apply(null); })
     };
     proxyquire.noCallThru();
     sut = proxyquire('../../routes/deviceTopologyApi', {
         '../repositories/deviceTopologiesRepository': repositoryStub
     });
 });
Example #12
0
  before(() => {

    proxyquire.noCallThru();

    const mocks = {

      passport: stubPassport
    };

    initAuthentication = proxyquire('../src/middleware/authentication', mocks).default;
  });
  beforeEach(() => {
    ipcRenderer = new ipcMock();

    // mock electron ipc event emitter when loading our library
    const lib = proxyquire.noCallThru().load('../src', {
      electron: { ipcRenderer }
    });

    createIpc = lib.default;
    send = lib.send;
  });
Example #14
0
  before(() => {

    proxyquire.noCallThru();

    const mocks = {

      helmet: stubHelmet
    };

    initialiseSecurity = proxyquire('../src/middleware/security', mocks).default;
  });
Example #15
0
function getSlop(mock) {
  const slop = proxyquire.noCallThru().load('./slop', {
    '../utils': {
      exec: () => Promise.resolve(mock)
    },
    '../../utils': {
      log: () => {}
    }
  }).default;

  return slop();
}
Example #16
0
(function () {
    'use strict';
    var stubs = require('./commonStubs');
    var mockrequire = require('proxyquire');
    var should = require('should');

    var lessProcessor = mockrequire.noCallThru().load('./../src/processor/modules/builders/lessbuilder', {
        './../../../logger/logger': stubs.loggerStub,
        'less': require('less')
    });

    describe('LessBuilder', function () {
        var preferences = {
            'table-bg': 'red',
            'table-border-color': 'black',
            'font-size-base': '11px',
            'table-bg-active': 'white'
        };
        var invalidPreferences= {
            'table-bg': 'red',
            'table-border-color': 'black',
            'font-size-base': '11px'
        };
        describe('#compileLess()', function () {
            it('should return css if less is valid and all variables are declared', function (done) {
                lessProcessor.compileLess(stubs.less, preferences, function(css){
                    css.should.equal(stubs.cssResult);
                    done();
                });
            });
            it('should return error equal null if less is valid and all variables are declared', function (done) {
                lessProcessor.compileLess(stubs.less, preferences, function(css, error){
                    should(error).equal(null);
                    done();
                });
            });

            it('should return css which contains error text if not all variables are declared', function (done) {
                lessProcessor.compileLess(stubs.less, invalidPreferences, function(css){
                    should(css).equal('variable @table-bg-active is undefined');
                    done();
                });
            });

            it('should return error if less is valid and not all variables are declared', function (done) {
                lessProcessor.compileLess(stubs.less, invalidPreferences, function(css, error){
                    should(error.message).equal('variable @table-bg-active is undefined');
                    done();
                });
            });
        });
    });
}());
Example #17
0
    before(() => {

      proxyquire.noCallThru();

      const mocks = {

        fs: stubFs
      };

      stubCwd = sinon.stub(process, 'cwd').returns('some-runtime-path');
      getRootPath = proxyquire('../src/core/utilities', mocks).getRootPath;
    });
Example #18
0
  before(() => {

    proxyquire.noCallThru();

    const mocks = {

      './winstonProvider': stubGetWinston
    };

    Logger = proxyquire('../src/core/logger', mocks).default;
    logger = Logger.createFromConfig(stubConfig);
  });
Example #19
0
 setup(function() {
   app = proxyquire.noCallThru().load(
           '../../settings', {
             './utils': mockUtils
           });
   mockUtils.getFileContent = function(file) {
     return file;
   };
   mockUtils.getFileAsDataURI = function(file) {
     return file.path;
   };
 });
Example #20
0
  before(() => {

    proxyquire.noCallThru();

    const mocks = {

      '../core/renderers': stubRenderView,
      'basis-components': { ErrorView: stubErrorView }
    };

    initialiseErrorHandlers = proxyquire('../src/middleware/errorHandlers', mocks).default;
  });
Example #21
0
  before(() => {

    proxyquire.noCallThru();

    const mocks = {

      react: stubReact,
      'react-dom/server': { renderToStaticMarkup: stubRenderToStaticMarkup }
    };

    renderView = proxyquire('../src/core/renderers', mocks).default;

  });
Example #22
0
describe('templates', function(){
  var auth = proxyquire.noCallThru().load('../../../../lib/templates/controllers/AuthController.js',
    {'waterlock': {waterlocked: function(){return {};}}});

  describe('controllers', function(){
    describe('AuthController', function(){
      it('should call waterlocked', function(done){
        auth.should.be.Object;
        done();
      });
    });    
  });
});
Example #23
0
    before(() => {

      proxyquire.noCallThru();
      sinon.stub(stubJsonfile, 'readFileSync').returns(stubSettingsJson);

      const mocks = {

        './utilities': { getEnvVariable: stubGetEnvVariable, getRootPath: sinon.stub().returns('') },
        jsonfile: stubJsonfile
      };

      Config = proxyquire('../src/core/config', mocks).default;
    });
Example #24
0
test('chokidar is not installed', function (t) {
	t.plan(2);

	var Subject = proxyquire.noCallThru().load('../lib/watcher', {
		chokidar: null
	});

	try {
		new Subject({}, {excludePatterns: [], on: function () {}}, [], []); // eslint-disable-line
	} catch (err) {
		t.is(err.name, 'AvaError');
		t.is(err.message, 'The optional dependency chokidar failed to install and is required for --watch. Chokidar is likely not supported on your platform.');
	}
});
Example #25
0
	function proxyWatcher(opts) {
		return proxyquire.noCallThru().load('../lib/watcher', opts ||
			{
				chokidar,
				debug(name) {
					return function () {
						const args = [name];
						args.push.apply(args, arguments);
						debug.apply(null, args);
					};
				},
				'./ava-files': avaFiles
			});
	}
Example #26
0
  setup(function() {
    app = proxyquire.noCallThru().load(
            '../../webapp-zip', {
              './utils': mockUtils
            });
    var GetFile = function(path) {
      this.path = path;
      this.append = function(subPath) {
        this.path += ('/' + subPath);
      };
      this.clone = function() {
        return new GetFile(this.path);
      };
      this.leafName = this.path;
      this.parent = this;
      this.exists = function() {
        return fileExists;
      };
      this.isHidden = function() {
        return isHidden;
      };
      this.isFile = function() {
        return isFile;
      };
      this.isDirectory = function() {
        return isDirectory;
      };
    };
    mockUtils.getFile = function(path) {
      filePath = path;
      return new GetFile(path);
    };

    mockUtils.createZip = function() {
      return {
        open: function(file, mode) {
          zipFilePath = file.path;
          zipMode = mode;
        }
      };
    };

    mockUtils.getCompression = function(type) {
      return type;
    };

    mockUtils.ensureFolderExists = function() {
    };
  });
Example #27
0
 it('should require auth method', function(done){
   var scope = {
     config: {
       authMethod: [{name: 'some-auth-module'}]
     }
   };
   var methods =  proxyquire.noCallThru().load('../../lib/methods',
     {
       '../../some-auth-module': {shake:'bake', authType: 'magic-man'}
     })();
   
   var results = methods._handleObjects(scope.config.authMethod);
   results.should.have.property('magic-man');
   done();
 });
Example #28
0
  describe('#waterlock()', function(){
    var Controllers = proxyquire.noCallThru().load('../../../lib/controllers',{
      './actions/login': {foo: 'bar'},
      './actions/logout': {faz: 'baz'}
    });
    var waterlock = {
      loggger: {verbose: function(){}},
      methods: {}
    };
    var controllers = Controllers.apply(waterlock);

    it('should have a login property', function(done){
      var results = controllers.waterlocked({});
      results.should.have.property('login');
      done();
    });
    it('should have a logout property', function(done){
      var results = controllers.waterlocked({});
      results.should.have.property('logout');
      done();
    });

    it('should merge given actions', function(done){
      var results = controllers.waterlocked({foo:'bar'});
      results.should.have.property('foo');
      done();
    });

    it('should merge any extras from waterlock.*.methods', function(done){
      var waterlock = {
        logger: {verbose: function(){}},
        methods: {
          shake: {
            actions:{
              extras: {
                shake: 'bake'
              }
            }
          }
        }
      };
      var controllers = Controllers.apply(waterlock);
      var results = controllers.waterlocked({});
      results.should.have.property('shake');
      done();
    });
  });
Example #29
0
 setup(function() {
   app = proxyquire.noCallThru().load(
           '../../preferences', {
             './utils': mockUtils
           });
   mockUtils.gaia = {
     getInstance: function(config) {
       return config;
     }
   };
   mockUtils.getFile = function(src, path) {
     return src + path;
   };
   mockUtils.writeContent = function(file, content) {
     fileContent = {
       file: file,
       content: content
     };
     return fileContent;
   };
   mockUtils.getLocaleBasedir = function(dir) {
     return dir;
   };
   mockUtils.Services = {
     prefs: {
       setCharPref: function(key, val) {
         servicePrefs[key] = {
           value: val,
           type: 'char'
         };
       },
       setBoolPref: function(key, val) {
         servicePrefs[key] = {
           value: val,
           type: 'bool'
         };
       },
       setIntPref: function(key, val) {
         servicePrefs[key] = {
           value: val,
           type: 'int'
         };
       }
     }
   };
 });
Example #30
0
  setup(function() {
    app = proxyquire.noCallThru().load(
      '../../webapp-zip', {
        './utils': mockUtils
      });
    var GetFile = function(filePath) {
      this.path = filePath;
      this.append = function(subPath) {
        this.path += ('/' + subPath);
      };
      this.clone = function() {
        return new GetFile(this.path);
      };
      this.leafName = fsPath.basename(this.path);
      this.parent = this;
      this.exists = function() {
        return fileExists;
      };
      this.isHidden = function() {
        return isHidden;
      };
      this.isFile = function() {
        return isFile;
      };
      this.isDirectory = function() {
        return isDirectory;
      };
    };
    mockUtils.getFile = function() {
      var args = Array.prototype.slice.call(arguments);
      filePath = fsPath.join.apply(fsPath, args);
      return new GetFile(filePath);
    };

    mockUtils.createZip = function(zipPath) {
      zipFilePath = zipPath;
      return {};
    };

    mockUtils.getCompression = function(type) {
      return type;
    };

    mockUtils.ensureFolderExists = function() {
    };
  });