探索 vue-cli4 创建集成 mocha + chai 的项目中,如何写单元测试和查看单元测试覆盖率。

1、建立一个集成单元测试的项目

首先创建一个新的项目 vue-cli4-unit-mocha-chai-nyc:

vue create vue-cli4-unit-mocha-chai-nyc# 选择手动配置
? Please pick a preset: zcloud (router, vuex, less, babel, eslint, unit-jest) default (babel, eslint) 
❯ Manually select features # 选择需要的功能
? Please pick a preset: Manually select features
? Check the features needed for your project: ◉ Babel◯ TypeScript◯ Progressive Web App (PWA) Support◉ Router◉ Vuex◉ CSS Pre-processors◉ Linter / Formatter◉ Unit Testing
❯◉ E2E Testing# 使用 history 模式
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter, Unit, E2E
? Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n) Y# scss
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter, Unit, E2E
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass) 
❯ Sass/SCSS (with node-sass) Less Stylus   # esLint
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter, Unit, E2E
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with node-sass)
? Pick a linter / formatter config: ESLint with error prevention only ESLint + Airbnb config 
❯ ESLint + Standard config ESLint + Prettier # 保存时进行检测
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter, Unit, E2E
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with node-sass)
? Pick a linter / formatter config: Standard
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◉ Lint on save◯ Lint and fix on commit# 单元测试 mocha + chai? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter, Unit, E2E
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with node-sass)
? Pick a linter / formatter config: Standard
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)Lint on save
? Pick a unit testing solution: (Use arrow keys)
❯ Mocha + Chai Jest # 端到端测试? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter, Unit, E2E
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with node-sass)
? Pick a linter / formatter config: Standard
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)Lint on save
? Pick a unit testing solution: Mocha
? Pick a E2E testing solution: (Use arrow keys)
❯ Cypress (Chrome only) Nightwatch (WebDriver-based) # 单独的配置文件
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter, Unit, E2E
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with node-sass)
? Pick a linter / formatter config: Standard
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)Lint on save
? Pick a unit testing solution: Mocha
? Pick a E2E testing solution: Cypress
? Where do you prefer placing config for Babel, ESLint, etc.? 
❯ In dedicated config files In package.json # 不保存配置
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter, Unit, E2E
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with node-sass)
? Pick a linter / formatter config: Standard
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)Lint on save
? Pick a unit testing solution: Mocha
? Pick a E2E testing solution: Cypress
? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? (y/N) n# 开始创建项目
Vue CLI v4.1.2
✨  Creating project in /Users/heyi/File/Front-End/demo/vue-unit.
🗃  Initializing git repository...
⚙  Installing CLI plugins. This might take a while...···📄  Generating README.md...🎉  Successfully created project vue-cli4-unit-mocha-chai-nyc.
👉  Get started with the following commands:$ cd vue-cli4-unit-mocha-chai-nyc$ npm run serve

生成的项目目录结构:
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTM0MTEzLzE1OTA3MjA2NzIwMjUtZmU2OWEzYmMtNzNlNy00ZDJkLTg4NjQtNjc2OTM5NDhhNmEzLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=750&margin=[object Object]&name=image.png&originHeight=1500&originWidth=942&size=248456&status=done&style=none&width=471)

创建项目完成后,可以发现 cli4 会自动生成一个默认的单元测试例子 tests/unit/ example.spec.js,其内容如下:

import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'describe('HelloWorld.vue', () => {it('renders props.msg when passed', () => {const msg = 'new message'const wrapper = shallowMount(HelloWorld, {propsData: { msg }})expect(wrapper.text()).to.include(msg)})
})

接下来,进入项目并运行单元测试:

cd vue-cli4-unit-mocha-chai-nyc
npm run test:unit> vue-cli4-unit-mocha-chai-nyc@0.1.0 test:unit /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc
> vue-cli-service test:unitWEBPACK  Compiling...[===                      ] 10% (building)Download the Vue Devtools extension for a better development experience:
https://github.com/vuejs/vue-devtools
You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html[=========================] 98% (after emitting)DONE  Compiled successfully in 3019ms[=========================] 100% (completed)WEBPACK  Compiled successfully in 3019msMOCHA  Testing...HelloWorld.vue✓ renders props.msg when passed1 passing (26ms)MOCHA  Tests completed successfully

npm run test:unit 命令会自动读取 tests/unit/ 目录下的 *.spec.js 文件,来跑我们的单元测试。

可以发现,通过 vue-cli4 创建集成的单元测试项目,已经可以让我们做到零配置来写单元测试了。接下来就动手写一个单元测试试试。

2、动手写第一个单元测试


首先我们在 src/components/ 目录下创建文件 AppEmpty.vue,其内容如下:

<template><div>{{text}}</div>
</template><script>
export default {name: 'AppEmpty',props: {text: {type: String,default: 'no data'}},data () {return {}}
}
</script><style scoped lang="scss">
</style>


接着在 tests/unit/ 目录下创建 app-empty.spec.js 文件,并添加如下内容:

import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
import AppEmpty from '@/components/AppEmpty.vue'describe('AppEmpty.vue', () => {it('no props.text when passed', () => {const wrapper = shallowMount(AppEmpty)expect(wrapper.text()).to.include('no data')})it('renders props.text when passed', () => {const text = '暂无数据'const wrapper = shallowMount(HelloWorld, {propsData: { text }})expect(wrapper.text()).to.include(text)})
})


最后,再次运行 test:unit 命令:

npm run test:unit> vue-cli4-unit-mocha-chai-nyc@0.1.0 test:unit /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc
> vue-cli-service test:unitWEBPACK  Compiling...[=========================] 98% (after emitting)DONE  Compiled successfully in 1935ms[=========================] 100% (completed)WEBPACK  Compiled successfully in 1935msMOCHA  Testing...AppEmpty.vue✓ no props.text when passed✓ renders props.text when passedHelloWorld.vue✓ renders props.msg when passed3 passing (35ms)MOCHA  Tests completed successfully


可以看到,我们自己写的单元测试也跑了起来。

3、单元测试文件书写位置调整


如果所有的 *.spec.js 文件都写在 tests/unit/ 目录下会显得很凌乱,那么如果我们在 /unit 目录下再新建文件夹,会被读取到吗?答案是肯定的。


在 tests/unit/ 目录下新建一个 components 文件夹,把刚刚创建的 app-empty.spec.js 文件移进去。再次运行 test:unit 命令:

npm run test:unit> vue-cli4-unit-mocha-chai-nyc@0.1.0 test:unit /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc
> vue-cli-service test:unitWEBPACK  Compiling...[=========================] 98% (after emitting)DONE  Compiled successfully in 2035ms[=========================] 100% (completed)WEBPACK  Compiled successfully in 2035msMOCHA  Testing...HelloWorld.vue✓ renders props.msg when passedAppEmpty.vue✓ no props.text when passed✓ renders props.text when passed3 passing (57ms)MOCHA  Tests completed successfully


说明我们是可以自己建立文件夹进行整理我们的单元测试文件的。


如果我们的项目是一个去中心化的架构,我们可能希望我们的单元测试文件位于我们的组件旁边,而不是都写在 tests/unit/ 目录下。


如何实现呢?


在 tests/unit 目录下新建 index.spec.js 文件,其内容如下:

// require all src files that ends with .spec.js
const srcContext = require.context('../../src/', true, /\.spec.js$/)
srcContext.keys().forEach(srcContext)


就可以在 src/ 目录下任何位置写我们的单元测试文件了。


为了验证所言非虚,简单的验证一下。复制 tests/unit/components/app-empty.spec.js 文件,在 src/components/ 目录下粘贴,然后稍稍修改一下测试套件的文本:

- describe('AppEmpty.vue', () => {
+ describe('src/**/*.spec.js AppEmpty.vue', () => {


再次运行 test:unit 命令:

npm run test:unit> vue-cli4-unit-mocha-chai-nyc@0.1.0 test:unit /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc
> vue-cli-service test:unitWEBPACK  Compiling...[=========================] 98% (after emitting)DONE  Compiled successfully in 1968ms[=========================] 100% (completed)WEBPACK  Compiled successfully in 1968msMOCHA  Testing...HelloWorld.vue✓ renders props.msg when passedsrc/**/*.spec.js AppEmpty.vue✓ no props.text when passed✓ renders props.text when passedAppEmpty.vue✓ no props.text when passed✓ renders props.text when passed5 passing (38ms)MOCHA  Tests completed successfully


嗯,所言不虚。

4、使用 mochawesome 输出结果


到目前为止,我们的测试报告都是在命令行展示,那么如果我们想要把结果输出并展示在页面上如何做到呢?


首先在项目中安装 mochawesome:

npm install --save-dev mochawesome


然后在 package.json 中修改 test:unit 命令如下:

"test:unit": "vue-cli-service test:unit --reporter=mochawesome",


然后再次执行:

npm run test:unit                      > vue-cli4-unit-mocha-chai-nyc@0.1.0 test:unit /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc
> vue-cli-service test:unit --reporter=mochawesomeWEBPACK  Compiling...[===                      ] 10% (building)Download the Vue Devtools extension for a better development experience:
https://github.com/vuejs/vue-devtools
You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html[=========================] 98% (after emitting)WARNING  Compiled with 1 warningswarning  in ./src/components/app-empty.spec.jsModule Error (from ./node_modules/eslint-loader/index.js):/Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc/src/components/app-empty.spec.js5:1  error  'describe' is not defined  no-undef6:3  error  'it' is not defined        no-undef11:3  error  'it' is not defined        no-undef✖ 3 problems (3 errors, 0 warnings)@ ./src sync \.spec.js$@ ./tests/unit/index.spec.js@ ./node_modules/mochapack/lib/entry.js[=========================] 100% (completed)WEBPACK  Compiled with 1 warning(s)Warning in ./src/components/app-empty.spec.jsModule Error (from ./node_modules/eslint-loader/index.js):/Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc/src/components/app-empty.spec.js5:1  error  'describe' is not defined  no-undef6:3  error  'it' is not defined        no-undef11:3  error  'it' is not defined        no-undef✖ 3 problems (3 errors, 0 warnings)MOCHA  Testing...HelloWorld.vue✓ renders props.msg when passedsrc/**/*.spec.js AppEmpty.vue✓ no props.text when passed✓ renders props.text when passedAppEmpty.vue✓ no props.text when passed✓ renders props.text when passed5 passing (35ms)[mochawesome] Report JSON saved to /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc/mochawesome-report/mochawesome.json[mochawesome] Report HTML saved to /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc/mochawesome-report/mochawesome.html


非常醒目的警告提示首先被发现:

 WEBPACK  Compiled with 1 warning(s)Warning in ./src/components/app-empty.spec.jsModule Error (from ./node_modules/eslint-loader/index.js):/Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc/src/components/app-empty.spec.js5:1  error  'describe' is not defined  no-undef6:3  error  'it' is not defined        no-undef11:3  error  'it' is not defined        no-undef✖ 3 problems (3 errors, 0 warnings)


告诉我们在 ./src/components/app-empty.spec.js 文件中 describe、it 未定义,为什么上面我们执行的时候都没有这个警告,这次就有了呢?而且,为什么只有 src/ 目录下的单元测试文件报了,tests/unit/ 目录下的没有报呢?


答案在项目的 .eslintrc.js 配置文件里:

module.exports = {root: true,env: {node: true},extends: ['plugin:vue/essential','@vue/standard'],parserOptions: {parser: 'babel-eslint'},rules: {'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off','no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'},overrides: [{files: ['**/__tests__/*.{j,t}s?(x)','**/src/**/*.spec.{j,t}s?(x)'],env: {mocha: true}}]
}


在项目生成的 eslint 配置文件中,存在针对特定文件的配置,具体理解不细说,只需要简单的在其中加入 src/ 的配置即可:

···overrides: [{files: ['**/__tests__/*.{j,t}s?(x)',
+       '**/tests/unit/**/*.spec.{j,t}s?(x)','**/src/**/*.spec.{j,t}s?(x)'],env: {mocha: true}}]···


接下来我们再次运行 test:unit 命令,上面出现的告警将不复存在:

npm run test:unit> vue-cli4-unit-mocha-chai-nyc@0.1.0 test:unit /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc
> vue-cli-service test:unit --reporter=mochawesomeWEBPACK  Compiling...[=========================] 98% (after emitting)DONE  Compiled successfully in 1212ms[=========================] 100% (completed)WEBPACK  Compiled successfully in 1212msMOCHA  Testing...HelloWorld.vue✓ renders props.msg when passedsrc/**/*.spec.js AppEmpty.vue✓ no props.text when passed✓ renders props.text when passedAppEmpty.vue✓ no props.text when passed✓ renders props.text when passed5 passing (36ms)[mochawesome] Report JSON saved to /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc/mochawesome-report/mochawesome.json[mochawesome] Report HTML saved to /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc/mochawesome-report/mochawesome.htmlMOCHA  Tests completed successfully


处理了告警问题,回到最初的目的。


命令执行完成后,会在项目根目录下增加一个名为 mochawesome-report 的文件夹,里面就放着输出的单元测试报告。


我们在浏览器打开 mochawesome.html 可以看到如下页面:
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTM0MTEzLzE1OTA3MjA4MTg5ODUtYjFjNzM0NDMtNjk5OC00MWVlLTk4ZmItZWRiNzk5NTQzMTBmLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=397&margin=[object Object]&name=image.png&originHeight=794&originWidth=1576&size=114632&status=done&style=none&width=788)


单元测试写了,测试报告也有了,接下来就差扫描项目单元测试覆盖率了。

5、使用 nyc 扫描测试覆盖率


文档地址:https://istanbul.js.org/


项目地址:https://github.com/istanbuljs/nyc


首先,在项目中安装所需依赖:

npm i --save-dev babel-plugin-istanbul istanbul-instrumenter-loader nyc


接着在项目根目录下新建 nyc.config.js 文件,其内容如下:

// 探索istanbul/nyc代码覆盖工具的原理 https://zhuanlan.zhihu.com/p/88524418
module.exports = {'check-coverage': true,'per-file': true,'lines': 0,'statements': 0,'functions': 0,'branches': 0,'include': ['src/**/*.js','src/**/*.vue'],'exclude': ['src/abandon-ui/**','src/*.js','**/*.spec.js'],'reporter': ['lcov','text','text-summary'],'extension': ['.js','.vue'],'cache': true,'all': true
}


完成后,在项目根目录新建 vue.config.js, 其内容如下:

const path = require('path')
const testMode = process.env.NODE_ENV === 'test'module.exports = {lintOnSave: false,productionSourceMap: false,chainWebpack: config => {if (testMode) {config.merge({devtool: 'eval'})config.module.rule('istanbul').test(/\.(js|vue)$/).include.add(path.resolve(__dirname, '/src')).end().use('istanbul-instrumenter-loader').loader('istanbul-instrumenter-loader').options({ esModules: true }).before('babel-loader')}}
}


完成后,打开项目根目录下的 babel.config.js 文件,修改如下:

+ const testMode = process.env.NODE_ENV === 'test'
+module.exports = {
-   presets: ['@vue/cli-plugin-babel/preset']
+   presets: ['@vue/cli-plugin-babel/preset'],
+   plugins: testMode ? ['babel-plugin-istanbul'] : []}


最后,打开 package.json 文件,修改 test:unit 命令:

-    "test:unit": "vue-cli-service test:unit --reporter=mochawesome",
+    "test:unit": "nyc vue-cli-service test:unit --reporter=mochawesome",


再次执行新的 test:unit 命令:

npm run test:unit> vue-cli4-unit-mocha-chai-nyc@0.1.0 test:unit /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc
> nyc vue-cli-service test:unit --reporter=mochawesomeWEBPACK  Compiling...[===                      ] 10% (building)Download the Vue Devtools extension for a better development experience:
https://github.com/vuejs/vue-devtools
You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html[=========================] 98% (after emitting)DONE  Compiled successfully in 2210ms[=========================] 100% (completed)WEBPACK  Compiled successfully in 2210msMOCHA  Testing...HelloWorld.vue✓ renders props.msg when passed (41ms)src/**/*.spec.js AppEmpty.vue✓ no props.text when passed✓ renders props.text when passedAppEmpty.vue✓ no props.text when passed✓ renders props.text when passed5 passing (72ms)[mochawesome] Report JSON saved to /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc/mochawesome-report/mochawesome.json[mochawesome] Report HTML saved to /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-nyc/mochawesome-report/mochawesome.htmlMOCHA  Tests completed successfully-----------------|---------|----------|---------|---------|-------------------
File             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-----------------|---------|----------|---------|---------|-------------------
All files        |   16.67 |      100 |      50 |   16.67 |                   components      |     100 |      100 |     100 |     100 |                   AppEmpty.vue   |     100 |      100 |     100 |     100 |                   HelloWorld.vue |       0 |        0 |       0 |       0 |                   router          |       0 |      100 |       0 |       0 |                   index.js       |       0 |      100 |       0 |       0 | 5-23              store           |       0 |      100 |     100 |       0 |                   index.js       |       0 |      100 |     100 |       0 | 4                 
-----------------|---------|----------|---------|---------|-------------------=============================== Coverage summary ===============================
Statements   : 16.67% ( 1/6 )
Branches     : 100% ( 0/0 )
Functions    : 50% ( 1/2 )
Lines        : 16.67% ( 1/6 )
================================================================================


执行成功后会发现根目录下除了新增加的 mochawesome-report/ 目录,还多了 coverage/ 和 .nyc_output/ 目录,我们的覆盖率结果就输出在 coverage/ 目录下。


在浏览器打开 coverage/ 目录下的 index.html 文件会出现以下页面:
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTM0MTEzLzE1OTA3MjA4NTI4NzktMTAwMjkzM2UtNGNmYy00YjVlLTk5M2ItOTBlZDUxNDY1YWNiLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=161&margin=[object Object]&name=image.png&originHeight=322&originWidth=1612&size=65484&status=done&style=none&width=806)


单击页面上的 components 可以看到改目录下的详细 .vue 文件覆盖率情况:
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTM0MTEzLzE1OTA3MjA4NzA1MjEtZTQzNTY3YmYtYTRjNS00YTViLTk4ZGQtMTBkOWY3Mzk0MGIxLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=142&margin=[object Object]&name=image.png&originHeight=284&originWidth=1610&size=55320&status=done&style=none&width=805)
再次单击 AppEmpty.vue 可以看到文件文件内的覆盖情况:
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTM0MTEzLzE1OTA3MjA4ODc1MzQtYzg5MjFlNTktN2EyNS00OWE0LWE5Y2EtODg0OWYzNDE4MGRhLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=256&margin=[object Object]&name=image.png&originHeight=512&originWidth=1604&size=83621&status=done&style=none&width=802)
最后列出 package.json 文件,以做参考:

{"name": "vue-cli4-unit-mocha-chai-nyc","version": "0.1.0","private": true,"scripts": {"serve": "vue-cli-service serve","build": "vue-cli-service build","test:unit": "nyc vue-cli-service test:unit --reporter=mochawesome","test:e2e": "vue-cli-service test:e2e","lint": "vue-cli-service lint"},"dependencies": {"core-js": "^3.6.5","vue": "^2.6.11","vue-router": "^3.2.0","vuex": "^3.4.0"},"devDependencies": {"@vue/cli-plugin-babel": "^4.4.0","@vue/cli-plugin-e2e-cypress": "^4.4.0","@vue/cli-plugin-eslint": "^4.4.0","@vue/cli-plugin-router": "^4.4.0","@vue/cli-plugin-unit-mocha": "^4.4.0","@vue/cli-plugin-vuex": "^4.4.0","@vue/cli-service": "^4.4.0","@vue/eslint-config-standard": "^5.1.2","@vue/test-utils": "^1.0.3","babel-eslint": "^10.1.0","babel-plugin-istanbul": "^6.0.0","chai": "^4.1.2","eslint": "^6.7.2","eslint-plugin-import": "^2.20.2","eslint-plugin-node": "^11.1.0","eslint-plugin-promise": "^4.2.1","eslint-plugin-standard": "^4.0.0","eslint-plugin-vue": "^6.2.2","istanbul-instrumenter-loader": "^3.0.1","mochawesome": "^6.1.1","node-sass": "^4.12.0","nyc": "^15.0.1","sass-loader": "^8.0.2","vue-template-compiler": "^2.6.11"}
}

6、使用 karma 扫描测试覆盖率


扫描测试覆盖率的另一个方法是使用 karma。


官网:http://karma-runner.github.io/latest/index.html


在前面的 1-5 节部分,所有的内容都是在第 1 节建立的项目 vue-cli4-unit-mocha-chai-nyc 中依次完成的。在本节内容开始之前,需要按照第 1 节的内容,重新创建一个项目:vue-cli4-unit-mocha-chai-karma 。


首先,依旧是安装需要的依赖:

npm i --save-dev karma karma-mocha mocha karma-chai \
karma-webpack karma-chrome-launcher karma-sourcemap-loader karma-spec-reporter \
karma-coverage@1.1.2 babel-plugin-istanbul@5.1.4 cross-env


在项目根目录创建 karma.conf.js 文件,其内容如下:

const webpackConfig = require('@vue/cli-service/webpack.config.js')module.exports = function (config) {config.set({frameworks: ['mocha'],files: ['tests/**/*.spec.js'],preprocessors: {'**/*.spec.js': ['webpack', 'sourcemap']},webpack: webpackConfig,reporters: ['spec', 'coverage'],coverageReporter: {dir: './coverage',reporters: [{ type: 'lcov', subdir: '.' },{ type: 'text-summary' }]},autoWatch: true,browsers: ['ChromeHeadless']})
}


然后,修改 babel.config.js 文件:

module.exports = {presets: ['@vue/cli-plugin-babel/preset'],
+ env: {
+   test: {
+     plugins: ["istanbul"]
+ 	}
+ }
}


接着,修改 package.json 文件的 test:unit 命令为:

"test:unit": "cross-env NODE_ENV=test karma start --single-run",


关于这里使用 BABEL_ENV=test 还是 NODE_ENV=test,建议是 NODE_ENV=test

Karma can’t handle split chunks.

  • In @vue/cli-service v3, unless you explicitly set NODE_ENV to production, splitChunks won’t be turned on.
  • In @vue/cli-service v4, unless you explicitly set NODE_ENV to test, splitChunks will be turned on by default.

It is a good practice to always set NODE_ENV to test during unit testing because many of the packages in Node.js ecosystem follows this convention.

Actually, with NODE_ENV=test, you can skip BABEL_ENV=test because it will default to NODE_ENV.


最后,我们执行 test:unit 命令:

npm run test:unit                                    > vue-cli4-unit-mocha-chai-karma@0.1.0 test:unit /Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-karma
> cross-env NODE_ENV=test karma start --single-runDONE  Compiled successfully in 671msℹ 「wdm」: Hash: f44d39181b90d9235a4b
Version: webpack 4.43.0
Time: 671ms
Built at: 2020-05-29 09:55:03Asset       Size                   Chunks             Chunk Names
../../../../../../Users/heyi/File/Front-End/demo/_unit/vue-cli4-unit-mocha-chai-karma/dist/favicon.ico   4.19 KiB                           [emitted]  app.js   1.22 MiB                      app  [emitted]  appimg/logo.82b9c7a5.png   6.69 KiB                           [emitted]  index.html  889 bytes                           [emitted]  tests/unit/example.spec.js    3.1 MiB  tests/unit/example.spec  [emitted]  tests/unit/example.spec
Entrypoint app = app.js
Entrypoint tests/unit/example.spec = tests/unit/example.spec.js
[0] multi ./src/main.js 28 bytes {app}
[./node_modules/@babel/runtime/helpers/interopRequireDefault.js] 147 bytes {app} {tests/unit/example.spec} [built]
[./node_modules/@vue/test-utils/dist/vue-test-utils.js] 400 KiB {tests/unit/example.spec} [built]
[./node_modules/chai/index.js] 40 bytes {tests/unit/example.spec} [built]
[./node_modules/chai/lib/chai.js] 1.23 KiB {tests/unit/example.spec} [built]
[./node_modules/vue-loader/lib/runtime/componentNormalizer.js] 2.71 KiB {app} {tests/unit/example.spec} [built]
[./node_modules/vue-template-compiler/index.js] 865 bytes {tests/unit/example.spec} [built]
[./node_modules/vue/dist/vue.runtime.esm.js] 222 KiB {app} {tests/unit/example.spec} [built]
[./src/App.vue] 566 bytes {app} [built]
[./src/components/HelloWorld.vue] 599 bytes {app} {tests/unit/example.spec} [built]
[./src/components/HelloWorld.vue?vue&type=script&lang=js&] 576 bytes {app} {tests/unit/example.spec}
[./src/components/HelloWorld.vue?vue&type=template&id=469af010&scoped=true&] 427 bytes {app} {tests/unit/example.spec}
[./src/main.js] 2.38 KiB {app} [built]
[./src/router/index.js] 3.23 KiB {app} [built]
[./tests/unit/example.spec.js] 3.27 KiB {tests/unit/example.spec} [built]+ 160 hidden modules
Child html-webpack-plugin for "index.html":Asset     Size  Chunks  Chunk Namesindex.html  534 KiB       1  Entrypoint undefined = index.html[./node_modules/html-webpack-plugin/lib/loader.js!./public/index.html] 928 bytes {1} [built][./node_modules/lodash/lodash.js] 528 KiB {1} [built][./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 497 bytes {1} [built]
ℹ 「wdm」: Compiled successfully.
29 05 2020 09:55:03.205:INFO [karma-server]: Karma v5.0.9 server started at http://0.0.0.0:9876/
29 05 2020 09:55:03.207:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
29 05 2020 09:55:03.231:INFO [launcher]: Starting browser ChromeHeadless
29 05 2020 09:55:03.790:INFO [Chrome Headless 83.0.4103.61 (Mac OS 10.14.6)]: Connected on socket WTpGcR9Fum14KL6rAAAA with id 16752070HelloWorld.vue✓ renders props.msg when passedChrome Headless 83.0.4103.61 (Mac OS 10.14.6): Executed 1 of 1 SUCCESS (0.012 secs / 0.009 secs)
TOTAL: 1 SUCCESS=============================== Coverage summary ===============================
Statements   : 100% ( 6/6 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 3/3 )
Lines        : 100% ( 6/6 )
================================================================================


执行成功后会在项目根目录下生成 coverage/** 文件夹,放着输出的测试覆盖率,我们在浏览器打开 coverage/lcov-report/index.html 文件,其页面如下:
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTM0MTEzLzE1OTA3MjA5MTQ1NDMtMmQ0NGIwYjYtNWQ1Yy00ODExLTkwMmUtOGM1Nzc4NDg4Y2ZlLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=125&margin=[object Object]&name=image.png&originHeight=250&originWidth=1616&size=46326&status=done&style=none&width=808)
与使用 nyc 输出的页面一样,也可以单击列表的 src/components/ 查看该目录下的详细文件:
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTM0MTEzLzE1OTA3MjA5Mjg1MDUtYWFhOGYyMGEtOWUxNi00OWRkLWFjZDQtMjE3YTM3Y2UwNTI0LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=111&margin=[object Object]&name=image.png&originHeight=222&originWidth=1616&size=40327&status=done&style=none&width=808)


查看 HelloWorld.vue 文件详情:
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvMTM0MTEzLzE1OTA3MjA5NDIzNzAtMDk0Yjc1YTctYzZmNy00MGM5LTljMWItMmIzYjdkN2I2MmU4LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=236&margin=[object Object]&name=image.png&originHeight=472&originWidth=1610&size=74341&status=done&style=none&width=805)


由于在写这篇记录的时候,发现存在依赖(karma-coverage、babel-plugin-istanbul)不能直接安装最新版本,下面列出完整的 package.json 文件,以做参考:

{"name": "vue-cli4-unit-mocha-chai-karma","version": "0.1.0","private": true,"scripts": {"serve": "vue-cli-service serve","build": "vue-cli-service build","test:unit": "cross-env NODE_ENV=test karma start --single-run","test:e2e": "vue-cli-service test:e2e","lint": "vue-cli-service lint"},"dependencies": {"core-js": "^3.6.5","vue": "^2.6.11","vue-router": "^3.2.0","vuex": "^3.4.0"},"devDependencies": {"@vue/cli-plugin-babel": "^4.4.0","@vue/cli-plugin-e2e-cypress": "^4.4.0","@vue/cli-plugin-eslint": "^4.4.0","@vue/cli-plugin-router": "^4.4.0","@vue/cli-plugin-unit-mocha": "^4.4.0","@vue/cli-plugin-vuex": "^4.4.0","@vue/cli-service": "^4.4.0","@vue/eslint-config-standard": "^5.1.2","@vue/test-utils": "^1.0.3","babel-eslint": "^10.1.0","babel-plugin-istanbul": "^5.1.4","chai": "^4.1.2","cross-env": "^7.0.2","eslint": "^6.7.2","eslint-plugin-import": "^2.20.2","eslint-plugin-node": "^11.1.0","eslint-plugin-promise": "^4.2.1","eslint-plugin-standard": "^4.0.0","eslint-plugin-vue": "^6.2.2","karma": "^5.0.9","karma-chai": "^0.1.0","karma-chrome-launcher": "^3.1.0","karma-coverage": "^1.1.2","karma-mocha": "^2.0.1","karma-sourcemap-loader": "^0.3.7","karma-spec-reporter": "0.0.32","karma-webpack": "^4.0.2","mocha": "^7.2.0","node-sass": "^4.12.0","sass-loader": "^8.0.2","vue-template-compiler": "^2.6.11"}
}


使用 karma 其它常用依赖:

chai-spies karma-chai-spies \
sinon sinon-chai karma-sinon-chai
查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. linux基础操作之samba文件共享服务

    参考来源1 参考来源2 文章目录0 samba介绍1. linux-安装samba2. linux-配置sambawindows登录共享 0 samba介绍samba 是基于信息服务块(ServerMessage Block, SMB)协议的开源软件。SMB是一种Linux、UNIX系统上可用于共享文件和打印机等资源的协议,这种协议是基于Client\Server…...

    2024/4/24 8:56:21
  2. 检查字段是否包含字符串

    本文翻译自:Checking if a field contains a string Im looking for an operator, which allows me to check, if the value of a field contains a certain string. 我正在寻找一个运算符,它允许我检查一个字段的值是否包含某个字符串。 Something like: 就像是: db.users…...

    2024/5/9 0:27:35
  3. 每天学习一个设计模式(九):创建型之建造者模式

    目录一、基本概念二、通俗解释三、建造者模式详解1.造车的例子2.建造者模式的结构3.建造者模式的优点4.使用场景5.注意事项四、建造者模式的扩展和最佳实践建造者模式的扩展最佳实践一、基本概念建造者模式(Builder Pattern)也叫做生成器模式,其定义如下:Separate the cons…...

    2024/5/8 16:12:19
  4. 20周岁-生日记

    20周岁,生日记,不想被时间冲走的那些回忆这是真的20岁了,时间的加速度正在不断的侵蚀着我们,首先祝自己生日快乐。我的人生已经是过去了五分之一啦,的确很平凡,也很平淡,但是也很曲折,总觉得自己想要去留下点什么,那些指得怀念的事我想去记下来,现在很多近几年得很多…...

    2024/5/8 19:17:41
  5. 《新下级学》第一章

    第一章 最悠久、最广大、最没存在感的 “人猿相揖别。……人世难逢开口笑,上疆场彼此弯弓月。……” 这是毛主席《贺新郎•读史》中的片断。是的,人类从诞生那一刻起,就是社会动物。当千百万人通过各种关系形成组织时,下级就自动产生了。人类正是依靠巨大的组织能力,才能移…...

    2024/4/24 8:56:15
  6. 基于netty搭建websocket,实现消息的主动推送

    netty的核心架构官网给出的底层示意图:项目结构代码结构(简单的springboot + maven项目)pom文件(netty版本 - 4.1.43.Final)代码展示 WebSocketServer服务类package com.netty.websocket.netty;import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Chann…...

    2024/5/8 22:01:30
  7. 初入银联支付总结一

    初入银联支付先从sdk入手。不多说,直接开正文 中国银联支付1sdk准备开始其他报错:10报文格式错误[5500030] 原因总结 准备注册银联开发者账号1、进入中国银联支付官网 2、点击注册并登录 3、进入到首页->鼠标移到业务合作->全渠道->在线网关支付4、下面就有两个操作…...

    2024/5/8 18:56:21
  8. macOS Catalina 提示:“应用名称” 已损坏,无法打开的解决方法总结

    macOS Catalina 提示:“应用名称” 已损坏,无法打开的解决方法总结 现象 提示:“应用名称”已损坏,无法打开,您应该将它移到废纸篓。 提示:“应用名称”已损坏,无法打开,您应该推出磁盘映像。(在DMG中双击)1.允许“任何来源”下载的App运行 sudo spctl --master-disabl…...

    2024/5/8 20:26:05
  9. spring boot基础知识和ssm搭建

    spring aop 通过切点指定在哪些类哪些方法进行织入横切逻辑,通过增强描述横切逻辑的具体实现,通过切面把切点和增强 链接到一起 spring aop 默认用的事jdk 动态代理,如果代理类没有实现接口,则用cglib,如果代理类实现接口则用的事jdk动态代理 cglib 采用asm 技术操作字节码…...

    2024/5/9 0:38:31
  10. Qt之调用百度API

    近几年来,语音识别、图像识别等AI技术发展得如火如荼。国内外各大科技巨头积极布局(各大AI 开放平台一览),百度是其中比较优秀的一家。百度希望通过百度大脑来实现战略转型,从一家无恶不作的广告推送、流量变现公司转型为一个高大上的AI开放平台。本篇文章介绍了如何利用Q…...

    2024/4/19 10:09:23
  11. 618购物节促销大战打响!聊聊和电商们有关的网络安全

    “6.18”即将来袭,作为疫情之后首个大规模且系统的限时大促,今年的“6.18”被寄予厚望,被视为疫情下的回血之战。顾客们满怀期待,商家和平台们战战兢兢。每年的“购物节”总会出现个别人无法下单的情景,难道真的是手慢无吗?我们本期就围绕电商的网络安全展开,安安从众多…...

    2024/5/1 21:56:11
  12. 微信封杀wetool等辅助工具,私域流量还能怎么玩?

    5月26日,对于很多做社群运营的,应该是一个“不眠夜”,因为腾讯封杀了一大批使用微信外挂的个人号,最近凡是登录了辅助工具的微信账号都会被封。有用户反映,自己被封了100多个号。这意味着,这100多个号里数十万的微信客户都转瞬蒸发。 也有网友传出自称是企业微信产品经理…...

    2024/5/2 7:07:24
  13. carsim2016安装及问题解决

    安装前关闭杀毒软件和防火墙 安装过程参考河马软件园http://www.pc0359.cn/article/jiaocheng/96585.html。记住破解软件MSCLICS_SSQ.LIC的位置,后面要用。 安装后运行carsim2016会出现 问题解决: 1、打开carsim2016.prog/programs/HostID.exe 里面有几个电脑的物理地址,…...

    2024/5/1 22:09:19
  14. java 平假名片假名判断

    package test;/*** @author 李鹏涛* @date 2020年5月29日 上午10:27:34*/ public class StringPanDuan {public static void main(String[] args) {// 平假名String str = "ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねの…...

    2024/5/2 6:15:20
  15. 使用python和vb控制cst进行自动化仿真之(一):环境配置

    使用python和vb控制cst进行自动化仿真之(一):环境配置 做微波的童鞋会经常用到cst进行仿真。我有个朋友最近一个课题需要使用cst仿真大量数据,这些数据对应的一部分结构参数要求随机生成,这样就没办法使用扫参。cst自带了vb(visual basic)编程环境,可以使用vb脚本编程控制…...

    2024/5/2 6:32:50
  16. Linux安装Nginx(离线状态下)

    Linux安装Nginx(离线状态下) 很多客户的网络环境都是在局域网下,不能出外网,所以在部署的时候就会遇到很多各式各样的问题。本篇就是在无网环境下安装Nginx。 1. Nginx安装包下载 下载地址: http://nginx.org/download/ 因为windows下目前用的版本是V1.15.8,所以下载的Li…...

    2024/5/2 1:56:44
  17. 大数据工具:Zookeeper的安装宝典!

    之前介绍了Hbase本地单节点模式的安装,该模式资源占用少适合学习使用。但是在生产环境中为了保证数据的安全,普遍采用集群模式来运用Hbase。在集群模式下Hbase的数据存储在HDFS文件系统而非本地文件系统,还需配以zookeeper集群来提供协调一致性服务。我们先来安装zookeeper然…...

    2024/5/2 5:06:11
  18. CentOS7下载与图文安装

    一、CentOS7.4下载官网下载地址:http://vault.centos.org/1、进入CentOS下载官网,找到CentOS7.4版本2、在CentOS7.4版本页面中,找到isos/3、进入页面后,可以看到x86_644、在CentOS下载页面中,选择 CentOS-7-x86_64-DVD-1708.torrent进行下载5、下载完成之后,由于“CentOS…...

    2024/5/1 22:43:33
  19. 量化参数

    量化参数 编码我们一般采用就是两种思想,在空间域上采用帧内压缩,利用数据的空间相关性进行压缩,这种压缩思想实现基本就是图片的压缩算法。另外一种就是一种利用时域的数据相关性进行压缩,采用参考参考帧和预测帧之间的宏块计算残差在此基础上进行压缩。一般用“残差”Dn …...

    2024/4/24 8:56:09
  20. HttpURLConnection的基本使用

    记录一下HttpURLConnection的基本使用 package com.xuegu.max_library.util; import android.util.Log; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnect…...

    2024/5/2 3:56:15

最新文章

  1. 如何在 Ubuntu 12.04 VPS 上使用 MongoDB 创建分片集群

    简介 MongoDB 是一个 NoSQL 文档数据库系统&#xff0c;可以在水平方向上很好地扩展&#xff0c;并通过键值系统实现数据存储。作为 Web 应用程序和网站的热门选择&#xff0c;MongoDB 易于实现并可以通过编程方式访问。 MongoDB 通过一种称为“分片”的技术实现扩展。分片是将…...

    2024/5/9 10:21:06
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/5/7 10:36:02
  3. 深入浅出 -- 系统架构之微服务中Nacos的部署

    前面我们提到过&#xff0c;在微服务架构中&#xff0c;Nacos注册中心属于核心组件&#xff0c;通常我们会采用高性能独立服务器进行部署&#xff0c;下面我们一起来看看Nacos部署过程&#xff1a; 1、环境准备 因为Nacos是支持windows和Linux系统的&#xff0c;且服务器操作…...

    2024/5/5 1:21:32
  4. Redis精品案例解析:Redis实现持久化主要有两种方式

    Redis实现持久化主要有两种方式&#xff1a;RDB&#xff08;Redis DataBase&#xff09;和AOF&#xff08;Append Only File&#xff09;。这两种方式各有优缺点&#xff0c;适用于不同的使用场景。 1. RDB持久化 RDB持久化是通过创建一个二进制的dump文件来保存当前Redis数据…...

    2024/5/7 16:47:17
  5. 【外汇早评】美通胀数据走低,美元调整

    原标题:【外汇早评】美通胀数据走低,美元调整昨日美国方面公布了新一期的核心PCE物价指数数据,同比增长1.6%,低于前值和预期值的1.7%,距离美联储的通胀目标2%继续走低,通胀压力较低,且此前美国一季度GDP初值中的消费部分下滑明显,因此市场对美联储后续更可能降息的政策…...

    2024/5/8 6:01:22
  6. 【原油贵金属周评】原油多头拥挤,价格调整

    原标题:【原油贵金属周评】原油多头拥挤,价格调整本周国际劳动节,我们喜迎四天假期,但是整个金融市场确实流动性充沛,大事频发,各个商品波动剧烈。美国方面,在本周四凌晨公布5月份的利率决议和新闻发布会,维持联邦基金利率在2.25%-2.50%不变,符合市场预期。同时美联储…...

    2024/5/7 9:45:25
  7. 【外汇周评】靓丽非农不及疲软通胀影响

    原标题:【外汇周评】靓丽非农不及疲软通胀影响在刚结束的周五,美国方面公布了新一期的非农就业数据,大幅好于前值和预期,新增就业重新回到20万以上。具体数据: 美国4月非农就业人口变动 26.3万人,预期 19万人,前值 19.6万人。 美国4月失业率 3.6%,预期 3.8%,前值 3…...

    2024/5/4 23:54:56
  8. 【原油贵金属早评】库存继续增加,油价收跌

    原标题:【原油贵金属早评】库存继续增加,油价收跌周三清晨公布美国当周API原油库存数据,上周原油库存增加281万桶至4.692亿桶,增幅超过预期的74.4万桶。且有消息人士称,沙特阿美据悉将于6月向亚洲炼油厂额外出售更多原油,印度炼油商预计将每日获得至多20万桶的额外原油供…...

    2024/5/9 4:20:59
  9. 【外汇早评】日本央行会议纪要不改日元强势

    原标题:【外汇早评】日本央行会议纪要不改日元强势近两日日元大幅走强与近期市场风险情绪上升,避险资金回流日元有关,也与前一段时间的美日贸易谈判给日本缓冲期,日本方面对汇率问题也避免继续贬值有关。虽然今日早间日本央行公布的利率会议纪要仍然是支持宽松政策,但这符…...

    2024/5/4 23:54:56
  10. 【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响

    原标题:【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响近日伊朗局势升温,导致市场担忧影响原油供给,油价试图反弹。此时OPEC表态稳定市场。据消息人士透露,沙特6月石油出口料将低于700万桶/日,沙特已经收到石油消费国提出的6月份扩大出口的“适度要求”,沙特将满…...

    2024/5/4 23:55:05
  11. 【外汇早评】美欲与伊朗重谈协议

    原标题:【外汇早评】美欲与伊朗重谈协议美国对伊朗的制裁遭到伊朗的抗议,昨日伊朗方面提出将部分退出伊核协议。而此行为又遭到欧洲方面对伊朗的谴责和警告,伊朗外长昨日回应称,欧洲国家履行它们的义务,伊核协议就能保证存续。据传闻伊朗的导弹已经对准了以色列和美国的航…...

    2024/5/4 23:54:56
  12. 【原油贵金属早评】波动率飙升,市场情绪动荡

    原标题:【原油贵金属早评】波动率飙升,市场情绪动荡因中美贸易谈判不安情绪影响,金融市场各资产品种出现明显的波动。随着美国与中方开启第十一轮谈判之际,美国按照既定计划向中国2000亿商品征收25%的关税,市场情绪有所平复,已经开始接受这一事实。虽然波动率-恐慌指数VI…...

    2024/5/7 11:36:39
  13. 【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试

    原标题:【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试美国和伊朗的局势继续升温,市场风险情绪上升,避险黄金有向上突破阻力的迹象。原油方面稍显平稳,近期美国和OPEC加大供给及市场需求回落的影响,伊朗局势并未推升油价走强。近期中美贸易谈判摩擦再度升级,美国对中…...

    2024/5/4 23:54:56
  14. 【原油贵金属早评】市场情绪继续恶化,黄金上破

    原标题:【原油贵金属早评】市场情绪继续恶化,黄金上破周初中国针对于美国加征关税的进行的反制措施引发市场情绪的大幅波动,人民币汇率出现大幅的贬值动能,金融市场受到非常明显的冲击。尤其是波动率起来之后,对于股市的表现尤其不安。隔夜美国股市出现明显的下行走势,这…...

    2024/5/6 1:40:42
  15. 【外汇早评】美伊僵持,风险情绪继续升温

    原标题:【外汇早评】美伊僵持,风险情绪继续升温昨日沙特两艘油轮再次发生爆炸事件,导致波斯湾局势进一步恶化,市场担忧美伊可能会出现摩擦生火,避险品种获得支撑,黄金和日元大幅走强。美指受中美贸易问题影响而在低位震荡。继5月12日,四艘商船在阿联酋领海附近的阿曼湾、…...

    2024/5/4 23:54:56
  16. 【原油贵金属早评】贸易冲突导致需求低迷,油价弱势

    原标题:【原油贵金属早评】贸易冲突导致需求低迷,油价弱势近日虽然伊朗局势升温,中东地区几起油船被袭击事件影响,但油价并未走高,而是出于调整结构中。由于市场预期局势失控的可能性较低,而中美贸易问题导致的全球经济衰退风险更大,需求会持续低迷,因此油价调整压力较…...

    2024/5/8 20:48:49
  17. 氧生福地 玩美北湖(上)——为时光守候两千年

    原标题:氧生福地 玩美北湖(上)——为时光守候两千年一次说走就走的旅行,只有一张高铁票的距离~ 所以,湖南郴州,我来了~ 从广州南站出发,一个半小时就到达郴州西站了。在动车上,同时改票的南风兄和我居然被分到了一个车厢,所以一路非常愉快地聊了过来。 挺好,最起…...

    2024/5/7 9:26:26
  18. 氧生福地 玩美北湖(中)——永春梯田里的美与鲜

    原标题:氧生福地 玩美北湖(中)——永春梯田里的美与鲜一觉醒来,因为大家太爱“美”照,在柳毅山庄去寻找龙女而错过了早餐时间。近十点,向导坏坏还是带着饥肠辘辘的我们去吃郴州最富有盛名的“鱼头粉”。说这是“十二分推荐”,到郴州必吃的美食之一。 哇塞!那个味美香甜…...

    2024/5/4 23:54:56
  19. 氧生福地 玩美北湖(下)——奔跑吧骚年!

    原标题:氧生福地 玩美北湖(下)——奔跑吧骚年!让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 啊……啊……啊 两…...

    2024/5/8 19:33:07
  20. 扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!

    原标题:扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!扒开伪装医用面膜,翻六倍价格宰客!当行业里的某一品项火爆了,就会有很多商家蹭热度,装逼忽悠,最近火爆朋友圈的医用面膜,被沾上了污点,到底怎么回事呢? “比普通面膜安全、效果好!痘痘、痘印、敏感肌都能用…...

    2024/5/5 8:13:33
  21. 「发现」铁皮石斛仙草之神奇功效用于医用面膜

    原标题:「发现」铁皮石斛仙草之神奇功效用于医用面膜丽彦妆铁皮石斛医用面膜|石斛多糖无菌修护补水贴19大优势: 1、铁皮石斛:自唐宋以来,一直被列为皇室贡品,铁皮石斛生于海拔1600米的悬崖峭壁之上,繁殖力差,产量极低,所以古代仅供皇室、贵族享用 2、铁皮石斛自古民间…...

    2024/5/8 20:38:49
  22. 丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者

    原标题:丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者【公司简介】 广州华彬企业隶属香港华彬集团有限公司,专注美业21年,其旗下品牌: 「圣茵美」私密荷尔蒙抗衰,产后修复 「圣仪轩」私密荷尔蒙抗衰,产后修复 「花茵莳」私密荷尔蒙抗衰,产后修复 「丽彦妆」专注医学护…...

    2024/5/4 23:54:58
  23. 广州械字号面膜生产厂家OEM/ODM4项须知!

    原标题:广州械字号面膜生产厂家OEM/ODM4项须知!广州械字号面膜生产厂家OEM/ODM流程及注意事项解读: 械字号医用面膜,其实在我国并没有严格的定义,通常我们说的医美面膜指的应该是一种「医用敷料」,也就是说,医用面膜其实算作「医疗器械」的一种,又称「医用冷敷贴」。 …...

    2024/5/9 7:32:17
  24. 械字号医用眼膜缓解用眼过度到底有无作用?

    原标题:械字号医用眼膜缓解用眼过度到底有无作用?医用眼膜/械字号眼膜/医用冷敷眼贴 凝胶层为亲水高分子材料,含70%以上的水分。体表皮肤温度传导到本产品的凝胶层,热量被凝胶内水分子吸收,通过水分的蒸发带走大量的热量,可迅速地降低体表皮肤局部温度,减轻局部皮肤的灼…...

    2024/5/4 23:54:56
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57