mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-21 22:25:57 -04:00
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:
@@ -69,6 +69,8 @@ function loadEntryObj(projectPath, device_level, abilityType, manifestFilePath)
|
|||||||
entryObj = addPageEntryObj(readManifest(manifestFilePath), projectPath);
|
entryObj = addPageEntryObj(readManifest(manifestFilePath), projectPath);
|
||||||
entryObj[`./${abilityType}`] = path.resolve(projectPath, `./${abilityType}.js?entry`);
|
entryObj[`./${abilityType}`] = path.resolve(projectPath, `./${abilityType}.js?entry`);
|
||||||
break;
|
break;
|
||||||
|
case 'testrunner':
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
entryObj[`./${abilityType}`] = path.resolve(projectPath, `./${abilityType}.js?entry`);
|
entryObj[`./${abilityType}`] = path.resolve(projectPath, `./${abilityType}.js?entry`);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
"richtest": "cd test/rich/testcase && webpack --config ../../../webpack.rich.config.js && mocha ../test.js",
|
"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",
|
"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",
|
"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": {
|
"devDependencies": {
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
|
|||||||
Executable
+24
@@ -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')
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -127,25 +127,33 @@ class ResourcePlugin {
|
|||||||
circularFile(input, output, '../share');
|
circularFile(input, output, '../share');
|
||||||
});
|
});
|
||||||
compiler.hooks.normalModuleFactory.tap('OtherEntryOptionPlugin', () => {
|
compiler.hooks.normalModuleFactory.tap('OtherEntryOptionPlugin', () => {
|
||||||
const cssFiles = readCSSInfo(watchCSSFiles);
|
if (process.env.abilityType === 'testrunner') {
|
||||||
if (process.env.DEVICE_LEVEL === 'card' && process.env.compileMode !== 'moduleJson') {
|
checkTestRunner(input, entryObj);
|
||||||
for(const entryKey in compiler.options.entry) {
|
for (const key in entryObj) {
|
||||||
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]) {
|
|
||||||
const singleEntry = new SingleEntryPlugin('', entryObj[key], key);
|
const singleEntry = new SingleEntryPlugin('', entryObj[key], key);
|
||||||
singleEntry.apply(compiler);
|
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', () => {
|
compiler.hooks.done.tap('copyManifest', () => {
|
||||||
copyManifest();
|
copyManifest();
|
||||||
@@ -417,12 +425,8 @@ function setCSSEntry(cssfiles, key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkTestRunner(projectPath, entryObj) {
|
function checkTestRunner(projectPath, entryObj) {
|
||||||
const testRunnerPath = path.join(path.parse(projectPath).dir, 'TestRunner');
|
|
||||||
if ((!fs.existsSync(testRunnerPath)) || !fs.statSync(testRunnerPath).isDirectory()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const files = [];
|
const files = [];
|
||||||
walkSync(testRunnerPath, files, entryObj, projectPath);
|
walkSync(projectPath, files, entryObj, projectPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
function walkSync(filePath_, files, entryObj, projectPath) {
|
function walkSync(filePath_, files, entryObj, projectPath) {
|
||||||
@@ -432,8 +436,8 @@ function walkSync(filePath_, files, entryObj, projectPath) {
|
|||||||
if (stat.isFile()) {
|
if (stat.isFile()) {
|
||||||
const extName = '.js';
|
const extName = '.js';
|
||||||
if (path.extname(filePath) === extName) {
|
if (path.extname(filePath) === extName) {
|
||||||
const key = filePath.replace(path.parse(projectPath).dir, '').replace(extName, '');
|
const key = filePath.replace(projectPath, '').replace(extName, '');
|
||||||
entryObj[`../${key}`] = filePath;
|
entryObj[`./${key}`] = filePath;
|
||||||
} else if (stat.isDirectory()) {
|
} else if (stat.isDirectory()) {
|
||||||
walkSync(filePath, files, entryObj, projectPath);
|
walkSync(filePath, files, entryObj, projectPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ let config = {
|
|||||||
poll: false,
|
poll: false,
|
||||||
ignored: /node_modules/
|
ignored: /node_modules/
|
||||||
},
|
},
|
||||||
|
|
||||||
output: {
|
output: {
|
||||||
filename: '[name].js',
|
filename: '[name].js',
|
||||||
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]',
|
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]',
|
||||||
@@ -338,13 +338,24 @@ module.exports = (env) => {
|
|||||||
config.output.sourceMapFilename = '_releaseMap/[name].js.map'
|
config.output.sourceMapFilename = '_releaseMap/[name].js.map'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.module.rules.unshift({
|
if (process.env.abilityType === 'testrunner') {
|
||||||
test: new RegExp("(" + (process.env.abilityType === 'page' ?
|
config.module.rules = [];
|
||||||
'app' : process.env.abilityType) + "\.js)(\\?[^?]+)?$"),
|
config.module.rules.unshift({
|
||||||
use: [{
|
test: /TestRunner/,
|
||||||
loader: path.resolve(__dirname, './index.js')
|
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;
|
config.output.library = process.env.hashProjectPath;
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user