我正在关注有关使用 casperjs 编写模块的文档,但出现错误。
直接来自文档的代码:
// my module, stored in universe.js
// patching phantomjs' require()
var require = patchRequire(require);
// now you're ready to go
var utils = require('utils');
var magic = 42;
exports.answer = function() {
return utils.format("it's %d", magic);
};
和调用脚本:
var universe = require("./universe");
var casper = require("casper").create();
console.log(universe.answer());
casper.test.begin("Home Page", 1, function suite(test) {
});
但我收到以下错误:
casperjs test testStage.js
Test file: testStage.js
CasperError: Can't find module ./universe
/usr/local/Cellar/casperjs/1/libexec/bin/bootstrap.js:214 in patchedRequire
/Users/smosk/Google Drive/source/nest/testStage.js:1
FAIL CasperError: Can't find module ./universe
# type: error
# file: testStage.js
# subject: false
# error: "CasperError: Can't find module ./universe"
# stack: in patchedRequire() in /usr/local/Cellar/casperjs/1/libexec/bin/bootstrap.js:214
in anonymous() in testStage.js:1
FAIL 1 test executed in 0.031s, 0 passed, 1 failed, 0 dubious, 0 skipped.
Details for the 1 failed test:
In testStage.js
Untitled suite in testStage.js
error: CasperError: Can't find module ./universe
还尝试先定义 casper:
var casper = require("casper").create();
var universe = require("./universe");
但这只是导致
Test file: testStage.js
CasperError: Can't find module ./universe
/usr/local/Cellar/casperjs/1/libexec/bin/bootstrap.js:214 in patchedRequire
/Users/smosk/Google Drive/source/nest/testStage.js:2