@aiot-toolkit/parser 2.0.6-beta.1 → 2.0.6-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ux/config/{vela/StyleAttributeConfig.d.ts → StyleBaseConfig.d.ts} +1 -1
- package/lib/ux/config/{vela/StyleAttributeConfig.js → StyleBaseConfig.js} +16 -24
- package/lib/ux/config/vela/ElementConfig.js +6 -0
- package/lib/ux/interface/IE2eConfig.d.ts +44 -0
- package/lib/ux/interface/IE2eConfig.js +1 -0
- package/lib/ux/interface/IStyleError.d.ts +2 -1
- package/lib/ux/parser/ScriptParser.js +2 -1
- package/lib/ux/parser/StyleParser.d.ts +3 -2
- package/lib/ux/parser/StyleParser.js +27 -30
- package/lib/ux/parser/UxParser.d.ts +1 -0
- package/lib/ux/parser/UxParser.js +17 -15
- package/lib/ux/translate/vela/ScriptToTypescript.d.ts +2 -1
- package/lib/ux/translate/vela/ScriptToTypescript.js +13 -6
- package/lib/ux/translate/vela/StyleToTypescript.js +8 -11
- package/lib/ux/translate/vela/plugins/e2e.js +30 -138
- package/lib/ux/translate/vela/utils/AttributeConfig.js +1 -1
- package/lib/ux/translate/vela/utils/TemplateUtil.d.ts +5 -3
- package/lib/ux/translate/vela/utils/TemplateUtil.js +187 -180
- package/lib/ux/utils/StyleMapUtil.d.ts +2 -3
- package/lib/ux/utils/StyleMapUtil.js +6 -5
- package/lib/ux/utils/StyleUtil.d.ts +2 -0
- package/lib/ux/utils/StyleUtil.js +60 -48
- package/lib/ux/utils/UxUtil.d.ts +5 -0
- package/lib/ux/utils/UxUtil.js +24 -0
- package/package.json +4 -4
|
@@ -8,7 +8,7 @@ var t = _interopRequireWildcard(require("@babel/types"));
|
|
|
8
8
|
var parser = _interopRequireWildcard(require("@babel/parser"));
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
11
|
-
var
|
|
11
|
+
var _UxUtil = _interopRequireDefault(require("../../../utils/UxUtil"));
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -62,10 +62,6 @@ function addAppTestCode(path) {
|
|
|
62
62
|
* b. 设置测试函数: 如果 onTestStart 方法已存在,则在其内部添加测试代码;否则,添加 onTestStart方法
|
|
63
63
|
*
|
|
64
64
|
*
|
|
65
|
-
* 2. 如果启用自动路由,且当前页面是首页
|
|
66
|
-
* a. 从routerList 中过滤出有测试文件的路由
|
|
67
|
-
* b. 在末尾添加 $generateAutoRunTest
|
|
68
|
-
* c. 在onShow 方法中调用 $generateAutoRunTest
|
|
69
65
|
*
|
|
70
66
|
*
|
|
71
67
|
* @description 示例
|
|
@@ -91,12 +87,17 @@ function addAppTestCode(path) {
|
|
|
91
87
|
* @param opts
|
|
92
88
|
*/
|
|
93
89
|
function addPageTestCode(path, opts) {
|
|
94
|
-
const e2eConfig = getE2eConfig(
|
|
95
|
-
|
|
90
|
+
const e2eConfig = _UxUtil.default.getE2eConfig({
|
|
91
|
+
projectPath: opts.options.projectPath,
|
|
92
|
+
e2eConfigPath: opts.compilerOption.e2eConfigPath
|
|
93
|
+
});
|
|
94
|
+
const filePath = opts.options.filePath;
|
|
95
|
+
const testFilePath = getTestFilePath(filePath, opts, e2eConfig);
|
|
96
|
+
const testCaseConfig = getTestcaseConfig(filePath, opts, e2eConfig);
|
|
96
97
|
// 1
|
|
97
98
|
if (_fsExtra.default.existsSync(testFilePath)) {
|
|
98
99
|
// 1.a
|
|
99
|
-
const relativePath = _path.default.relative(_path.default.dirname(
|
|
100
|
+
const relativePath = _path.default.relative(_path.default.dirname(filePath), testFilePath);
|
|
100
101
|
const vmImport = t.importDeclaration([t.importDefaultSpecifier(t.identifier('fnTestCase'))], t.stringLiteral(relativePath));
|
|
101
102
|
if (path.parent.type === 'Program') {
|
|
102
103
|
path.parent.body.unshift(vmImport);
|
|
@@ -105,33 +106,21 @@ function addPageTestCode(path, opts) {
|
|
|
105
106
|
// 1.b
|
|
106
107
|
if (path.node.declaration.type === 'ObjectExpression') {
|
|
107
108
|
const properties = path.node.declaration.properties;
|
|
108
|
-
insertFun('onTestStart', generateTestFn(), properties);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// 2
|
|
113
|
-
if (isIndexPage(opts) && e2eConfig.autoRoute) {
|
|
114
|
-
let {
|
|
115
|
-
routerList,
|
|
116
|
-
pageSleep
|
|
117
|
-
} = e2eConfig.autoRoute;
|
|
118
|
-
routerList = routerList?.filter(item => hasTestFile(item, opts, e2eConfig));
|
|
119
|
-
if (!routerList?.length) {
|
|
120
|
-
console.log('missing autoRoute.routerList');
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
// 2.a
|
|
124
|
-
|
|
125
|
-
if (path.node.declaration.type === 'ObjectExpression') {
|
|
126
|
-
const properties = path.node.declaration.properties;
|
|
127
|
-
|
|
128
|
-
// 2.b
|
|
129
|
-
insertFun('$generateAutoRunTest', generateAutoRouterFn(pageSleep, routerList), properties);
|
|
130
|
-
// 2.c
|
|
131
|
-
insertFun('onShow', generateAutoRouterInOnShow(), properties);
|
|
109
|
+
insertFun('onTestStart', generateTestFn(testCaseConfig), properties);
|
|
132
110
|
}
|
|
133
111
|
}
|
|
134
112
|
}
|
|
113
|
+
function getTestcaseConfig(filePath, opts, e2eConfig) {
|
|
114
|
+
const {
|
|
115
|
+
projectPath
|
|
116
|
+
} = opts.options;
|
|
117
|
+
const {
|
|
118
|
+
sourceRoot
|
|
119
|
+
} = opts.compilerOption;
|
|
120
|
+
const relativeSrc = _path.default.relative(_path.default.join(projectPath, sourceRoot || ''), filePath);
|
|
121
|
+
const pageName = _path.default.dirname(relativeSrc).replace(/\\/g, _path.default.posix.sep);
|
|
122
|
+
return e2eConfig.testcases?.find(item => item.name === pageName);
|
|
123
|
+
}
|
|
135
124
|
|
|
136
125
|
/**
|
|
137
126
|
* 插入函数
|
|
@@ -152,77 +141,6 @@ function insertFun(name, body, properties) {
|
|
|
152
141
|
}, [], body));
|
|
153
142
|
}
|
|
154
143
|
}
|
|
155
|
-
function hasTestFile(router, opts, e2eConfig) {
|
|
156
|
-
const manifest = getManifest(opts);
|
|
157
|
-
if (manifest) {
|
|
158
|
-
const {
|
|
159
|
-
pages
|
|
160
|
-
} = manifest.router;
|
|
161
|
-
const pageRouter = pages[router];
|
|
162
|
-
if (!pageRouter) {
|
|
163
|
-
opts.options.onLog({
|
|
164
|
-
level: _sharedUtils.Loglevel.WARN,
|
|
165
|
-
message: [{
|
|
166
|
-
word: router
|
|
167
|
-
}, `missing router in manifest.json`]
|
|
168
|
-
});
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
const pagePath = `${opts.compilerOption.sourceRoot}/${router}/${pageRouter.component}`;
|
|
172
|
-
const testFilePath = getTestFilePath(pagePath, opts, e2eConfig);
|
|
173
|
-
return _fsExtra.default.existsSync(testFilePath);
|
|
174
|
-
}
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
function isIndexPage(opts) {
|
|
178
|
-
const manifest = getManifest(opts);
|
|
179
|
-
if (manifest) {
|
|
180
|
-
const {
|
|
181
|
-
entry,
|
|
182
|
-
pages
|
|
183
|
-
} = manifest.router;
|
|
184
|
-
const entryItem = pages[entry];
|
|
185
|
-
const entryPath = `${entry}/${entryItem.component}`;
|
|
186
|
-
const sourcePath = _path.default.join(opts.options.projectPath, opts.compilerOption.sourceRoot);
|
|
187
|
-
const filePath = _path.default.relative(sourcePath, opts.options.filePath);
|
|
188
|
-
const filePathParsed = _path.default.parse(filePath);
|
|
189
|
-
return entryPath === `${filePathParsed.dir}/${filePathParsed.name}`;
|
|
190
|
-
}
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
function getManifest(opts) {
|
|
194
|
-
const manifestPath = _path.default.resolve(opts.options.projectPath, opts.compilerOption.sourceRoot, 'manifest.json');
|
|
195
|
-
if (manifestPath) {
|
|
196
|
-
return _fsExtra.default.readJSONSync(manifestPath);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function getE2eConfig(opts) {
|
|
200
|
-
const defaultTestDir = 'test';
|
|
201
|
-
let result = {
|
|
202
|
-
testDir: _path.default.join(opts.options.projectPath, defaultTestDir)
|
|
203
|
-
};
|
|
204
|
-
const {
|
|
205
|
-
projectPath
|
|
206
|
-
} = opts.options;
|
|
207
|
-
const {
|
|
208
|
-
e2eConfigPath
|
|
209
|
-
} = opts.compilerOption;
|
|
210
|
-
if (e2eConfigPath) {
|
|
211
|
-
const configFilePath = _path.default.resolve(projectPath, e2eConfigPath);
|
|
212
|
-
const configFileDir = _path.default.dirname(configFilePath);
|
|
213
|
-
if (_fsExtra.default.existsSync(configFilePath)) {
|
|
214
|
-
result = _fsExtra.default.readJSONSync(configFilePath, 'utf-8');
|
|
215
|
-
|
|
216
|
-
// 目录转换为绝对路径
|
|
217
|
-
if (result) {
|
|
218
|
-
result.testDir = _path.default.resolve(configFileDir, result.testDir || defaultTestDir);
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
throw new Error(`e2e Configuration file does not exist: ${configFilePath}`);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return result;
|
|
225
|
-
}
|
|
226
144
|
|
|
227
145
|
/**
|
|
228
146
|
* 获取源文件对应的测试文件地址
|
|
@@ -240,14 +158,18 @@ function getTestFilePath(sourceFile, opts, e2eConfig) {
|
|
|
240
158
|
} = opts.compilerOption;
|
|
241
159
|
const relativeSrc = _path.default.relative(_path.default.join(projectPath, sourceRoot || ''), sourceFile);
|
|
242
160
|
const parsed = _path.default.parse(relativeSrc);
|
|
243
|
-
return _path.default.join(e2eConfig.
|
|
161
|
+
return _path.default.join(e2eConfig.dir, parsed.dir, `${parsed.name}.js`);
|
|
244
162
|
}
|
|
245
163
|
|
|
246
164
|
/**
|
|
247
165
|
* 获取测试函数的函数体
|
|
248
166
|
* @returns
|
|
249
167
|
*/
|
|
250
|
-
function generateTestFn() {
|
|
168
|
+
function generateTestFn(config) {
|
|
169
|
+
const {
|
|
170
|
+
sleep,
|
|
171
|
+
back = true
|
|
172
|
+
} = config || {};
|
|
251
173
|
const fn = `function(){
|
|
252
174
|
this.$options = this._options || this.$options;
|
|
253
175
|
if (this.$options._descriptor) {
|
|
@@ -259,46 +181,16 @@ function generateTestFn() {
|
|
|
259
181
|
global.qat = new VelaQuickappTest();
|
|
260
182
|
setTimeout(() => {
|
|
261
183
|
typeof fnTestCase === 'function' && fnTestCase(this)
|
|
262
|
-
qat.run(() => {
|
|
184
|
+
qat.run(async () => {
|
|
263
185
|
if (this.back !== "false") {
|
|
264
186
|
console.info("拥有关联测试用例,测试完毕,返回到之前的页面");
|
|
265
187
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
266
188
|
var _system = _interopRequireDefault($app_require$('@app-module/system.router'));
|
|
267
|
-
|
|
189
|
+
${sleep ? `await new Promise(resolve => setTimeout(resolve, ${sleep}));` : ''}
|
|
190
|
+
${back ? `_system.default.back();` : ''}
|
|
268
191
|
}
|
|
269
192
|
});
|
|
270
193
|
}, global.CASE_TEST_START);
|
|
271
194
|
}`;
|
|
272
195
|
return parser.parseExpression(fn).body;
|
|
273
|
-
}
|
|
274
|
-
function generateAutoRouterFn() {
|
|
275
|
-
let sleep = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3000;
|
|
276
|
-
let routerList = arguments.length > 1 ? arguments[1] : undefined;
|
|
277
|
-
const fn = `function(){
|
|
278
|
-
const routerList = ${JSON.stringify(routerList)}
|
|
279
|
-
if (!routerList) {
|
|
280
|
-
console.log('missing routerList');
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
if (this.autoTestPageIndex === undefined) {
|
|
284
|
-
this.autoTestPageIndex = -1;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
setTimeout(() => {
|
|
288
|
-
if (++this.autoTestPageIndex < routerList.length) {
|
|
289
|
-
const uri = routerList[this.autoTestPageIndex];
|
|
290
|
-
console.log(\`auto test page=\${uri}, index=\${this.autoTestPageIndex}\`);
|
|
291
|
-
router.push({ uri });
|
|
292
|
-
} else {
|
|
293
|
-
console.log('auto test finish');
|
|
294
|
-
}
|
|
295
|
-
}, ${sleep});
|
|
296
|
-
}`;
|
|
297
|
-
return parser.parseExpression(fn).body;
|
|
298
|
-
}
|
|
299
|
-
function generateAutoRouterInOnShow() {
|
|
300
|
-
const fn = `function(){
|
|
301
|
-
this.$generateAutoRunTest();
|
|
302
|
-
}`;
|
|
303
|
-
return parser.parseExpression(fn).body;
|
|
304
196
|
}
|
|
@@ -29,7 +29,7 @@ const ATTRIBUTE_CONFIG = {
|
|
|
29
29
|
return $classValue$;
|
|
30
30
|
}`;
|
|
31
31
|
}
|
|
32
|
-
return `[${JSON.parse(result).split(' ').map(item =>
|
|
32
|
+
return `[${JSON.parse(result).split(' ').map(item => item.trim()).filter(Boolean).map(item => JSON.stringify(item)).join(',')}]`;
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
style: {
|
|
@@ -261,10 +261,10 @@ declare class TemplateUtil {
|
|
|
261
261
|
* 获取节点中的文字内容
|
|
262
262
|
*
|
|
263
263
|
* 1. 如果是文字元素,返回 value
|
|
264
|
-
*
|
|
264
|
+
* 2. 循环子元素列表
|
|
265
265
|
* 1. 如果子元素是文本,直接返回内容
|
|
266
266
|
* 2. 否则,如果子元素允许文本,则递归获取结果
|
|
267
|
-
*
|
|
267
|
+
* 3. 文字中连续的特定符号[\r\n\t ]
|
|
268
268
|
* 1. 首尾的替换为空字符串
|
|
269
269
|
* 2. 其它替换为1个空格
|
|
270
270
|
*
|
|
@@ -273,7 +273,9 @@ declare class TemplateUtil {
|
|
|
273
273
|
* a
|
|
274
274
|
* b
|
|
275
275
|
*
|
|
276
|
-
* `
|
|
276
|
+
* `
|
|
277
|
+
* -->
|
|
278
|
+
* `a b`
|
|
277
279
|
*
|
|
278
280
|
* @param node
|
|
279
281
|
*/
|