diff --git a/ace-loader/main.product.js b/ace-loader/main.product.js index 22a0efe..0611d0b 100644 --- a/ace-loader/main.product.js +++ b/ace-loader/main.product.js @@ -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; diff --git a/ace-loader/package.json b/ace-loader/package.json index 72f15e6..24d6d0e 100644 --- a/ace-loader/package.json +++ b/ace-loader/package.json @@ -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", diff --git a/ace-loader/sample/TestRunner/runner.js b/ace-loader/sample/TestRunner/runner.js new file mode 100755 index 0000000..0830af6 --- /dev/null +++ b/ace-loader/sample/TestRunner/runner.js @@ -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') + } +}; \ No newline at end of file diff --git a/ace-loader/src/resource-plugin.js b/ace-loader/src/resource-plugin.js index d8a473c..dea4cf1 100644 --- a/ace-loader/src/resource-plugin.js +++ b/ace-loader/src/resource-plugin.js @@ -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); } diff --git a/ace-loader/webpack.rich.config.js b/ace-loader/webpack.rich.config.js index e742d44..fae169e 100644 --- a/ace-loader/webpack.rich.config.js +++ b/ace-loader/webpack.rich.config.js @@ -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 }