控制台错误
Error: The creation time must be a valid UTC date string.[0m[90m
at FirebaseAuthError.FirebaseError [as constructor] (node_modules\firebase-admin\lib\utils\error.js:39:28)
at FirebaseAuthError.PrefixedFirebaseError [as constructor] (node_modules\firebase-admin\lib\utils\error.js:85:28)
at new FirebaseAuthError (node_modules\firebase-admin\lib\utils\error.js:143:16)
at validateCreateEditRequest (node_modules\firebase-admin\lib\auth\auth-api-request.js:194:15)
at D:\webstorm_workspace\pixelcity-new-local-server\functions\node_modules\firebase-admin\lib\auth\auth-api-request.js:346:5
at D:\webstorm_workspace\pixelcity-new-local-server\functions\node_modules\firebase-admin\lib\auth\auth-api-request.js:700:13
at <anonymous>
From previous event:
From previous event:
at listAllUsers.then.then (test\test.online.js:118:20)
at <anonymous>
package.json
"dependencies": {
"@heroiclabs/nakama-js": "^2.0.1",
"bluebird": "^3.5.1",
"cookie-parser": "^1.4.3",
"cors": "^2.8.1",
"errorhandler": "^1.5.0",
"express": "^4.16.3",
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.1.0",
"jsdom": "11.11.0",
"jsdom-global": "3.0.2",
"moment": "^2.22.2"
},
"devDependencies": {
"chai": "^4.1.2",
"cross-env": "^5.2.0",
"eslint": "^4.19.1",
"eslint-plugin-promise": "^3.8.0",
"firebase-functions-test": "^0.1.2",
"mocha": "^5.2.0",
"sinon": "^6.0.1"
}
代码(摩卡测试)
....
describe('Test Cloud Functions', () => {
let initData;
let uid = "antiqueUid";
before((done) => {
// Require index.js and save the exports inside a namespace called myFunctions.
// This includes our cloud functions, which can now be accessed at myFunctions.makeUppercase
// and myFunctions.addMessage
initData = require("../../build/pixelcity-demo-48860.export");
myFunction = require('../index');
// 강제 debug break point 진입
if (typeof(v8debug) !== undefined) {
debugger;
}
// Do cleanup tasks.
test.cleanup();
// Resolution method is overspecified. Specify a only callback *or* only return a Promise; not both!!
// 내부적으로는 promise chain으로 연결되어야하고, 외부 최초 return은 callback처럼 작성하기
// callback type과 promise 타입을 섞어서 쓰면 작동을 안한다
admin.database().ref('/').remove().then(() => {
users = [];
return listAllUsers(users).then(users => {
return Promise.each(users, (item) => {
return admin.auth().deleteUser(item.uid);
}).then(() => {
let userCountRef = admin.database().ref("saving-data/count");
return userCountRef.update({
"user": 0
});
});
// end clear data
}).then(() => {
return Promise.each(objectToArray(initData.user), (item, index, length) => {
item.value.password = "11112222";
return admin.auth().createUser(item.value);
});
}).then(() => {
return admin.database().ref('/').set(initData);
}).then((ref) => {
let userArr = [];
return listAllUsers(userArr).then((users) => {
let userCountRef = admin.database().ref("saving-data/count/user");
return userCountRef.transaction(function (current_value) {
let userCount = users.length;
return userCount;
});
});
// end dump test data
});
}).then(() => done()).catch((err) => done(err));
});
....
describe('signupTrigger', () => {
before((done) => {
users = [];
done(); // done()을 안하면 멈춰서 다음 case로 넘어가지지 않는다
});
it('should occur signupTrigger when user created(cloud database onCreate)', (done) => {
// [START assertOnline]
// Create a DataSnapshot with the value 'input' and the reference path 'messages/11111/original'.
let mockVal = {
uid: uid,
email: "testandtest.net"
};
let mockRefPath = 'user/' + uid;
const snap = test.database.makeDataSnapshot(mockVal, mockRefPath, admin.app());
// Wrap the makeUppercase function
const wrappedSignupTrigger = test.wrap(myFunctions.signupTrigger);
// Call the wrapped function with the snapshot you constructed.
return wrappedSignupTrigger(snap).then(() => {
// Read the value of the data at messages/11111/uppercase. Because `admin.initializeApp()` is
// called in functions/index.js, there's already a Firebase app initialized. Otherwise, add
// `admin.initializeApp()` before this line.
return admin.database().ref('userProperty/' + uid).once('value').then((createdSnap) => {
let val = createdSnap.val();
// Assert that the value is the uppercased version of our input.
assert.equal(val.level, 1, `userProperty/${uid}/level: ${val.level}`);
return admin.database().ref("saving-data/count/user").once('value').then((currentSnap) => {
let currentUserLength = currentSnap.val();
let prevUserLength = objectToArray(initData.user).length;
assert.equal(currentUserLength, prevUserLength + 1, `saving-data/count/user: ${currentUserLength}`);
return Promise.resolve();
});
}).then(() => done()).catch((err) => done(err));
});
// [END assertOnline]
});
});
....
我们正在使用Mocha框架对Firebase身份验证,数据库,云功能进行单元测试
我尝试创建test.database.makeDataSnapshot,但由于Firebase核心错误(JSON.parse-无法解析“ u” ...),因此未创建该文件。
所以我今天更新了整个npm软件包,并且得到了上面的错误
这是最初传递的代码,但是由于完成了更新程序包而发生了错误,并且未检索到相关的问题/文档。
我该如何解决?