Skip to content

Commit

Permalink
feat: 对默认模版增加测试工具的配置 (#14068)
Browse files Browse the repository at this point in the history
* feat: 对默认模版增加测试工具的配置

---------

Co-authored-by: zhuminghui2 <[email protected]>
Co-authored-by: xuanzebin <[email protected]>
  • Loading branch information
3 people authored and bigmeow committed Jun 26, 2023
1 parent d8510d1 commit 67d6c38
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 260 deletions.
2 changes: 1 addition & 1 deletion packages/taro-cli/src/create/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class Creator {
if (!path.isAbsolute(filepath)) {
filepath = path.join(this.destinationRoot(), filepath)
}
if (filepath.endsWith('package.json.tmpl')) {
if (filepath.endsWith('.tmpl')) {
filepath = filepath.replace('.tmpl', '')
}
const basename = path.basename(filepath)
Expand Down
12 changes: 12 additions & 0 deletions packages/taro-cli/templates/default/__tests__/index.test.js.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if (['react', 'preact'].includes(framework)) {%>import TestUtils from '@tarojs/test-utils-react'<%}%><% if (framework === 'vue3') {%>import TestUtils from '@tarojs/test-utils-vue3'<%}%><% if (framework === 'vue') {%>import TestUtils from '@tarojs/test-utils-vue'<%}%>

describe('Testing', () => {

test('Test', async () => {
const testUtils = new TestUtils()
await testUtils.createApp()
await testUtils.PageLifecycle.onShow('pages/index/index')
expect(testUtils.html()).toMatchSnapshot()
})

})
6 changes: 6 additions & 0 deletions packages/taro-cli/templates/default/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if (['react', 'preact'].includes(framework)) {%>const defineJestConfig = require('@tarojs/test-utils-react/dist/jest.js').default<%}%><% if (framework === 'vue3') {%>const defineJestConfig = require('@tarojs/test-utils-vue3/dist/jest.js').default<%}%><% if (framework === 'vue') {%>const defineJestConfig = require('@tarojs/test-utils-vue/dist/jest.js').default<%}%>

module.exports = defineJestConfig({
testEnvironment: 'jsdom',
testMatch: ['<rootDir>/__tests__/?(*.)+(spec|test).[jt]s?(x)']
})
11 changes: 9 additions & 2 deletions packages/taro-cli/templates/default/package.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"dev:rn": "npm run build:rn -- --watch",
"dev:qq": "npm run build:qq -- --watch",
"dev:jd": "npm run build:jd -- --watch",
"dev:quickapp": "npm run build:quickapp -- --watch"
"dev:quickapp": "npm run build:quickapp -- --watch",
"test": "jest"
},
"browserslist": [
"last 3 versions",
Expand Down Expand Up @@ -63,6 +64,7 @@
"@babel/core": "^7.8.0",
"@tarojs/cli": "<%= version %>",
"@types/webpack-env": "^1.13.6",<% if (['react', 'preact'].includes(framework)) {%>
"@tarojs/test-utils-react": "^0.1.1",
"@types/react": "^18.0.0",<%}%><% if (compiler === 'webpack4') {%>
"@tarojs/mini-runner": "<%= version %>",
"@tarojs/webpack-runner": "<%= version %>",
Expand All @@ -73,9 +75,11 @@
"babel-preset-taro": "<%= version %>",<% if (['vue', 'vue3'].includes(framework)) {%>
"css-loader": "3.4.2",
"style-loader": "1.3.0",<%}%><% if (framework === 'vue') {%>
"@tarojs/test-utils-vue": "^0.1.1",
"@vue/babel-preset-jsx": "^1.2.4",
"vue-loader": "^15.9.2",
"eslint-plugin-vue": "^8.x",<%}%><% if (framework === 'vue3') {%>
"@tarojs/test-utils-vue3": "^0.1.1",
"@vue/babel-plugin-jsx": "^1.0.6",
"@vue/compiler-sfc": "^3.0.0",
"vue-loader": "^17.0.0",
Expand All @@ -97,6 +101,9 @@
"tsconfig-paths-webpack-plugin": "^4.0.1"<%}%>,
"postcss": "^8.4.18",
"ts-node": "^10.9.1",
"@types/node": "^18.15.11"
"@types/node": "^18.15.11",
"@types/jest": "^29.3.1",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.5.0"
}
}
Loading

0 comments on commit 67d6c38

Please sign in to comment.