Explorar el Código

use handlebars for test index iife

Adam Shaw hace 3 años
padre
commit
ff4108a89b

+ 2 - 0
packages/core/scripts/generate-locales-all.js

@@ -10,6 +10,8 @@ const localesDir = joinPaths(pkgDir, 'src/locales')
 
 export default async function() {
   const localeFilenames = await globby('*.ts', { cwd: localesDir })
+
+  // TODO: use basename to remove extension
   const localeCodes = localeFilenames.map((filename) => filename.replace(/\.ts$/, ''))
 
   const templateText = await readFile(templatePath, 'utf8')

+ 1 - 1
tests/package.json

@@ -27,7 +27,7 @@
     "@types/jasmine": "^3.3.12",
     "@types/jasmine-jquery": "^1.5.33",
     "@types/jquery": "^3.3.29",
-    "handlebars": "^4.1.2"
+    "handlebars": "^4.7.7"
   },
   "scripts": {
     "build": "workspace-scripts pkg:build",

+ 16 - 10
tests/scripts/generate-index-iife.js

@@ -1,13 +1,19 @@
-import { resolve as resolvePath } from 'path'
+import { join as joinPaths, resolve as resolvePath } from 'path'
+import { fileURLToPath } from 'url'
+import { readFile } from 'fs/promises'
+import handlebars from 'handlebars'
 import { capture } from '@fullcalendar/workspace-scripts/utils/exec'
 
+const pkgDir = joinPaths(fileURLToPath(import.meta.url), '../..')
+const templatePath = joinPaths(pkgDir, 'src/index.iife.js.tpl')
+
 export default async function main() {
-  const srcPathAbs = resolvePath('./src')
+  const srcDir = resolvePath('./src') // HACK: works when called from other test dirs
 
   let testPaths = await capture(
     "find . -mindepth 2 -type f \\( -name '*.ts' -or -name '*.tsx' \\) -print0 | " +
     'xargs -0 grep -E "(fdescribe|fit)\\("',
-    { cwd: srcPathAbs }
+    { cwd: srcDir }
   ).then(
     (res) => strToLines(res.stdout).map((line) => line.trim().split(':')[0]),
     () => [], // TODO: somehow look at stderr string. if empty, simply no testPaths. if populated, real error
@@ -21,19 +27,19 @@ export default async function main() {
   } else {
     testPaths = strToLines((await capture(
       "find . -mindepth 2 -type f \\( -name '*.ts' -or -name '*.tsx' \\)",
-      { cwd: srcPathAbs }
+      { cwd: srcDir }
     )).stdout)
 
     console.log(`Using all ${testPaths.length} test files.`)
   }
 
-  return `
-    import './index.js';
+  const extensionlessTestPaths = testPaths.map((testPath) => testPath.replace(/\.tsx?$/, ''))
+
+  const templateText = await readFile(templatePath, 'utf8')
+  const template = handlebars.compile(templateText)
+  const code = template({ extensionlessTestPaths })
 
-    ${testPaths.map((testPath) => testPath.replace(/\.tsx?$/, '.js')).map((p) => {
-      return `import '${p}';\n`
-    }).join('\n')}
-  `
+  return code
 }
 
 function strToLines(s) {

+ 5 - 0
tests/src/index.iife.js.tpl

@@ -0,0 +1,5 @@
+import './index.js'
+
+{{#each extensionlessTestPaths}}
+  import '{{this}}.js'
+{{/each}}