Tag: coffeescript

如何在节点中用coffeescript导出类

文件1: module.exports = { class Verify myMethod: -> # return stuff 和file2: Verify = require('excelTest.js') verify = new Verify verify = verify.myMethod() 以上失败: Running "coffee:glob_to_multiple" (coffee) task >> server/api/abrechnung/excelTest.coffee:7:2: error: unexpected class >> class Verify >> ^^^^^ >> In file: server/api/abrechnung/excelTest.coffee >> On line: 6 >> class Verify >> ^

我如何用咖啡脚本和ES6创build一个sails.js项目

我尝试使用咖啡脚本和ES6创buildsails.js项目首先,我使用新的'appName'和npm install咖啡脚本–save npm install babel –save 并修改app.js options = { loose : "all", stage : 1, ignore : null, only : null, extensions: null }; require("sails-hook-babel/node_modules/babel/register")(options); 但是这是错的 我看到别人可以通过自动创build它(它可以创buildapp.coffee local.coffee …等不需要修改)如何做到这一点? ———————————————– error: ** Grunt :: An error occurred. ** error: ———————————————————————— Warning: Task "watch" not found. Aborted due to warnings. ———————————————————————— error: Looks like a […]

Node.js – Gunzip已读文件的asynchronous问题

相对较新的node.js和asynchronous的做法,到目前为止,我已经能够使用承诺阅读文件使用fs readFile,但我没有任何运气让zlib Gunzip工作。 用Coffeescript写作: promisifyRun(fs, 'readFile', filepath, 'utf-8') .then (file) -> promisifyRun(zlib, 'Gunzip', file) .then (data) -> console.log "HELLO" return data .catch respondError res promisfyRun是承诺一个单一的function(我没有写,但它的确工作)。 我已经成功地将它用于fs.readFile组件,如下所示: promisifyRun(fs, 'readFile', filepath, 'utf-8') .then (data) -> return data .catch respondError res 这工作得很好,它等待文件被打开,然后继续。 'data'包含文件的主体。 我认为它应该是一个非常合乎逻辑的扩展,将枪支组件纳入其中,但迄今为止这一直是一个挑战。 我看了几个npm gunzip模块。 看起来最有趣的是gunzip-或者zlib.Gunzip (我在这里尝试)。 这个特定情况的错误信息是: “未处理的拒绝错误:发送后无法设置标题”。 我认为这与已经完成的asynchronous性原因有关 更新 – 全堆栈跟踪: 未处理的拒绝错误:发送后无法设置标题。 ServerResponse.send(/ Users / […]

编译Coffeescript时不要添加var

我在写一个简单的应用程序,使用John Resig的简单类inheritance 。 我在Node.js中这样做,我也使用CoffeeScript。 我试图编写CoffeeScript, 在BrowserQuest游戏中输出类似于这个文件的代码。 当我这样写CoffeeScript的时候, cls = require './class' module.exports = Model = cls.Class.extend({ init: () -> console.log 'Model.init()' }) “var”会自动添加到Model中,因此似乎不能正确导出。 var Model, cls; cls = require('../class'); module.exports = Model = cls.Class.extend({ init: function() { return console.log('Model.init()'); } }); 有没有办法标记一个variables不使用CoffeeScript的“var”?

自定义错误在throw语句或next()调用中不能正确传播

我正在开发一个Node.js / CoffeeScript应用程序,我正在使用类层次结构的错误。 当我在路由处理程序的根中使用throw语句时,一切正常。 class APIError extends Error constructor: -> app.error (err, req, res, next) -> if err instance of APIError console.log 'APIError captured' app.get '/', (req, res, next) -> throw new APIError 但是,在Mongoose中,在callback函数中使用throw语句: app.get '/', (req, res, next) -> UserModel.where('name', 'Joe').findOne (err, doc) -> throw new APIError 结果是 /usr/local/lib/node_modules/mongoose/lib/utils.js:413 throw err; ^ Error: 当我调用next()而不是,如 […]

每次testing之前都无法获得所需的文件

我尝试将咖啡与咖啡和柴混合使用。 在包含testing的每个文件之前,我想包含以下文件: testing/ _helper.coffee path = require 'path' AppDir = path.resolve("#{__dirname}/../src/app") chai = require('chai') should = chai.should() factories = require('chai-factories') chai.use(factories) 这样我才能访问AppDirvariables。 所以当我想要一个文件时,我不需要指定app目录的完整path。 testing/应用程序/ setup-test.coffee describe 'Setup instance', -> it 'should be a object', -> setup = require "#{AppDir}/setup" setup.should.be.a('object') 我尝试了以下设置: 添加_hellper.coffee摩卡命令行选项,如下所示: ./node_modules/.bin/mocha –require coffee-script –require test/_helper.coffee –compilers coffee:coffee-script –recursive –reporter spec test 所以: ./node_modules/.bin/mocha […]

我的摩卡testing分开工作,但一次运行全部失败

这可能与asynchronous代码有关,但我不知道是什么。 当我将它们分开时,两者都通过: mocha test/models.coffee和mocha test/login.coffee 但是, describe 'saving another user with same username', ->与npm test一起运行testing失败。 我想数据库得到清除,因为它正在运行该步骤,所以它节省了,而不是产生一个错误,因为它应该是一个独特的价值。 另外:在这个软件testing方面我是非常新的,如果有人有任何提示,或者想批评我公然的错误,随时给我发电子邮件(检查我的个人资料) 谢谢!! 这里是我的两个testing文件(coffeescript): /test/models.coffee should = require 'should' {User} = require '../models' # function to find our test user, John Egbert findJohn = (cb) -> User.findOne {'public.username': 'john'}, (err, john) -> throw err if err cb(john) before (done) -> […]

我如何断言一个函数被调用?

我有一个山羊类: class Goat constructor: (@headbutt) -> @isCranky = true approach: -> if @isCranky @headbutt() 我想写一个摩卡testing来声明,如果isCranky为true并调用方法,则调用headbutt()。 我能find的唯一解释是在Ruby中。 试着翻译它,但失败了。 我怎样才能断言正确的function被称为? 我认为我可以用一种拙劣的方式解决问题,但宁可学习正确的方法。 build议?

导出所需的相同对象会混淆摩卡

我正在使用摩卡运行unit testing的节点应用程序。 当我运行这个命令时: mocha –compilers coffee:coffee-script –reporter spec ./test/unit/*-test.coffee 我得到这个错误: ERROR: Unknown option –compilers 看来摩卡是混乱的,因为它肯定有一个编译器选项。 当我添加一个新的文件到项目时,这个错误开始发生。 这是我可以得到摩卡生成的唯一输出。 – 破坏者什么都不做。 比方说,我有一个名为人安装的软件包。 我想全局configuration这个包,这样我就可以在我的项目的任何地方导入configuration的对象。 为此,我导入人员,将其configuration为驱动程序,然后重新导出。 但是,当我导入它(无论是在Car.coffee或Car-test.coffee),摩卡失败,出现上述错误。 Driver.coffee driver = require 'person' driver.setSkill "Drive" module.exports = driver Car.coffee driver = require './driver' … Car-test.coffee driver = require '../../src/driver' … 请注意,这工作正常,如果我只是用咖啡编译和运行节点项目。 这里没有问题导入。 但是当我用摩卡运行,如果我导入文件失败。 我无法确定这个错误。 这看起来就像摩卡的一个错误,但也许我正在做一些“坏”的东西,通过导出相同的对象,我导入,节点只是更宽容? 我正在使用最新版本的摩卡(1.13.0)。 谢谢! 编辑: 这不能解决这个错误,而且不是理想的语法: person […]

使用节点的作用域http客户端的选项,将rejectUnauthorized设置为false

使用节点的HTTP库,我可以轻松设置我想要的选项 options = port: 443 path: "/" method: 'GET' rejectUnauthorized: false https.get options, (res) -> … 我如何做node-scoped-http-client的同样的事情? # Passing options doesn't seem to work (defined as above) cli = msg.http(stats_url, options) # Injecting it doesn't pass it on either cli.options['rejectUnauthorized'] = false 我仍然得到这个错误: ERROR Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE 我在这里错过了什么吗? 我对node和coffeescript相当陌生。