()
| 40 | const GENEREATED_TEST_PREFIXE = 'ZEXAMPLE_'; |
| 41 | |
| 42 | async function main() { |
| 43 | |
| 44 | if(!dirExist(ECHARTS_EXAMPLES_DIR)) { |
| 45 | throw new Error(`${ECHARTS_EXAMPLES_DIR} is required!`); |
| 46 | } |
| 47 | if(!dirExist(ECHARTS_EXAMPLES_E2E_GENERATED_BUNDLES_DIR)) { |
| 48 | throw new Error( |
| 49 | `${ECHARTS_EXAMPLES_E2E_GENERATED_BUNDLES_DIR} is missing, which is generated by e2e test.` |
| 50 | + ` See ${ECHARTS_EXAMPLES_DIR}/README.md for the guide.` |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | const tplContent = nodeFS.readFileSync(ECHARTS_EXAMPLES_E2E_TEMPLATE_PATH, {encoding:'utf-8'}) |
| 55 | |
| 56 | const bundlePathList = (await readFilePaths({ |
| 57 | patterns: ['*.js'], |
| 58 | cwd: ECHARTS_EXAMPLES_E2E_GENERATED_BUNDLES_DIR |
| 59 | })).filter(bundlePath => { |
| 60 | return bundlePath.relative.indexOf('.minimal.') < 0 |
| 61 | }); |
| 62 | |
| 63 | bundlePathList.forEach(bundlePath => { |
| 64 | if (!fileExist(bundlePath.absolute)) { |
| 65 | console.error(`${bundlePath.absolute} does not exists!`); |
| 66 | return; |
| 67 | } |
| 68 | const bundleContent = nodeFS.readFileSync(bundlePath.absolute, {encoding: 'utf-8'}); |
| 69 | const testContent = tplContent.replace( |
| 70 | TEMPLATE_REPLACE_TOKEN, |
| 71 | // Use a cb to avoid `$$` => `$` issue of JS replace method. |
| 72 | () => `<script> |
| 73 | $.ajaxPrefilter(function (options) { |
| 74 | try { |
| 75 | // echarts-examples use port 3322. need rewrite. |
| 76 | const url = new URL(options.url, window.location.origin); |
| 77 | if (url.port === '3322') { |
| 78 | url.port = window.location.port; |
| 79 | options.url = url.toString(); |
| 80 | } |
| 81 | } catch (e) { |
| 82 | console.log(e); // Invalid URL. |
| 83 | } |
| 84 | }); |
| 85 | (function () { |
| 86 | ${bundleContent} |
| 87 | })(); |
| 88 | </script>` |
| 89 | ); |
| 90 | const bundleName = nodePath.basename(bundlePath.relative, '.js'); |
| 91 | |
| 92 | const generatedHTMLPath = |
| 93 | nodePath.resolve(ECHARTS_TEST_HTML_DIR, `${GENEREATED_TEST_PREFIXE}${bundleName}.html`); |
| 94 | console.log(`Writing to ${generatedHTMLPath}`); |
| 95 | nodeFS.writeFileSync(generatedHTMLPath, testContent, {encoding: 'utf-8'}); |
| 96 | }); |
| 97 | |
| 98 | console.log('All accomplished.'); |
| 99 | } |
no test coverage detected
searching dependent graphs…