私はnodenameでテストしているCoffeescriptで書かれたWebアプリケーションを持っており、テストで設定されたグローバル変数(「セッション」変数)にアクセスできないようです:出力のCoffeescript、nodeunit、およびglobal変数
のsrc/test.coffee
root = exports ? this
this.test_exports = ->
console.log root.export
root.export
テスト/ test.coffee
exports["test"] = (test) ->
exports.export = "test"
test.equal test_file.test_exports(), "test"
test.done()
結果:
test.coffee
undefined
✖ test
AssertionError: undefined == 'test'
テストでグローバルにアクセスするにはどうすればよいですか?
'b'-Flagでコンパイルしてみてください。これにより、セキュリティクロージャが追加されなくなります。 – TimWolla
ソースが 'nice -n 19 coffee -o web/-b -c -w src /'フラグでコンパイルされました。Trevor Burnhamの連続Cakefileビルド=(watch、callback)に-bを追加しました - > \t typeof演算時計は '関数' \t \tコールバックがある場合= falseを= \t \t時計を見 \tオプション= [ '-b'、 '-c'、 '-o'、 'libに'、 'SRC'] \tオプション を見るなら.unshift '-w'だがダイスはない。 –
グローバル変数を使用しないでください。 – Raynos