可能是您项目中的配置根本没有完成,我按照firebase 功能的快速入门,部署到我的项目,然后使用以下命令安装依赖项:
npm install jest @types/jest firebase-functions-test ts-jest -D
将测试脚本添加到我的 package.json
“测试”:“开玩笑--watchAll--verbose=false”
最后在我的项目(在我的函数目录)中配置了 jest(jest.config.js)
// this config includes typescript specific settings
// and if you're not using typescript, you should remove `transform` property
module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: 'src(/testing/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
testPathIgnorePatterns: ['lib/', 'node_modules/'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testEnvironment: 'node',
rootDir: 'src',
}
毕竟,我在 function/src 文件夹中创建了一个测试目录,并在 testing 中编写了一个像这样的简单测试
test("should pass", () => {
// test test lol
expect(1).toBe(1);
});
最后,如果您对我使用的依赖项有任何其他疑问,可以查看我的 package.json 文件。
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "jest --watchAll --verbose=false"
},
"engines": {
"node": "8"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^8.6.0",
"firebase-functions": "^3.3.0"
},
"devDependencies": {
"@types/jest": "^24.0.19",
"firebase-functions-test": "^0.1.6",
"jest": "^24.9.0",
"ts-jest": "^24.1.0",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
"private": true
}