私のコードでいくつかのテストを実行しようとしています。しかし、私は彼らにこれを実行しようとするたびにNpmテスト用のFirebaseエラー
> [email protected] test /home/ubuntu/workspace
> mocha
home/ubuntu/workspace/node_modules/@firebase/app/dist/cjs/src /firebaseApp.js:343
throw appErrors.create(code, args);
^
FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
at error (/home/ubuntu/workspace/node_modules/@firebase/app/dist/cjs/src/firebaseApp.js:343:21)
at app (/home/ubuntu/workspace/node_modules/@firebase/app/dist/cjs/src/firebaseApp.js:227:13)
at Object.serviceNamespace [as database] (/home/ubuntu/workspace/node_modules/@firebase/app/dist/cjs/src/firebaseApp.js:283:47)
at Object.<anonymous> (/home/ubuntu/workspace/routes/news.js:7:25)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/ubuntu/workspace/test/test.js:8:12)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at /home/ubuntu/workspace/node_modules/mocha/lib/mocha.js:231:27
at Array.forEach (native)
at Mocha.loadFiles (/home/ubuntu/workspace/node_modules/mocha/lib/mocha.js:228:14)
at Mocha.run (/home/ubuntu/workspace/node_modules/mocha/lib/mocha.js:514:10)
at Object.<anonymous> (/home/ubuntu/workspace/node_modules/mocha/bin/_mocha:484:18)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
を返されたが、私はHerokuの上でアプリをプレビューする際に、アプリが正常に動作しているものです。
test.js上記
this.jsdom = require('jsdom-global')()
global.$ = global.jQuery = require('jquery');
var expect = require("chai").expect;
var test = require("../public/javascripts/testing");
var getStock = require("../public/javascripts/getStock.js");
var index = require("../routes/index.js");
var news = require("../routes/news.js");
var express = require('express');
var firebase = require('firebase');
var router = express.Router();
var yahooStocks = require("yahoo-stocks");
before(function(done) {
var config = {
apiKey: process.env.firebase,
authDomain: "xxxxxxxx",
databaseURL: "xxxxxxxx",
projectId: "xxxxx",
storageBucket: "",
messagingSenderId: "xxxxxxxxxxxxxx"
};
firebase.initializeApp(config);
firebase.auth().signInWithEmailAndPassword("default", "default");
done();
})
describe("Home page tests", function() {
it("Should Callback AAPL",function(done) {
this.timeout(3000);
news.get_stock_news("AAPL",function(data){
console.log(data);
expect(data).to.be.above(0);
done();
})
})
});
news.js
var express = require('express');
var firebase = require("firebase");
var router = express.Router();
var https = require("https");
// Get a reference to the database service
var database = firebase.database();
var googleFinance = require('google-finance');
var userUid;
var handle;
var signedIn = false;
var names = [];
var info = [];
var urls = [];
var namesReturned = [];
var auth = "Basic " + new Buffer(username + ':' + password).toString('base64');
function get_stock_news(symbol,callback){
var request = https.request({
method: "GET",
host: "api.intrinio.com",
path:"/news?ticker="+symbol+"&page_size=1",
headers: {
"Authorization": auth
}
} , function(response) {
var json = "";
response.on('data', function (chunk) {
json += chunk;
});
response.on('end', function() {
var company = JSON.parse(json);
callback(company.data[0].ticker);
});
});
});
module.exports = router;
module.exports.get_stock_news = get_stock_news;
私が使用していたコードです。コードが機能するので、セミコロンなどが見つからない場合は、自分の書式から取り除いてください。私はfirebaseはあなたがtest.js
でfirebase.initializeApp()
を呼び出す前に、あなたはnews.js
でvar database = firebase.database();
を呼び出すことはできません
期待どおりに動作しないコードとテストを教えてください。 –