关于sap:SAP-Spartacus-Definition-of-Done

43次阅读

共计 2757 个字符,预计需要花费 7 分钟才能阅读完成。

SAP Spartacus Definition of Done)

Coding guidelines

Spartacus 团队采纳了以下一组规定来放弃 Spartacus 代码的可读性和可维护性。作为贡献者,咱们要求您恪守这些规定(即便您发现它们在某处被违反)。当文件始终不遵循这些规定,并且恪守这些规定会使代码变得更糟时,请遵循本地格调。

TL;DR

您能够运行位于我的项目根目录的 build.sh 脚本。它将运行上面提到的大部分查看或规定,例如 linting 和 prettier 查看、运行单元测试和端到端测试等。

Linting

Linting

We use TSLint to analyze and improve our typescript code.

You can run the following command to lint your code:

yarn lint

We also encourage you to use the TSLint plugin in VS Code.

Coding Format

咱们应用 Prettier 来格式化咱们的代码(并使其更丑陋)。

要查看是否所有文件都通过丑化,请运行以下命令:

yarn prettier

要格式化和丑化您的代码库,请运行以下命令:

yarn prettier:fix

咱们还激励应用 Prettier VS Code 插件。无关更多信息,请参阅 Spartacus 的开发工具。

SCSS is Preprocessed (node-sass)

We use Sass for all of our CSS, which then is converted to CSS using node-sass.

Use the following command to preprocess the Sass in projects/storefrontstyles

yarn sass

单元测试

Spartacus 代码须要单元测试。确保新性能或谬误具备单元测试,并确保它们通过。

运行以下命令以运行库的单元测试:

yarn test [project]

yarn test storefrontlib

当您运行测试时,Chrome 会关上,您能够看到测试的进度以及详细信息,包含测试是否通过。

单元测试代码覆盖率

Please ensure that unit test coverage is >= 80% for everything, and >=60% for branches.

To get the test coverage report, run the following commands:

yarn test [project] –code-coverage

yarn test storefrontlib –code-coverage

Alternatively, you can run the following commands:

yarn test [project] –code-coverage

yarn test:core:lib

The coverage report can be found in ./coverage/index.html.

端到端测试

Spartacus 中的所有新性能都须要应用 Cypress 编写的端到端测试。请确保新性能具备端到端测试,并且它们正在通过。

在实用的状况下,编写端到端测试以确保您的新性能或更新性能十拿九稳。如果编写端到端测试有意义,那么最低要求是编写根本的 UI 端到端测试。您还能够思考应用用户流编写 UI 端到端测试,但这是可选的。

必须审查、更新或重用所有新编写的端到端测试。他们还应该遵循端到端测试指南。

运行以下命令以执行端到端测试:

  • yarn e2e:cy:run # smoke tests
  • yarn e2e:cy:run:mobile # mobile tests
  • yarn e2e:cy:run:regression # regression tests

留神:在运行端到端测试之前,请确保在 projects/storefrontapp-e2e-cypress 中装置依赖项,并确保应用程序正在运行。

端到端测试的指标是确保您的性能失常工作。例如,如果您要实现一个带有两个按钮(例如登录和勾销按钮)的简略登录屏幕,您能够编写以下测试:

  • 应用无效凭据登录
  • 尝试应用有效凭据登录
  • 填写输出字段,而后单击勾销按钮。

留神:E2E 测试目前只能在 SAP 内运行。咱们正在致力向贡献者公开 E2E 测试。

浏览器兼容性

要使新性能满足实现的定义,至多,必须胜利对新性能进行手动、高兴门路测试,并且在以下浏览器的最新次要版本中没有显著的布局问题:

  • Chrome
  • Firefox
  • Safari
  • Edge

The Library Builds Without Errors

Run the following command to ensure the libraries build without errors:

yarn build:libs

Shell 启动时没有谬误

运行以下命令以确保 shell 店面应用程序启动时没有谬误:

yarn start

运行命令后,您应该看到以下内容:

  • webpack 终端输入没有谬误
  • 显示主页时,Chrome 中的 JS 控制台没有谬误。

Shell App 中的新性能 Happy Path

运行该性能的冒烟测试,部署在 shell 应用程序的库中。

而后确定新性能是否须要在 shell 应用程序或配置文件中进行更改。

一些文件和概念存在于 shell 应用程序自身中。问问本人新代码是否须要更新 shell 应用程序或配置文件。

以下更改可能是候选对象:

  • 增加或更改 route
  • 增加或更改模块(更改门路或名称)
  • 增加组件
  • 增加模块
  • 扭转配置机制的工作形式。

验证生产构建工作

运行以下命令以验证生产构建是否无效,尤其是提前 (AOT) 编译器:

yarn build:libs

yarn start

以下是生产构建可能失败的一些起因:

  • 因为 AOT,咱们必须显式指定一些类型,例如函数返回类型。只管 TypeScript 不须要它们,但它能够推断它们。

应用 index.ts 文件(即桶文件)时要小心。运行生产构建时,您可能会在 node/webpack 控制台中看到以下谬误:

ERROR in : Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using ‘barrel’ index.ts files.

这通常是由导入语句引起的,例如:

import * as fromServices from ‘../../services’。

相同,您应该专门导入每个类,如以下示例所示:


import {OccCmsService} from "../../services/occ-cms.service";

import {DefaultPageService} from "../../services/default-page.service";

正文完
 0