Skip to content

Commit

Permalink
test(runner): 为 mini/webpack-runner 增加 vue3 测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj committed Jun 29, 2020
1 parent 40b0510 commit babff4d
Show file tree
Hide file tree
Showing 41 changed files with 1,823 additions and 67 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
"ts-jest": "23",
"typescript": "^3.8.3",
"vue": "^2.6.11",
"vue-loader": "^15.9.3",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-loader/src/h5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if (config.tabBar) {
config.routes = [
${config.pages?.map(path => genResource(path, pages, this)).join('')}
]
${execBeforeCreateWebApp}
${execBeforeCreateWebApp || ''}
var inst = ${creator}(component, ${frameworkArgs})
createRouter(inst, config, ${importFrameworkName})
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ require(\\"./taro\\");
options._ssrRegister = hook;
} else if (injectStyles) {
hook = shadowMode ? function() {
injectStyles.call(this, this.$root.$options.shadowRoot);
injectStyles.call(this, (options.functional ? this.parent : this).$root.$options.shadowRoot);
} : injectStyles;
}
if (hook) {
Expand Down
809 changes: 809 additions & 0 deletions packages/taro-mini-runner/__tests__/__snapshots__/vue3.spec.ts.snap

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions packages/taro-mini-runner/__tests__/fixtures/vue3/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// babel-preset-taro 更多选项和默认值:
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
module.exports = {
presets: [
['taro', {
framework: 'vue3',
ts: false
}]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
pages: [
'pages/index/index'
],
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat',
navigationBarTextStyle: 'black'
}
}
Empty file.
9 changes: 9 additions & 0 deletions packages/taro-mini-runner/__tests__/fixtures/vue3/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createApp } from 'vue'
import './app.css'

const App = createApp({
onShow (options) {},
// 入口组件不需要实现 render 方法,即使实现了也会被 taro 所覆盖
})

export default App
19 changes: 19 additions & 0 deletions packages/taro-mini-runner/__tests__/fixtures/vue3/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="format-detection" content="telephone=no,address=no">
<meta name="apple-mobile-web-app-status-bar-style" content="white">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
<title></title>
<script>
!function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;tes=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=640){r.style.fontSize="40px"}else{if(a<=320){r.style.fontSize="20px"}else{r.style.fontSize=a/320*20+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
navigationBarTitleText: '首页'
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<view class="index">
<text>{{ msg }}</text>
</view>
</template>

<script>
import { ref } from 'vue'
export default {
setup () {
const msg = ref('Hello world')
return {
msg
}
}
}
</script>
15 changes: 15 additions & 0 deletions packages/taro-mini-runner/__tests__/vue3.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { compile, getOutput } from './utils/compiler'

describe('vue3', () => {
test('should build vue3 app', async () => {
const { stats, config } = await compile('vue3', {
framework: 'vue3'
})
const assets = stats.toJson().assets

expect(assets.length).toMatchSnapshot()

const output = getOutput(stats, config)
expect(output).toMatchSnapshot()
})
})
1 change: 0 additions & 1 deletion packages/taro-mini-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"terser-webpack-plugin": "^3.0.5",
"url-loader": "^4.1.0",
"vm2": "^3.8.4",
"vue-template-compiler": "^2.6.10",
"webpack": "4.42.0",
"webpack-chain": "4.9.0",
"webpack-format-messages": "^2.0.5",
Expand Down
15 changes: 0 additions & 15 deletions packages/taro-mini-runner/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1676,10 +1676,6 @@ date-now@^0.1.4:
version "0.1.4"
resolved "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"

de-indent@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"

debug@^2.2.0, debug@^2.3.3:
version "2.6.9"
resolved "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down Expand Up @@ -2296,10 +2292,6 @@ hash.js@^1.0.0, hash.js@^1.0.3:
inherits "^2.0.3"
minimalistic-assert "^1.0.1"

he@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"

hmac-drbg@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
Expand Down Expand Up @@ -4923,13 +4915,6 @@ vm2@^3.8.4:
version "3.8.4"
resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.8.4.tgz#882be9135467942d84d1af80b6e6549b57c69041"

vue-template-compiler@^2.6.10:
version "2.6.11"
resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.6.11.tgz#c04704ef8f498b153130018993e56309d4698080"
dependencies:
de-indent "^1.0.2"
he "^1.1.0"

w3c-hr-time@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz#82ac2bff63d950ea9e3189a58a65625fedf19045"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ exports[`babel should convert do expressions 2`] = `
var _unused_webpack_default_export = \\"taro-components-mock\\";
function defineCustomElements() {}
function applyPolyfills() {}
function initVue3Components() {}
}, function(module, __webpack_exports__, __webpack_require__) {
\\"use strict\\";
__webpack_require__.d(__webpack_exports__, \\"a\\", (function() {
Expand Down Expand Up @@ -678,6 +679,7 @@ exports[`babel should convert do expressions 2`] = `
\\"use strict\\";
__webpack_require__.r(__webpack_exports__);
var taro_h5 = \\"taro-h5-mock\\";
function createRouter() {}
var h5 = taro_h5;
var classCallCheck = __webpack_require__(2);
var createClass = __webpack_require__(3);
Expand Down Expand Up @@ -715,6 +717,9 @@ exports[`babel should convert do expressions 2`] = `
var src_app = app_App;
var taro_runtime = \\"taro-runtime-mock\\";
var taro_runtime_window = {};
function createReactApp() {}
function createVueApp() {}
function createVue3App() {}
var taro_components = __webpack_require__(1);
var mocks_taro_components = __webpack_require__(9);
Object(taro_components[\\"c\\"])().then((function() {
Expand Down Expand Up @@ -755,8 +760,8 @@ exports[`babel should convert do expressions 2`] = `
}, {
\\"navigationBarTitleText\\": \\"首页\\"
} || {}) ];
var inst = undefined(src_app, react, react[\\"default\\"], config);
undefined(inst, config, react);
var inst = createReactApp(src_app, react, react[\\"default\\"], config);
createRouter(inst, config, react);
} ]);
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ exports[`config should build from origin and pipe to output 2`] = `
var _unused_webpack_default_export = \\"taro-components-mock\\";
function defineCustomElements() {}
function applyPolyfills() {}
function initVue3Components() {}
}, function(module, __webpack_exports__, __webpack_require__) {
\\"use strict\\";
__webpack_require__.d(__webpack_exports__, \\"a\\", (function() {
Expand Down Expand Up @@ -684,6 +685,7 @@ exports[`config should build from origin and pipe to output 2`] = `
\\"use strict\\";
__webpack_require__.r(__webpack_exports__);
var taro_h5 = \\"taro-h5-mock\\";
function createRouter() {}
var h5 = taro_h5;
var classCallCheck = __webpack_require__(1);
var createClass = __webpack_require__(2);
Expand Down Expand Up @@ -721,6 +723,9 @@ exports[`config should build from origin and pipe to output 2`] = `
var origin_app = app_App;
var taro_runtime = \\"taro-runtime-mock\\";
var taro_runtime_window = {};
function createReactApp() {}
function createVueApp() {}
function createVue3App() {}
var taro_components = __webpack_require__(0);
var nerv = \\"nervjs-mock\\";
var mocks_taro_components = __webpack_require__(9);
Expand Down Expand Up @@ -762,8 +767,8 @@ exports[`config should build from origin and pipe to output 2`] = `
}, {
\\"navigationBarTitleText\\": \\"首页\\"
} || {}) ];
var inst = undefined(origin_app, nerv, nerv, config);
undefined(inst, config, nerv);
var inst = createReactApp(origin_app, nerv, nerv, config);
createRouter(inst, config, nerv);
} ]);
"
`;
Expand Down Expand Up @@ -1057,6 +1062,7 @@ I m irrelevant.
var _unused_webpack_default_export = \\"taro-components-mock\\";
function defineCustomElements() {}
function applyPolyfills() {}
function initVue3Components() {}
}, function(module, __webpack_exports__, __webpack_require__) {
\\"use strict\\";
__webpack_require__.d(__webpack_exports__, \\"a\\", (function() {
Expand Down Expand Up @@ -1456,6 +1462,7 @@ I m irrelevant.
\\"use strict\\";
__webpack_require__.r(__webpack_exports__);
var taro_h5 = \\"taro-h5-mock\\";
function createRouter() {}
var h5 = taro_h5;
var classCallCheck = __webpack_require__(1);
var createClass = __webpack_require__(2);
Expand Down Expand Up @@ -1493,6 +1500,9 @@ I m irrelevant.
var origin_app = app_App;
var taro_runtime = \\"taro-runtime-mock\\";
var taro_runtime_window = {};
function createReactApp() {}
function createVueApp() {}
function createVue3App() {}
var taro_components = __webpack_require__(0);
var nerv = \\"nervjs-mock\\";
var mocks_taro_components = __webpack_require__(9);
Expand Down Expand Up @@ -1534,8 +1544,8 @@ I m irrelevant.
}, {
\\"navigationBarTitleText\\": \\"首页\\"
} || {}) ];
var inst = undefined(origin_app, nerv, nerv, config);
undefined(inst, config, nerv);
var inst = createReactApp(origin_app, nerv, nerv, config);
createRouter(inst, config, nerv);
} ]);
/** filePath: dist/weapp/index.wxml **/
Expand Down Expand Up @@ -1829,6 +1839,7 @@ exports[`config should resolved alias 2`] = `
var _unused_webpack_default_export = \\"taro-components-mock\\";
function defineCustomElements() {}
function applyPolyfills() {}
function initVue3Components() {}
}, function(module, __webpack_exports__, __webpack_require__) {
\\"use strict\\";
__webpack_require__.d(__webpack_exports__, \\"a\\", (function() {
Expand Down Expand Up @@ -2228,6 +2239,7 @@ exports[`config should resolved alias 2`] = `
\\"use strict\\";
__webpack_require__.r(__webpack_exports__);
var taro_h5 = \\"taro-h5-mock\\";
function createRouter() {}
var h5 = taro_h5;
var classCallCheck = __webpack_require__(1);
var createClass = __webpack_require__(2);
Expand Down Expand Up @@ -2265,6 +2277,9 @@ exports[`config should resolved alias 2`] = `
var origin_app = app_App;
var taro_runtime = \\"taro-runtime-mock\\";
var taro_runtime_window = {};
function createReactApp() {}
function createVueApp() {}
function createVue3App() {}
var taro_components = __webpack_require__(0);
var nerv = \\"nervjs-mock\\";
var mocks_taro_components = __webpack_require__(9);
Expand Down Expand Up @@ -2306,8 +2321,8 @@ exports[`config should resolved alias 2`] = `
}, {
\\"navigationBarTitleText\\": \\"首页\\"
} || {}) ];
var inst = undefined(origin_app, nerv, nerv, config);
undefined(inst, config, nerv);
var inst = createReactApp(origin_app, nerv, nerv, config);
createRouter(inst, config, nerv);
} ]);
/** filePath: dist/js/extra.js **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ exports[`css modules should use css modules with global mode 2`] = `
var _unused_webpack_default_export = \\"taro-components-mock\\";
function defineCustomElements() {}
function applyPolyfills() {}
function initVue3Components() {}
}, function(module, __webpack_exports__, __webpack_require__) {
\\"use strict\\";
__webpack_require__.d(__webpack_exports__, \\"a\\", (function() {
Expand Down Expand Up @@ -702,6 +703,7 @@ exports[`css modules should use css modules with global mode 2`] = `
\\"use strict\\";
__webpack_require__.r(__webpack_exports__);
var taro_h5 = \\"taro-h5-mock\\";
function createRouter() {}
var h5 = taro_h5;
var classCallCheck = __webpack_require__(2);
var createClass = __webpack_require__(3);
Expand Down Expand Up @@ -739,6 +741,9 @@ exports[`css modules should use css modules with global mode 2`] = `
var src_app = app_App;
var taro_runtime = \\"taro-runtime-mock\\";
var taro_runtime_window = {};
function createReactApp() {}
function createVueApp() {}
function createVue3App() {}
var taro_components = __webpack_require__(1);
var mocks_taro_components = __webpack_require__(9);
Object(taro_components[\\"c\\"])().then((function() {
Expand Down Expand Up @@ -779,8 +784,8 @@ exports[`css modules should use css modules with global mode 2`] = `
}, {
\\"navigationBarTitleText\\": \\"首页\\"
} || {}) ];
var inst = undefined(src_app, react, react[\\"default\\"], config);
undefined(inst, config, react);
var inst = createReactApp(src_app, react, react[\\"default\\"], config);
createRouter(inst, config, react);
} ]);
"
`;
Expand Down Expand Up @@ -1087,6 +1092,7 @@ exports[`css modules should use css modules with module mode 2`] = `
var _unused_webpack_default_export = \\"taro-components-mock\\";
function defineCustomElements() {}
function applyPolyfills() {}
function initVue3Components() {}
}, function(module, __webpack_exports__, __webpack_require__) {
\\"use strict\\";
__webpack_require__.d(__webpack_exports__, \\"a\\", (function() {
Expand Down Expand Up @@ -1483,6 +1489,7 @@ exports[`css modules should use css modules with module mode 2`] = `
\\"use strict\\";
__webpack_require__.r(__webpack_exports__);
var taro_h5 = \\"taro-h5-mock\\";
function createRouter() {}
var h5 = taro_h5;
var classCallCheck = __webpack_require__(2);
var createClass = __webpack_require__(3);
Expand Down Expand Up @@ -1520,6 +1527,9 @@ exports[`css modules should use css modules with module mode 2`] = `
var src_app = app_App;
var taro_runtime = \\"taro-runtime-mock\\";
var taro_runtime_window = {};
function createReactApp() {}
function createVueApp() {}
function createVue3App() {}
var taro_components = __webpack_require__(1);
var mocks_taro_components = __webpack_require__(9);
Object(taro_components[\\"c\\"])().then((function() {
Expand Down Expand Up @@ -1560,8 +1570,8 @@ exports[`css modules should use css modules with module mode 2`] = `
}, {
\\"navigationBarTitleText\\": \\"首页\\"
} || {}) ];
var inst = undefined(src_app, react, react[\\"default\\"], config);
undefined(inst, config, react);
var inst = createReactApp(src_app, react, react[\\"default\\"], config);
createRouter(inst, config, react);
} ]);
"
`;
Loading

0 comments on commit babff4d

Please sign in to comment.