コード例 #1
0
function verify(callback) {
    if (!this.submission || !this.solution) {
        throw new TypeError("Submission and solution paths must be present on the exercise object.");
    }

    var submission = require(this.submission);
    var solution = require(this.solution);

    var allPassed = true;
    for (var i = 0; i < this._testCases.length; ++i) {
        var args = this._testCases[i];

        var submissionResult = submission.apply(undefined, args);
        var solutionResult = solution.apply(undefined, args);

        var passFail = submissionResult === solutionResult ? "pass" : "fail";

        var formattedArgs = formatArgs(args);
        var opts = {
            name: this.solutionFunctionName,
            args: formattedArgs,
            expected: solutionResult,
            actual: submissionResult
        };
        var message = this.__(passFail + '.singleFunction', opts);

        this.emit(passFail, message);

        allPassed = allPassed && passFail === "pass";
    }

    process.nextTick(function () {
        callback(null, allPassed);
    });
}
コード例 #2
0
ファイル: console.js プロジェクト: TrickyCat/beamjs
exports.error = exports.warn = exports.info = exports.log = function(d) {
	if (d == null) {
		erlang.apply("io","format",["null~n"]);
	} else if (typeof d == 'function') {
		erlang.apply("io","format",["~s~n",[d.toString()]]);
	} else if (typeof d == 'object') {
		erlang.apply("io","format",["~s~n",[d.toString()]]);
	} else if (typeof d == 'string') {
		erlang.apply("io","format",["~s~n",[d]]);
	} else if (typeof d == 'number') {
		erlang.apply("io","format",["~w~n",[d]]);
	}
}
コード例 #3
0
        it('should detect glob errors',function(){
            var context     = {};
            var policy      = new PolicyUpload();
            policy.apply(context,config.copySettings(),null,onResolve,onReject);
            context.should.eql({action: 'error',error: 'GLOB error: **/*',result: {added: 0,updated: 0,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});

            policy.apply(context,config.copySettings(),null,onResolve,onReject);
            context.should.eql({action: 'error+error',error: 'GLOB error: **/*',result: {added: 0,updated: 0,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});

            resolveSeen.should.eql(false);
            rejectSeen.should.eql(['GLOB error: **/*','GLOB error: **/*']);

            test.mockLogger.checkMockLogEntries(['ERROR - policy error: GLOB error: **/*','ERROR - policy error: GLOB error: **/*']);
        });
コード例 #4
0
        it('should upload a file and move it',function(done){
            test.mockGlob.lookup['**/*'] = ['test/data/test.json'];

            test.mockAwsSdk.deferAfterS3ListObjects = function(callback){ callback(null,{Contents: []}); };
            test.mockAwsSdk.deferAfterS3Upload = function(callback){ callback(null,true); };

            var renamedFILES = [];
            test.mockHelpers.renameSync = function(src,dst) { renamedFILES.push([src,dst]); };

            var context     = {result: result};
            var policy      = new PolicyUpload();
            var settings    = config.copySettings();

            test.mockHelpers.fileExists = function(filename) { return {isDirectory: function() {return filename === settings.move_after_upload}} };

            settings.input_remove_prefix    = 'test/data/';
            settings.output_key_prefix      = 'upload/';
            settings.move_after_upload      = 'moved/';

            policy.lastSeenList.should.eql({});

            policy.apply(context,settings,null,function(){
                context.should.eql({result: {added: 1,updated: 0,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});

                test.mockAwsSdk.checkMockState([
                    ['s3.listObjects',{Bucket: 'unknown-s3-bucket',Prefix: 'upload/test.json'}],
                    ['s3.upload',{Bucket: 'unknown-s3-bucket',Key: 'upload/test.json',Body: true}]
                ]);
                test.mockLogger.checkMockLogEntries(['... add: test/data/test.json => upload/test.json']);
                test.mockHelpers.checkMockFiles([[config.settings.aws_keys_file,'default']]);
                renamedFILES.should.eql([['test/data/test.json','moved/test.json']]);
                done();
            },done);
        });
コード例 #5
0
ファイル: react-xjst.js プロジェクト: amel-true/react-xjst
    return function (bemJson) {

        let isValidReactElement = (obj) => {
            return typeof obj === 'object' && obj.$$typeof;
        };

        function makeComponent(args) {
            // if (args.filter(a => isValidReactElement(a)).length === args.length) {
            //     return React.createElement.apply(null, ['div', null].concat(args));
            // }

            let children = args.slice(2).map((a) => {
                if (Array.isArray(a)) {
                    return makeComponent(a);
                } else {
                    return a;
                }
            });

            return reactInstance.createElement.apply(reactInstance, args.slice(0, 2).concat(children));

        }

        var res = makeComponent(templates.apply(bemJson));
        return res;
    }
コード例 #6
0
ファイル: express-load.js プロジェクト: rsirres/express-load
ExpressLoad.prototype.into = function(instance) {

  for (var s in this.scripts) {

    var script = this.scripts[s]
      , parts = script.location.split(path.sep)
      , maps = parts.slice(0)
      , ns = createNamespace(instance, parts.slice(script.level))
      , mod = require(script.fullpath)
      , map = [];

    if (typeof mod === 'function') {
      mod = mod.apply(script, arguments);
    }

    ns[script.name] = mod;

    while (maps.length) {
      map.push(
        getName(
          maps.shift()
        )
      );
    }

    this.__log('Loaded *.' + map.join('.'));
  }

  return this;
};
コード例 #7
0
ファイル: npm.js プロジェクト: 119120119/node
      commandCache[a] = function () {
        var args = Array.prototype.slice.call(arguments, 0)
        if (typeof args[args.length - 1] !== 'function') {
          args.push(defaultCb)
        }
        if (args.length === 1) args.unshift([])

        // Options are prefixed by a hyphen-minus (-, \u2d).
        // Other dash-type chars look similar but are invalid.
        Array(args[0]).forEach(function (arg) {
          if (/^[\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]/.test(arg)) {
            log.error('arg', 'Argument starts with non-ascii dash, this is probably invalid:', arg)
          }
        })

        npm.registry.version = npm.version
        if (!npm.registry.refer) {
          npm.registry.refer = [a].concat(args[0]).map(function (arg) {
            // exclude anything that might be a URL, path, or private module
            // Those things will always have a slash in them somewhere
            if (arg && arg.match && arg.match(/\/|\\/)) {
              return '[REDACTED]'
            } else {
              return arg
            }
          }).filter(function (arg) {
            return arg && arg.match
          }).join(' ')
        }

        cmd.apply(npm, args)
      }
コード例 #8
0
ファイル: helper.js プロジェクト: gitter-badger/condensation
var helper = function (cModule,pPath,hArgs,hOpts,cOpts) {

    var particle = cOpts.particleLoader.loadParticle('helper',cModule,pPath,{parentFile: hOpts.data._file});
    var helperFunc = require(particle.path);

    return helperFunc.apply(this,hArgs);
};
コード例 #9
0
        it('should upload a file and delete it',function(done){
            test.mockGlob.lookup['**/*'] = ['test/data/test.json'];

            test.mockAwsSdk.deferAfterS3ListObjects = function(callback){ callback(null,{Contents: []}); };
            test.mockAwsSdk.deferAfterS3Upload = function(callback){ callback(null,true); };

            var deletedFILES = [];
            test.mockHelpers.unlinkSync = function(target) { deletedFILES.push(target); };
            test.mockHelpers.rmdirSync  = function(target) { deletedFILES.push(target); };

            var context     = {result: result};
            var policy      = new PolicyUpload();
            var settings    = config.copySettings();

            settings.delete_after_upload = true;

            policy.lastSeenList.should.eql({});

            policy.apply(context,settings,null,function(){
                context.should.eql({result: {added: 1,updated: 0,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});

                test.mockAwsSdk.checkMockState([
                    ['s3.listObjects',{Bucket: 'unknown-s3-bucket',Prefix: 'test/data/test.json'}],
                    ['s3.upload',{Bucket: 'unknown-s3-bucket',Key: 'test/data/test.json',Body: true}]
                ]);
                test.mockLogger.checkMockLogEntries(['... add: test/data/test.json => test/data/test.json']);
                test.mockHelpers.checkMockFiles([[config.settings.aws_keys_file,'default']]);
                deletedFILES.should.eql(['test/data/test.json']);
                done();
            },done);
        });
コード例 #10
0
ファイル: check.js プロジェクト: jonschlinkert/arr-filter
 fs.readdirSync(__dirname + '/fixtures').forEach(function (fixture) {
   var basename = path.basename(fixture, path.extname(fixture));
   if (mm(f).test(basename) && /\.js/.test(fixture)) {
     fixture = path.resolve(__dirname, 'fixtures', fixture);
     console.log(chalk.bold(name) + ':', fn.apply(null, require(fixture)).length);
   }
 });
コード例 #11
0
        it('should catch an s3.upload error',function(done){
            test.mockGlob.lookup['**/*'] = ['test/data/test.json'];

            test.mockAwsSdk.deferAfterS3ListObjects = function(callback){ callback(null,{Contents: []}); };
            test.mockAwsSdk.deferAfterS3Upload = function(callback){ callback('upload-error'); };

            var context     = {result: result};
            var policy      = new PolicyUpload();

            policy.apply(context,config.copySettings(),null,function(){ true.should.not.be.ok; done(); },function(err){
                err.should.eql('upload-error');
                context.should.eql({action: 'error',error: 'upload-error',result: {added: 1,updated: 0,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});
                test.mockAwsSdk.checkMockState([
                    ['s3.listObjects',{Bucket: 'unknown-s3-bucket',Prefix: 'test/data/test.json'}],
                    ['s3.upload',{Bucket: 'unknown-s3-bucket',Key: 'test/data/test.json',Body: true}]
                ]);
                test.mockLogger.checkMockLogEntries([
                    '... add: test/data/test.json => test/data/test.json',
                    'ERROR - policy error: upload-error'
                ]);
                test.mockHelpers.checkMockFiles([[config.settings.aws_keys_file,'default']]);

                done();
            });
        });
コード例 #12
0
                policy.apply(context,settings,null,function(){
                    context.should.eql({result: {added: 2,updated: 0,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});
                    test.mockLogger.checkMockLogEntries(['... add: test/data/test.json => test/data/test.json']);
                    test.mockAwsSdk.checkMockState([
                        ['s3.listObjects',{Bucket: 'unknown-s3-bucket',Prefix: 'test/data/test.json'}],
                        ['s3.upload',{Bucket: 'unknown-s3-bucket',Key: 'test/data/test.json',Body: true}]
                    ]);

                    test.mockAwsSdk.deferAfterS3ListObjects = function(callback){ callback(null,{Contents: [{Size: lastSeen.size,LastModified: lastSeen.mtime}]}); };
                    lastSeen.mtime = lastSeen.atime;

                    policy.apply(context,settings,null,function(){
                        context.should.eql({result: {added: 2,updated: 1,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});
                        test.mockLogger.checkMockLogEntries(['... update: test/data/test.json => test/data/test.json']);
                        test.mockAwsSdk.checkMockState([
                            ['s3.listObjects',{Bucket: 'unknown-s3-bucket',Prefix: 'test/data/test.json'}],
                            ['s3.upload',{Bucket: 'unknown-s3-bucket',Key: 'test/data/test.json',Body: true}]
                        ]);

                        var lastSeen = policy.lastSeenList['test/data/test.json'];
                        lastSeen.mtime = lastSeen.atime;
                        test.mockAwsSdk.deferAfterS3ListObjects = function(callback){ callback(null,{Contents: [{Size: lastSeen.size,LastModified: lastSeen.mtime}]}); };

                        policy.apply(context,settings,null,function(){
                            context.should.eql({result: {added: 2,updated: 2,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});
                            test.mockAwsSdk.checkMockState([
                                ['s3.listObjects',{Bucket: 'unknown-s3-bucket',Prefix: 'test/data/test.json'}],
                                ['s3.upload',{Bucket: 'unknown-s3-bucket',Key: 'test/data/test.json',Body: true}]
                            ]);
                            test.mockLogger.checkMockLogEntries(['... update: test/data/test.json => test/data/test.json']);

                            done();
                        },done);
                    },done);
                },done);
コード例 #13
0
var Generator = module.exports = function Generator(name) {
  ScriptBase.apply(this, arguments);
  this.option('uri', {
    desc: 'Allow a custom uri for routing',
    type: String,
    required: false
  });

  var bower = require(path.join(process.cwd(), 'bower.json'));
  var match = require('fs').readFileSync(path.join(
    this.env.options.appPath,
    'scripts/routes.' + (this.env.options.coffee ? 'coffee' : 'js')
  ), 'utf-8').match(/\.when/);

  if (
    bower.dependencies['angular-route'] ||
    bower.devDependencies['angular-route'] ||
    match !== null
  ) {
    this.foundWhenForRoute = true;
  }

  if( !this.options.skipController ) {
    this.hookFor('angularfire-express:controller');
  }
  if( !this.options.skipView ) {
    this.hookFor('angularfire-express:view');
  }
};
コード例 #14
0
ファイル: listeners_spec.js プロジェクト: alexlehm/Ghost
 .then(function () {
     return sequence.apply(self, args)
         .finally(function () {
             setTimeout(function () {
                 listenerHasFinished = true;
             }, 500);
         });
 });
コード例 #15
0
ファイル: npm.js プロジェクト: deanlandolt/npm
 commandCache[a] = function () {
   var args = Array.prototype.slice.call(arguments, 0)
   if (typeof args[args.length - 1] !== "function") {
     args.push(defaultCb)
   }
   if (args.length === 1) args.unshift([])
   cmd.apply(npm, args)
 }
コード例 #16
0
ファイル: index.js プロジェクト: bigpandaio/metro
  pipelineCreator: function(name) {
    var factory = require('./lib/pipelines/' + name);
    if (!factory) {
      return false;
    }

    Array.prototype.shift.apply(arguments);
    return factory.apply(null,arguments);
  }
コード例 #17
0
ファイル: index.js プロジェクト: PoeBlu/api
      async.reduce(this.settings.hooks.afterGet, results, (current, hookConfig, callback) => {
        var hook = new Hook(hookConfig, 'afterGet')

        Promise.resolve(hook.apply(current, this.schema, this.name, req)).then((newResults) => {
          callback((newResults === null) ? {} : null, newResults)
        }).catch((err) => {
          callback(err)
        })
      }, (err, finalResult) => {
コード例 #18
0
ファイル: index.js プロジェクト: PoeBlu/api
        async.reduce(this.settings.hooks.beforeUpdate, update, (current, hookConfig, callback) => {
          var hook = new Hook(hookConfig, 'beforeUpdate')

          Promise.resolve(hook.apply(current, updatedDocs, this.schema, this.name, req)).then((newUpdate) => {
            callback((newUpdate === null) ? {} : null, newUpdate)
          }).catch((err) => {
            callback(err)
          })
        }, (err, result) => {
コード例 #19
0
ファイル: loader.js プロジェクト: ww24/twitter-to-call
  modules.forEach(function (module) {
    if (module.slice(-3) !== ".js" || module === "index.js")
      return false;

    var name = module.slice(0, -3),
        func = require(path.resolve(path.join(dir, name)));

    mod[name] = args.length > 0 ? func.apply(that, args) : func;
  });
コード例 #20
0
ファイル: spawn-generic.js プロジェクト: raszi/node-tmp
 fnUnderTest(config.options, function (err, name, fdOrCallback, cb) {
   if (err) spawn.err(err);
   else {
     var result = null;
     if (config.file) result = { name: name, fd: fdOrCallback, removeCallback: cb };
     else result = { name: name, removeCallback: fdOrCallback };
     fn.apply(spawn, [result, tmp]);
   }
 });
コード例 #21
0
ファイル: plugins.js プロジェクト: zaharin/pyatnashki
    return function () {
        var locArgs = args;
        var module = require(moduleName);

        if (arguments.length)
            locArgs = arguments;

        return module.apply(module, locArgs);
    };
コード例 #22
0
ファイル: transport.js プロジェクト: leankitscott/autohost
				.then( function( deps ) {
					var argList = _.map( args, function( arg ) {
						return deps[ arg ];
					} );
					argList.unshift( state.host );
					var mod = modFn.apply( modFn, argList );
					attachPath( state, mod, resourcePath );
					return mod;
				} );
コード例 #23
0
ファイル: index.js プロジェクト: PoeBlu/api
      async.reduce(this.settings.hooks.beforeDelete, query, (current, hookConfig, callback) => {
        var hook = new Hook(hookConfig, 'beforeDelete')
        var hookError = {}

        Promise.resolve(hook.apply(current, hookError, this.schema, this.name, req)).then((newQuery) => {
          callback((newQuery === null) ? {} : null, newQuery)
        }).catch((err) => {
          callback(err)
        })
      }, (err, result) => {
コード例 #24
0
ファイル: KompressorCSS.js プロジェクト: chazsolo/kompressor
function KompressorCSS(){

    KompressorBase.apply(this, arguments) 

    this.assetType                           = "link";
    this.assetSrcAttribute                   = "href";

    // we need to run this through sed to remove any (@CHARSET nonsense);
    this.execString = 'yuicompressor --type css %s | sed "s/@CHARSET [\\"|\']UTF-8[\\"|\'];//g"\r\n exit ${PIPESTATUS[0]}';
}
コード例 #25
0
ファイル: index.js プロジェクト: sdgluck/lodash-invariants
 obj[fn] = function (name, two, three, four) {
   return invariant.apply(invariant, [
     is.apply(is, [two, three]),
     message,
     name,
     expectation,
     three ? String(two).toString() : typeof two,
     four
   ])
 }
コード例 #26
0
        it('should do nothing on a directory',function(done){
            test.mockGlob.lookup['**/*'] = ['test/'];

            var context     = {};
            var policy      = new PolicyUpload();
            policy.apply(context,config.copySettings(),null,function(){
                context.should.eql({result: {added: 0,updated: 0,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});
                done();
            },onReject);
        });
コード例 #27
0
ファイル: launcher.js プロジェクト: shmoop207/appolo-express
 _.forEach([allPath, environmentPath], (filePath) => {
     if (!fs.existsSync(filePath)) {
         return;
     }
     this.cachedRequire.push(filePath);
     let func = require(filePath);
     let args = appolo.Util.getFunctionArgs(func);
     let dependencies = _.map(args, (arg) => appolo.inject.getObject(arg));
     func.apply(func, dependencies);
 });
コード例 #28
0
ファイル: app.js プロジェクト: SomeNameDevTeam/bem-editor
	.post('/make_article', function(req, res){
		var data = req.body.data;
		var id = req.body.id;
		var bhFilePath = __dirname+'/pages/article/article.bh.js';
		mkdirp.sync('storage/'+id);
		fs.writeFileSync('storage/'+id+'/article.bemjson', JSON.stringify(data), {encoding: 'utf8'});
		var bh = require(bhFilePath);
		var html = bh.apply(data);
		fs.writeFileSync('storage/'+id+'/article.html', html, {encoding: 'utf8'});
		res.status(200).send('ok');
	});
コード例 #29
0
        it('should trap an error on fs.stat',function(done){
            test.mockGlob.lookup['**/*'] = ['unknown.file'];

            var context     = {};
            var policy      = new PolicyUpload();
            policy.apply(context,config.copySettings(),null,function(){
                test.mockLogger.checkMockLogEntries(["ERROR - SKIP ERROR: Error: ENOENT: no such file or directory, stat 'unknown.file'"]);
                context.should.eql({result: {added: 0,updated: 0,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});
                done();
            },onReject);
        });
コード例 #30
0
        it('should upload a file and remember it in the "lastSeenList" then "skip" it and finally "update" it',function(done){
            test.mockGlob.lookup['**/*'] = ['test/data/test.json'];

            test.mockAwsSdk.deferAfterS3ListObjects = function(callback){ callback(null,{Contents: []}); };
            test.mockAwsSdk.deferAfterS3Upload = function(callback){ callback(null,true); };

            var context     = {result: result};
            var policy      = new PolicyUpload();

            policy.lastSeenList.should.eql({});

            policy.apply(context,config.copySettings(),null,function(){
                context.should.eql({result: {added: 1,updated: 0,skipped: 0,ignored: 0,unchanged: 0,delayed: 0}});

                var lastSeen = policy.lastSeenList['test/data/test.json'];
                (!!lastSeen).should.be.ok;
                test.mockAwsSdk.checkMockState([
                    ['s3.listObjects',{Bucket: 'unknown-s3-bucket',Prefix: 'test/data/test.json'}],
                    ['s3.upload',{Bucket: 'unknown-s3-bucket',Key: 'test/data/test.json',Body: true}]
                ]);
                test.mockLogger.checkMockLogEntries(['... add: test/data/test.json => test/data/test.json']);
                test.mockHelpers.checkMockFiles([[config.settings.aws_keys_file,'default']]);

                policy.apply(context,config.copySettings(),null,function(){
                    context.should.eql({result: {added: 1,updated: 0,skipped: 0,ignored: 0,unchanged: 1,delayed: 0}});
                    test.mockLogger.checkMockLogEntries(['DEBUG - ... unchanged: test/data/test.json']);

                    test.mockAwsSdk.deferAfterS3ListObjects = function(callback){ callback(null,{Contents: [{Size: lastSeen.size,LastModified: lastSeen.mtime}]}); };
                    lastSeen = policy.lastSeenList['test/data/test.json'];
                    lastSeen.mtime = lastSeen.atime;

                    policy.apply(context,config.copySettings(),null,function(){
                        context.should.eql({result: {added: 1,updated: 0,skipped: 1,ignored: 0,unchanged: 1,delayed: 0}});
                        test.mockAwsSdk.checkMockState([['s3.listObjects',{Bucket: 'unknown-s3-bucket',Prefix: 'test/data/test.json'}]]);
                        test.mockLogger.checkMockLogEntries(['DEBUG - ... skip: test/data/test.json => test/data/test.json']);

                        lastSeen = policy.lastSeenList['test/data/test.json'];
                        lastSeen.mtime = lastSeen.atime;
                        test.mockAwsSdk.deferAfterS3ListObjects = function(callback){ callback(null,{Contents: [{Size: lastSeen.size + 1,LastModified: lastSeen.mtime}]}); };

                        policy.apply(context,config.copySettings(),null,function(){
                            context.should.eql({result: {added: 1,updated: 1,skipped: 1,ignored: 0,unchanged: 1,delayed: 0}});
                            test.mockAwsSdk.checkMockState([
                                ['s3.listObjects',{Bucket: 'unknown-s3-bucket',Prefix: 'test/data/test.json'}],
                                ['s3.upload',{Bucket: 'unknown-s3-bucket',Key: 'test/data/test.json',Body: true}]
                            ]);
                            test.mockLogger.checkMockLogEntries(['... update: test/data/test.json => test/data/test.json']);

                            done();
                        },done);
                    },done);
                },done);
            },done);
        });