- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题描述:
我为 typescript 类编写了两个测试。这两个测试通过了,因此 jest 成功检索了测试文件。然后我使用 --coverage 选项,但看起来 Jest 并没有在这里选择覆盖的文件。
这是我得到的输出:
api_jester | PASS src/tests/repositories/user.test.ts
api_jester | User Repository
api_jester | ✓ it should return an empty array (18ms)
api_jester | ✓ should successfully create a user and return its data (7ms)
api_jester |
api_jester | ----------|----------|----------|----------|----------|-------------------|
api_jester | File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
api_jester | ----------|----------|----------|----------|----------|-------------------|
api_jester | All files | 0 | 0 | 0 | 0 | |
api_jester | ----------|----------|----------|----------|----------|-------------------|
api_jester | Test Suites: 1 passed, 1 total
api_jester | Tests: 2 passed, 2 total
api_jester | Snapshots: 0 total
api_jester | Time: 3.208s
api_jester | Ran all test suites.
我尝试使用collectCoverageFrom选项,但没有成功。我已经用 github 上找到的一些简单示例进行了测试,这些示例正在运行,因此问题不是来 self 的环境。我猜我在配置中遗漏了一些东西,但我在这上面花了很多时间,我有点沮丧,所以也许一些新鲜的外观可以有所帮助..
项目架构:
config
|__ jest.config.js
|__ tsconfig.json
src
|__tests
| |__repositories
| |__user.test.ts
|__repositories
|___ userRepository
|__User.ts
Jest.config.js:
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
roots: ["../src/tests/"],
transform: {
"^.+\\.tsx?$": "ts-jest"
},
collectCoverageFrom: ["../src/"],
moduleFileExtensions: ["ts", "js", "json"],
coverageDirectory: "../coverage"
};
package.json
{
"name": "theralog_api",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"build": "tsc",
"prettier": "npx prettier --write src/**/*.ts --config ./config/.prettierrc",
"eslint": "npx eslint --config ./config/.eslintrc ./src/**/**/*",
"start:dev": "npx nodemon -L --config ./config/api.nodemon.json",
"test:watch": "npx nodemon -L --config ./config/jester.nodemon.json",
"test:coverage": "npx jest --config ./config/jest.config.js --coverage --colors --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/compression": "^1.0.1",
"@types/express": "^4.17.1",
"@types/graphql-depth-limit": "^1.1.2",
"@types/jest": "^24.0.23",
"@types/node": "^12.7.12",
"@typescript-eslint/eslint-plugin": "^2.5.0",
"@typescript-eslint/parser": "^2.5.0",
"apollo-server-testing": "2.9.7",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"graphql-depth-limit": "^1.1.0",
"graphql-import": "^0.7.1",
"graphql-import-node": "0.0.4",
"jest": "^24.9.0",
"nodemon": "^1.19.3",
"prettier": "^1.18.2",
"ts-jest": "^24.1.0",
"ts-node": "^8.4.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.7.2"
},
"dependencies": {
"apollo-server-express": "^2.9.6",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"graphql": "^14.5.8",
"http": "0.0.0",
"lodash": "^4.17.15",
"ncp": "^2.0.0",
"pg": "^7.12.1",
"winston": "3.2.1"
}
}
jester.nodemon.json
{
"watch": ["../src"],
"ext": "ts",
"exec": "npx jest --config ./config/jest.config.js --watchAll"
}
最佳答案
您在 jest.config.js 中缺少一项设置,collectCoverage: true
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
roots: ["../src/tests/"],
transform: {
"^.+\\.tsx?$": "ts-jest"
},
collectCoverage: true,
collectCoverageFrom: ["../src/"],
moduleFileExtensions: ["ts", "js", "json"],
coverageDirectory: "../coverage"
};
我还使用更具描述性的collectCoverageFrom:
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
'!<rootDir>/src/**/*.interface.ts',
'!<rootDir>/src/**/*.mock.ts',
'!<rootDir>/src/**/*.module.ts',
'!<rootDir>/src/**/*.spec.ts',
'!<rootDir>/src/**/*.test.ts',
'!<rootDir>/src/**/*.d.ts'
],
通过这种方式,我可以排除一些我不想计算覆盖率的文件,例如我的模块、模拟和测试。
我的完整文件,其中包含原始 Jest 初始化过程以及其中的评论。
有关每个配置属性的详细说明,请访问:the Jest documentation
module.exports = {
// All imported modules in your tests should be mocked automatically
// automock: false,
// Stop running tests after the first failure
// bail: false,
// Respect "browser" field in package.json when resolving modules
// browser: false,
// The directory where Jest should store its cached dependency information
// cacheDirectory: "C:\\Users\\sscott\\AppData\\Local\\Temp\\jest",
// Automatically clear mock calls and instances between every test
// clearMocks: false,
// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
'!<rootDir>/src/**/*.mock.ts',
'!<rootDir>/src/**/*.module.ts',
'!<rootDir>/src/**/*.spec.ts',
'!<rootDir>/src/**/*.test.ts',
'!<rootDir>/src/**/*.d.ts'
],
// The directory where Jest should output its coverage files
coverageDirectory: "<rootDir>/docs",
// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: [
"\\\\node_modules\\\\"
],
// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: [
"lcov",
"clover",
"text-summary"
],
// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: null,
// Make calling deprecated APIs throw helpful error messages
errorOnDeprecated: true,
// Force coverage collection from ignored files usin a array of glob patterns
// forceCoverageMatch: [],
// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: null,
// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: null,
// A set of global variables that need to be available in all test environments
globals: {
"ts-jest": {
"diagnostics": false,
"tsConfig": "tsconfig.json"
}
},
// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],
// An array of file extensions your modules use
moduleFileExtensions: [
"ts",
"tsx",
"js"
],
// A map from regular expressions to module names that allow to stub out resources with a single module
// moduleNameMapper: {},
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
// Activates notifications for test results
// notify: false,
// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "always",
// A preset that is used as a base for Jest's configuration
// preset: null,
// Run tests from one or more projects
// projects: null,
// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
// Automatically reset mock state between every test
// resetMocks: false,
// Reset the module registry before running each individual test
// resetModules: false,
// A path to a custom resolver
// resolver: null,
// Automatically restore mock state between every test
// restoreMocks: false,
// The root directory that Jest should scan for tests and modules within
// rootDir: null,
// A list of paths to directories that Jest should use to search for files in
roots: [
"<rootDir>/src"
],
// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",
// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],
// The path to a module that runs some code to configure or set up the testing framework before each test
// setupTestFrameworkScriptFile: null,
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],
// The test environment that will be used for testing
testEnvironment: "node",
// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
// Adds a location field to test results
// testLocationInResults: false,
// The glob patterns Jest uses to detect test files
testMatch: [
"**/*.spec.ts"
],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],
// The regexp pattern Jest uses to detect test files
// testRegex: "",
// This option allows the use of a custom results processor
// testResultsProcessor: null,
// "testResultsProcessor": "jest-jenkins-reporter",
// This option allows use of a custom test runner
// testRunner: "jasmine2",
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
// testURL: "http://localhost",
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
// timers: "real",
// A map from regular expressions to paths to transformers
transform: {
"^.+\\.(ts|tsx)$": "ts-jest"
},
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
// Indicates whether each individual test should be reported during the run
verbose: false
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],
// Whether to use watchman for file crawling
// watchman: true,
};
关于node.js - Jest 通过了测试,但 --covering 选项未拾取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58881706/
我将视差效果与 background-size: cover; 一起使用。当屏幕分辨率为 +1090px 时没有问题,但如果它更小,背景图像开始隐藏在底部 div 下。 这是我的 bg img 的 c
我想存储来自 Coverity® 的结果到 InfluxDB,我想知道 Coverity 是否有 REST API? 最佳答案 如果您只是想将数据转储到 InfluxDB,您可以从 REST API
这个问题在这里已经有了答案: How to remove the stripes that appears when using linear gradient property [duplica
我已经建立了一个项目来使用 Coverity Scan . 在分析设置→项目组件下我有 Component name Pattern Ignore in analysis
我是使用覆盖的新手,这可能不是一个非常具有挑战性的问题,但如果有人能指导我完成设置 . 我首先运行以下命令: cov-configure --compiler/usr/bin/gcc --compty
我使用封面图像填充侧边栏,但在未填充正文的封面图像和封面正文本身之间出现了一条黑线。您可以在实际中看到它 here .我很确定这不是边界或其他任何东西。 谢谢! HTML CSS .co
我正在尝试构建一个背景图片我希望始终填满整个屏幕的网站。 当浏览器窗口又短又宽时,我希望图像展开,以便它的顶部在纵向填满整个屏幕,而其余部分则不可见。 当浏览器窗口又高又薄时,我希望图像展开,以便它的
我需要在其中一个元素上设置“封面”背景。 使用 CSS background-size: cover 与实际 img 和 object-fit: cover 的优缺点是什么? 最佳答案 除了其他人所说
我正在尝试用图像填充 div,同时保持其纵横比。但是我不想使用带有 background-size: cover 的背景图像,甚至不想使用 object-fit: cover 属性,我想要它们使用 i
这是我非常简单的 C++/CMake .travis.yml env: global: # The next declaration is the encrypted COVERITY_SC
在我通过启动并运行一个 100% 覆盖率的小型 C++ 测试项目来了解更多关于自动化测试的过程中,我遇到了以下问题——尽管我所有的实际代码行和所有执行分支都是被测试覆盖,lcov 仍然报告两行未经测试
我已经用 coverity-scan 注册了一个项目过去。 我现在想从 coverity-scan 中删除该项目(或者至少从我的仪表板中删除;但我更希望完全删除该项目)。 我被卡住了,因为网络界面中似
我通过覆盖工具收到以下错误 - overrun-buffer-arg:通过将 4 字节的结构类型 in_addr 传递给使用参数“8UL”在字节偏移量 7 处访问它的函数来溢出 4 个字节。 示例代码
有一个覆盖警告类型:UNUSED_VALUE。这是由“代码可维护性问题”下的工具定义的 UNUSED_VALUE:当一个变量被分配一个从函数调用返回的指针值并且从未在源代码中的其他任何地方使用时,它不
对 Java 来说相对较新,但任务是检查 Coverity 缺陷。这件事真像我想的那么简单吗? (我无法说服代码所有者。) 50 // this method is used when
我想在本地虚拟机上使用 Coverity。我创建了简单的 HalloWorld 并使用 Coverity Wizard 来设置分析。一切正常。问题是当我想从终端运行 Coverity 时。它没有“找到
给定以下程序: int main(){ float x = non_det_float(); float y = NAN; if (isnan(y) && x == 1.0f){
我想实现如下的封面流程 我试过 Carousel,但它不是一回事。一些谷歌搜索是否无法找到甚至接近给定示例中实现的封面流程的内容。 最佳答案 一定要看看这个,FancyCoverFlow . Play
如果我使用 background-size: cover 并且我想确保我的图像在分辨率为 2880x1880 的视网膜 macbook pro 上看起来不错,我是否只需要使图像达到该分辨率,或者它是否
我有两个 block 元素,第一个 ( ) 是浏览器窗口的大小并呈现动态大小的背景图像(使用 background-size: cover; )。另一个是固定的 高度恒定为 62px 和更大的 z-
我是一名优秀的程序员,十分优秀!