Browse Source

feat: 开源准备:单元测试/端对端测试/CI/文档/代码规范

master
lenghui.yp 4 years ago
parent
commit
0bc7e361df
  1. 47
      .circleci/config.yml
  2. 14
      .eslintrc.js
  3. 5
      __tests__/core/src/api/index.test.js
  4. 5
      __tests__/core/src/common/baseCell.test.js
  5. 5
      __tests__/core/src/common/const.test.js
  6. 5
      __tests__/core/src/common/previewCell.test.js
  7. 5
      __tests__/core/src/common/shortcuts.test.js
  8. 5
      __tests__/core/src/components/colorPicker.test.js
  9. 5
      __tests__/core/src/components/miniMapSimpleNode.test.js
  10. 5
      __tests__/core/src/components/xIcon.test.js
  11. 5
      __tests__/core/src/mods/flowChart.test.js
  12. 5
      __tests__/core/src/mods/header.test.jsx
  13. 5
      __tests__/core/src/mods/layout.test.js
  14. 5
      __tests__/core/src/mods/settingBar.test.js
  15. 5
      __tests__/core/src/mods/sideBar.test.js
  16. 5
      __tests__/core/src/mods/toolBar.test.js
  17. 5
      __tests__/core/src/utils/flowChartUtils.test.js
  18. 5
      __tests__/core/src/utils/index.test.js
  19. 11
      config/cli.jest.config.js
  20. 11
      config/core.jest.config.js
  21. 11
      config/editor.jest.config.js
  22. 11
      config/plugin.jest.config.js
  23. 5
      cypress/fixtures/example.json
  24. 28
      cypress/integration/examples/actions.spec.js
  25. 28
      cypress/integration/examples/dataSave.spec.js
  26. 21
      cypress/plugins/index.js
  27. 25
      cypress/support/commands.js
  28. 20
      cypress/support/index.js
  29. 8
      docs/api/CONTRIBUTING.md
  30. 1
      docs/api/ctx.md
  31. 1
      docs/api/data.md
  32. 1
      docs/api/edge.md
  33. 1
      docs/api/group.md
  34. 1
      docs/api/layout.md
  35. 1
      docs/api/module.md
  36. 1
      docs/api/node.md
  37. 1
      docs/api/schema.md
  38. 1
      docs/config/index.md
  39. 1
      docs/docs/index.md
  40. 1
      docs/guide/index.md
  41. 1
      docs/plugins/index.md
  42. 22
      package.json
  43. 1
      tsconfig.json

47
.circleci/config.yml

@ -0,0 +1,47 @@
version: 2
jobs:
build:
docker:
- image: circleci/node:latest
working_directory: ~/repo
steps:
- checkout
# 恢复缓存
- restore_cache:
key: node-modules-{{ checksum "package.json" }}
# 安装依赖
- run:
name: Install Dependencies
command: yarn --frozen-lockfile
# 格式化代码
- run:
name: Format Code
command: yarn lint
# 写缓存
- save_cache:
key: node-modules-{{ checksum "package-lock.json" }}
paths:
- ./node_modules
- ~/.cache/yarn
# 代码打包构建
# - run:
# name: Run Build
# command: yarn build
# 跑单元测试代码
- run:
name: Run Tests
command: yarn test
no_output_timeout: 300m
# 跑端对端测试代码
- run:
name: Run E2E Tests
command: yarn e2e
no_output_timeout: 300m
# 集成文档
- run:
name: Generate Doc
command: yarn doc
no_output_timeout: 300m

14
.eslintrc.js

@ -1,7 +1,6 @@
module.exports = { module.exports = {
extends: [ extends: [
'airbnb', 'standard',
'airbnb/hooks',
'plugin:import/typescript', 'plugin:import/typescript',
'plugin:unicorn/recommended', 'plugin:unicorn/recommended',
'prettier', 'prettier',
@ -18,9 +17,13 @@ module.exports = {
// 修复 tsx 文件引用 tsx 文件报错的问题 // 修复 tsx 文件引用 tsx 文件报错的问题
'react/jsx-filename-extension': ['error', { extensions: ['.ts', '.tsx'] }], 'react/jsx-filename-extension': ['error', { extensions: ['.ts', '.tsx'] }],
'unicorn/prevent-abbreviations': 'off', 'unicorn/prevent-abbreviations': 'off',
"semi": [2, "always"],//语句强制分号结尾
"semi-spacing": [0, { "before": false, "after": true }],//分号前后空格
"no-var": 0,//禁用var,用let和const代替
"no-use-before-define": 2,//未定义前不能使用
"no-unused-expressions": 2,//禁止无用的表达式
}, },
overrides: [ overrides: [{
{
files: ['*.ts', '*.tsx'], files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser', parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'], plugins: ['@typescript-eslint'],
@ -42,6 +45,5 @@ module.exports = {
}, },
], ],
}, },
}, },],
],
}; };

5
__tests__/core/src/api/index.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/common/baseCell.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/common/const.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/common/previewCell.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/common/shortcuts.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/components/colorPicker.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/components/miniMapSimpleNode.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/components/xIcon.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/mods/flowChart.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/mods/header.test.jsx

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/mods/layout.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/mods/settingBar.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/mods/sideBar.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/mods/toolBar.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/utils/flowChartUtils.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

5
__tests__/core/src/utils/index.test.js

@ -0,0 +1,5 @@
describe('test', () => {
it('test suite', () => {
})
})

11
config/cli.jest.config.js

@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
testEnvironment: "node",
rootDir: '../',
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
testMatch: [
"<rootDir>/__tests__/cli/src/**/*.(spec|test).[jt]s?(x)"
]
};

11
config/core.jest.config.js

@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
testEnvironment: "node",
rootDir: '../',
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
testMatch: [
"<rootDir>/__tests__/core/src/**/*.(spec|test).[jt]s?(x)"
]
};

11
config/editor.jest.config.js

@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
testEnvironment: "node",
rootDir: '../',
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
testMatch: [
"<rootDir>/__tests__/json-schema-editor/src/**/*.(spec|test).[jt]s?(x)"
]
};

11
config/plugin.jest.config.js

@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
testEnvironment: "node",
rootDir: '../',
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
testMatch: [
"<rootDir>/__tests__/plugin-store/src/**/*.(spec|test).[jt]s?(x)"
]
};

5
cypress/fixtures/example.json

@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

28
cypress/integration/examples/actions.spec.js

@ -0,0 +1,28 @@
/// <reference types="cypress" />
context('Actions', () => {
// 1. 打开http://localhost:8001/
beforeEach(() => {
cy.visit('http://localhost:8001/')
})
// 2. 测试是否能将左侧的组件拖动到画布中
it('the components on the left can be dragged into the canvas', () => {
})
// 3. 测试是否可修改节点的显示名称、逻辑触发名称、代码、投放配置schema、依赖
it('you can modify the display name, logical trigger name, code, delivery configuration schema, and dependencies of the node', () => {
})
// 4. 测试能够run起来一个最小流程(写好代码)
it('A minimal process can be run', () => {
})
// 5. 测试更改节点位置,输出结果不变
it('ensure that the node position is changed and the output result remains unchanged', () => {
})
})

28
cypress/integration/examples/dataSave.spec.js

@ -0,0 +1,28 @@
/// <reference types="cypress" />
context('Actions', () => {
// 1. 打开http://localhost:8001/
beforeEach(() => {
cy.visit('http://localhost:8001/')
})
// 2. 测试是否能将左侧的组件拖动到画布中
it('the components on the left can be dragged into the canvas', () => {
})
// 3. 测试是否可修改节点的显示名称、逻辑触发名称、代码、投放配置schema、依赖
it('you can modify the display name, logical trigger name, code, delivery configuration schema, and dependencies of the node', () => {
})
// 4. 测试能够run起来一个最小流程(写好代码)
it('A minimal process can be run', () => {
})
// 5. 测试更改节点位置,输出结果不变
it('ensure that the node position is changed and the output result remains unchanged', () => {
})
})

21
cypress/plugins/index.js

@ -0,0 +1,21 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}

25
cypress/support/commands.js

@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

20
cypress/support/index.js

@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')

8
docs/api/CONTRIBUTING.md

@ -0,0 +1,8 @@
# 为iMove做贡献
* 请先fork一份到自己的项目下,不要直接在仓库下建分支。
* commit信息要以`[组件名]:描述信息`的形式填写,例如`[canvas]:fix xxx bug`。
* 如果您已经修复了错误或者添加了应测试的代码,请添加测试!
* 确保提交PR之前请先rebase,保持commit记录的整洁性。
* 确保PR是提交到`dev`分支,而不是`master`分支。
* 如果修复的是bug,请在PR中给出描述信息。

1
docs/api/ctx.md

@ -0,0 +1 @@
# 上下文(ctx)

1
docs/api/data.md

@ -0,0 +1 @@
# 数据读写(data)

1
docs/api/edge.md

@ -0,0 +1 @@
# 边(edge)

1
docs/api/group.md

@ -0,0 +1 @@
# 节点组(group)

1
docs/api/layout.md

@ -0,0 +1 @@
# 布局(layout)

1
docs/api/module.md

@ -0,0 +1 @@
# 逻辑元件(module)

1
docs/api/node.md

@ -0,0 +1 @@
# 节点(node)

1
docs/api/schema.md

@ -0,0 +1 @@
# 流程图(schema)

1
docs/config/index.md

@ -0,0 +1 @@
## 配置文档

1
docs/docs/index.md

@ -0,0 +1 @@
## 使用文档

1
docs/guide/index.md

@ -0,0 +1 @@
## 问题指引

1
docs/plugins/index.md

@ -0,0 +1 @@
## 插件文档

22
package.json

@ -4,7 +4,18 @@
"scripts": { "scripts": {
"lint-eslint": "eslint --cache --ext .js,.jsx,.ts,.tsx ./packages/**/src", "lint-eslint": "eslint --cache --ext .js,.jsx,.ts,.tsx ./packages/**/src",
"check-types": "tsc --noEmit", "check-types": "tsc --noEmit",
"lint": "npm run lint-eslint & npm run check-types" "lint": "npm run lint-eslint & npm run check-types",
"test": "jest --coverage",
"e2e": "cypress open",
"doc": "dumi dev"
},
"jest": {
"projects": [
"config/cli.jest.config.js",
"config/core.jest.config.js",
"config/editor.jest.config.js",
"config/plugin.jest.config.js"
]
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.9.0", "@babel/core": "^7.9.0",
@ -23,6 +34,9 @@
"@svgr/rollup": "^5.3.1", "@svgr/rollup": "^5.3.1",
"@typescript-eslint/eslint-plugin": "^2.29.0", "@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0", "@typescript-eslint/parser": "^2.29.0",
"cypress": "^6.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
"eslint": "^6.8.0", "eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0", "eslint-config-airbnb": "^18.1.0",
"eslint-config-prettier": "^6.10.1", "eslint-config-prettier": "^6.10.1",
@ -32,17 +46,23 @@
"eslint-plugin-react": "^7.19.0", "eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^3.0.0", "eslint-plugin-react-hooks": "^3.0.0",
"eslint-plugin-unicorn": "^18.0.1", "eslint-plugin-unicorn": "^18.0.1",
"jest": "^26.6.3",
"jest-environment-jsdom-fourteen": "^1.0.1",
"lerna": "^3.20.2", "lerna": "^3.20.2",
"prettier": "^2.0.4", "prettier": "^2.0.4",
"react-app-polyfill": "^2.0.0",
"rollup": "^2.6.1", "rollup": "^2.6.1",
"rollup-plugin-babel": "^4.4.0", "rollup-plugin-babel": "^4.4.0",
"rollup-plugin-size-snapshot": "^0.11.0", "rollup-plugin-size-snapshot": "^0.11.0",
"snazzy": "^9.0.0",
"standard": "^16.0.3",
"typescript": "^3.8.3" "typescript": "^3.8.3"
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.9.2", "@babel/runtime": "^7.9.2",
"@babel/runtime-corejs3": "^7.9.2", "@babel/runtime-corejs3": "^7.9.2",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"dumi": "^1.0.37",
"ora": "^4.0.3" "ora": "^4.0.3"
} }
} }

1
tsconfig.json

@ -1,6 +1,5 @@
{ {
"compilerOptions": { "compilerOptions": {
/* Basic Options */
"target": "esnext", "target": "esnext",
"module": "commonjs", "module": "commonjs",
"allowJs": false, "allowJs": false,

Loading…
Cancel
Save