나는 여기에서 간단한 테스트를해야겠다. 아이디어는 팬텀이 모카의 tdd에서 작동하도록하는 것입니다. (그런데 내가 성공하지 노드 팬텀과 phantomjs 노드를 모두 노력했다.) 다음과 같이모카에서 노드 팬텀을 실행
nodephantom = require 'node-phantom'
assert = require("chai").assert
host = 'http://google.com'
phantom = null
page = null
suite "Mocha Node-Phantom Loading Google:", ->
suiteSetup (done) ->
nodephantom.create (err,p) ->
phantom = p
done()
test "Google page should load", (done) ->
phantom.createPage (p) ->
page = p
page.open host, ->
assert.match page.content(), /google/, "Page is loaded"
done()
suiteTeardown ->
phantom.exit()
내가 코드를 실행 :
mocha -u tdd -R tap -b sometest.coffee
내가받을 다음과 같은 오류 :
1..1
not ok 1 Mocha Node-Phantom Loading Google: "before all" hook
Error: global leak detected: location
at Runner.checkGlobals (/home/ericstob/b/nodejs/lib/node_modules/mocha/lib/runner.js:104:21)
at Runner.<anonymous> (/home/ericstob/b/nodejs/lib/node_modules/mocha/lib/runner.js:44:44)
at Runner.EventEmitter.emit (events.js:88:17)
at Runner.hook (/home/ericstob/b/nodejs/lib/node_modules/mocha/lib/runner.js:170:12)
at done (/home/ericstob/b/nodejs/lib/node_modules/mocha/lib/runnable.js:134:5)
at Runnable.run.duration (/home/ericstob/b/nodejs/lib/node_modules/mocha/lib/runnable.js:146:9)
at phantom.createPage.page (/home/ericstob/b/seo/t/sometest.coffee:18:16)
at SocketNamespace.module.exports.create (/home/ericstob/b/nodejs/lib/node_modules/node-phantom/node-phantom.js:156:4)
at SocketNamespace.EventEmitter.emit [as $emit] (events.js:115:20)
at connect (/home/ericstob/b/nodejs/lib/node_modules/node-phantom/node_modules/socket.io/lib/namespace.js:292:10)
at /home/ericstob/b/nodejs/lib/node_modules/node-phantom/node_modules/socket.io/lib/namespace.js:308:13
at SocketNamespace.authorize (/home/ericstob/b/nodejs/lib/node_modules/node-phantom/node_modules/socket.io/lib/namespace.js:252:5)
at SocketNamespace.handlePacket (/home/ericstob/b/nodejs/lib/node_modules/node-phantom/node_modules/socket.io/lib/namespace.js:302:14)
at Manager.handleClient (/home/ericstob/b/nodejs/lib/node_modules/node-phantom/node_modules/socket.io/lib/manager.js:697:32)
at Manager.handleUpgrade (/home/ericstob/b/nodejs/lib/node_modules/node-phantom/node_modules/socket.io/lib/manager.js:618:8)
at Server.<anonymous> (/home/ericstob/b/nodejs/lib/node_modules/node-phantom/node_modules/socket.io/lib/manager.js:123:10)
at Server.EventEmitter.emit (events.js:115:20)
at Socket.socket.ondata (http.js:1710:14)
at TCP.onread (net.js:403:27)
이 테스트에서 팬텀을 제거하면 예상대로 작동합니다.
assert = require("chai").assert
is_decimal = (val) -> assert.match String(val), /^-?[0-9]*\.?[0-9]+$/, String(val) + ' is a decimal.'
is_hex = (val) -> assert.match String(val), /^(0[xX])?[a-fA-F0-9]+$/, String(val) + ' is a hexadecimal.'
suite "Mocha Minimal Test:", ->
suiteSetup (done) ->
done()
test "Assertions pass", (done) ->
is_decimal 1.5
is_hex "0x2fc3"
done()
test "Assertions fail", (done) ->
is_decimal 'dog'
done()
suiteTeardown ->
{}
결과 :
$ mocha -u tdd -R tap -b mintest.coffee
1..2
ok 1 Mocha Minimal Test: Assertions pass
not ok 2 Mocha Minimal Test: Assertions fail
'dog' is a decimal.: expected 'dog' to match /^-?[0-9]*\.?[0-9]+$/
그래서 나는 내 테스트의 기본 구조가 정확한지 알고 모카는 행복하다. 그러나 노드 - 팬텀 (node-phantom)이 불만족 스럽다는 점이 있습니다.
이 프레임 워크 내에서 phantomjs 작업을 원합니다. 누구든지 나를 도울 수 있습니까?