IssueNo:#I53XB0

Description: add testrunner suport
Sig: SIG_ApplicationFramework
Feature or Bugfix: Feature
Binary Source: No
Signed-off-by: guyuanzhang <zhangguyuan@huawei.com>

Change-Id: Ib72e6a9b282e6566ff1ac64cce33d45a7f655c33
This commit is contained in:
guyuanzhang 2022-04-21 17:15:56 +08:00
parent 1d28afafa0
commit 5bd94f5c47
5 changed files with 73 additions and 31 deletions

View File

@ -69,6 +69,8 @@ function loadEntryObj(projectPath, device_level, abilityType, manifestFilePath)
entryObj = addPageEntryObj(readManifest(manifestFilePath), projectPath);
entryObj[`./${abilityType}`] = path.resolve(projectPath, `./${abilityType}.js?entry`);
break;
case 'testrunner':
break;
default:
entryObj[`./${abilityType}`] = path.resolve(projectPath, `./${abilityType}.js?entry`);
break;

View File

@ -20,7 +20,8 @@
"richtest": "cd test/rich/testcase && webpack --config ../../../webpack.rich.config.js && mocha ../test.js",
"litetest": "cd test/lite/testcase && webpack --config ../../../webpack.lite.config.js && mocha ../test.js",
"cardtest": "cd test/card/testcase && webpack --config ../../../webpack.rich.config.js && mocha ../test.js",
"test": "npm run build && npm run richtest && npm run litetest && npm run cardtest"
"test": "npm run build && npm run richtest && npm run litetest && npm run cardtest",
"testrunner": "cd sample/TestRunner && webpack --config ../../webpack.rich.config.js"
},
"devDependencies": {
"chai": "^3.5.0",

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default {
onPrepare() {
console.log('testRunner OnPrepare')
},
onRun() {
console.log('testRunner onRun run')
}
};

View File

@ -127,25 +127,33 @@ class ResourcePlugin {
circularFile(input, output, '../share');
});
compiler.hooks.normalModuleFactory.tap('OtherEntryOptionPlugin', () => {
const cssFiles = readCSSInfo(watchCSSFiles);
if (process.env.DEVICE_LEVEL === 'card' && process.env.compileMode !== 'moduleJson') {
for(const entryKey in compiler.options.entry) {
setCSSEntry(cssFiles, entryKey);
}
writeCSSInfo(watchCSSFiles, cssFiles);
return;
}
addPageEntryObj();
entryObj = Object.assign(entryObj, abilityEntryObj);
checkTestRunner(input, entryObj);
for (const key in entryObj) {
if (!compiler.options.entry[key]) {
if (process.env.abilityType === 'testrunner') {
checkTestRunner(input, entryObj);
for (const key in entryObj) {
const singleEntry = new SingleEntryPlugin('', entryObj[key], key);
singleEntry.apply(compiler);
}
setCSSEntry(cssFiles, key);
} else {
const cssFiles = readCSSInfo(watchCSSFiles);
if (process.env.DEVICE_LEVEL === 'card' && process.env.compileMode !== 'moduleJson') {
for(const entryKey in compiler.options.entry) {
setCSSEntry(cssFiles, entryKey);
}
writeCSSInfo(watchCSSFiles, cssFiles);
return;
}
addPageEntryObj();
entryObj = Object.assign(entryObj, abilityEntryObj);
for (const key in entryObj) {
if (!compiler.options.entry[key]) {
const singleEntry = new SingleEntryPlugin('', entryObj[key], key);
singleEntry.apply(compiler);
}
setCSSEntry(cssFiles, key);
}
writeCSSInfo(watchCSSFiles, cssFiles);
}
writeCSSInfo(watchCSSFiles, cssFiles);
});
compiler.hooks.done.tap('copyManifest', () => {
copyManifest();
@ -417,12 +425,8 @@ function setCSSEntry(cssfiles, key) {
}
function checkTestRunner(projectPath, entryObj) {
const testRunnerPath = path.join(path.parse(projectPath).dir, 'TestRunner');
if ((!fs.existsSync(testRunnerPath)) || !fs.statSync(testRunnerPath).isDirectory()) {
return;
}
const files = [];
walkSync(testRunnerPath, files, entryObj, projectPath);
walkSync(projectPath, files, entryObj, projectPath);
}
function walkSync(filePath_, files, entryObj, projectPath) {
@ -432,8 +436,8 @@ function walkSync(filePath_, files, entryObj, projectPath) {
if (stat.isFile()) {
const extName = '.js';
if (path.extname(filePath) === extName) {
const key = filePath.replace(path.parse(projectPath).dir, '').replace(extName, '');
entryObj[`../${key}`] = filePath;
const key = filePath.replace(projectPath, '').replace(extName, '');
entryObj[`./${key}`] = filePath;
} else if (stat.isDirectory()) {
walkSync(filePath, files, entryObj, projectPath);
}

View File

@ -143,7 +143,7 @@ let config = {
poll: false,
ignored: /node_modules/
},
output: {
filename: '[name].js',
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]',
@ -338,13 +338,24 @@ module.exports = (env) => {
config.output.sourceMapFilename = '_releaseMap/[name].js.map'
}
}
config.module.rules.unshift({
test: new RegExp("(" + (process.env.abilityType === 'page' ?
'app' : process.env.abilityType) + "\.js)(\\?[^?]+)?$"),
use: [{
loader: path.resolve(__dirname, './index.js')
}]
})
if (process.env.abilityType === 'testrunner') {
config.module.rules = [];
config.module.rules.unshift({
test: /TestRunner/,
use: [{
loader: path.resolve(__dirname, './index.js')
}]
})
} else {
config.module.rules.unshift({
test: new RegExp("(" + (process.env.abilityType === 'page' ?
'app' : process.env.abilityType) + "\.js)(\\?[^?]+)?$"),
use: [{
loader: path.resolve(__dirname, './index.js')
}]
})
}
config.output.library = process.env.hashProjectPath;
return config
}