Javascript 理解幽灵JS中的作用域

Javascript 理解幽灵JS中的作用域,javascript,node.js,phantomjs,casperjs,spookyjs,Javascript,Node.js,Phantomjs,Casperjs,Spookyjs,SpookyJS的这个实现真的很吓人。在使用Gulp运行Mocha+SpookyJS测试时,我无法看到大多数控制台日志输出。我一直在遵循SpookyJS的github上的快速入门步骤。为什么我看不到这些控制台日志输出 describe('test', function () { it('test 1', function(done){ try { var Spooky = require('spooky'); } catch (e) { var

SpookyJS的这个实现真的很吓人。在使用Gulp运行Mocha+SpookyJS测试时,我无法看到大多数控制台日志输出。我一直在遵循SpookyJS的github上的快速入门步骤。为什么我看不到这些控制台日志输出

describe('test', function () {
it('test 1', function(done){

    try {
        var Spooky = require('spooky');
    } catch (e) {
        var Spooky = require('../lib/spooky');
    }
    var spooky = new Spooky({
            child: {
                transport: 'http'
            },
            casper: {
                logLevel: 'debug',
                verbose: true
            }
        }, function (err) {
            if (err) {
                e = new Error('Failed to initialize SpookyJS');
                e.details = err;
                throw e;
            }

            spooky.start(URL);
            console.log('Hello 3');  //currently this is not printing anything to the console
            spooky.then(function () {                
                 this.emit('hello', 'Hello, from ' + this.evaluate(function () {
                 return document.title;
                 }));                  
            });
            spooky.run();
            console.log('Hello 1');  //currently this is not printing anything to the console
        });
        spooky.on('hello', function (line) {
           console.log(line);
        });
        spooky.on('console', function (line) {
           console.log(line);
        });
        spooky.on('error', function (e, stack) {
            console.error(e);

            if (stack) {
                console.log(stack);
            }
        });

    console.log('Hello 2');  //this is printing to the console
    done();

    });
});

简化代码,大致如下所示:

describe('test', function () {
    it('test 1', function(done){
        var Spooky = require('spooky');
        var spooky = create a spooky object with a lot of logic in it;

        console.log('Hello 2');  //this is printing to the console
        done();
    });
});
创建了
spooky
对象,之后,程序流继续运行。
spooky
对象所做的任何事情,稍后都会异步执行

创建了
spooky
对象后,您将获得
Hello 2
,然后调用
done()
,从而结束此测试

因此,在处理任何
hello
内容之前,您的测试已经结束

done()
行移到此处可能会有所帮助:

spooky.on('hello', function (line) {
    console.log(line);
    done();
});
一旦捕获到
hello
事件,测试将结束


由于我不熟悉《幽灵》(Spooky)或您想要测试的内容,我恐怕帮不上什么忙了。希望这能让您更进一步。

您确定您的代码达到了日志记录的程度吗?e、 匿名函数运行吗?不,我没有看到文档标题。目前唯一的控制台输出是Mocha进度条和Hello 2控制台输出。