diff --git a/package.json b/package.json index 8c0c169..74688f9 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "preReleaseHook": "prepareRelease", "prepareRelease": "npm run clean && npm i && npm run build && npm run bundle && npm run denoify && npm run test && npm run test:deno && npm run test:browser", "test": "npm run test:nodejs && npm run test:jsx-runtime:client && npm run test:jsx-runtime:server", - "test:nodejs": "npm run clean:test && tsc --project tsconfig.test.json && jest \"test/.+\\.test.js$\" && npm run clean:test", + "test:nodejs": "npm run clean:test && tsc --project tsconfig.test.json && node ./test/scripts.mjs add-jest-environment && jest \"test/.+\\.ssr.test.js$\" && npm run clean:test", "test:jsx-runtime:client": "tsc --project tsconfig.test.jsx-runtime.json && jest --coverage=false \"test.jsx-runtime/.+\\.test.js$\"", "test:jsx-runtime:server": "tsc --project tsconfig.test.jsx-runtime.json && node test.jsx-runtime/nodejs/server.js", "test:browser": "rimraf .nyc_output coverage && webpack -c webpack/webpack.bundle.instrumented.js && tsc -p scripts/browserTest/tsconfig.json && node scripts/browserTest/index.mjs --coverage && npx nyc report --exclude \"src/{bundles,dev,htm,ui}/**\" --exclude \"src/mod.ts\" --reporter=text --reporter=html --reporter=lcov", diff --git a/src/ssr.ts b/src/ssr.ts index dc6c1cd..978132b 100644 --- a/src/ssr.ts +++ b/src/ssr.ts @@ -56,7 +56,9 @@ export const renderSSR = (component: any, options: { pathname?: string; clearSta initSSR(pathname) if (clearState) _state.clear() - return render(component, null, true).join('') as string + const tmp = render(component, null, true) as string | string[] + if (Array.isArray(tmp)) return tmp.join('') + else return Array.from(tmp).join('') } export const clearState = () => { diff --git a/test/scripts.mjs b/test/scripts.mjs new file mode 100644 index 0000000..435000d --- /dev/null +++ b/test/scripts.mjs @@ -0,0 +1,31 @@ +// @ts-check + +import { readFile, readdir, writeFile } from "fs/promises" +import { resolve } from "path" + +const args = process.argv.splice(2) +const arg0 = args[0] + +async function* getFiles(dir) { + const dirents = await readdir(dir, { withFileTypes: true }); + for (const dirent of dirents) { + const res = resolve(dir, dirent.name); + if (dirent.isDirectory()) { + yield* getFiles(res); + } else { + yield res; + } + } +} + +if (arg0 === "add-jest-environment") { + const str = "/**\n* @jest-environment node\n*/\n\n" + + for await (const f of getFiles("test")) { + if (/ssr\.test\.js/.test(f)) { + const file = await readFile(f, { encoding: "utf-8" }) + await writeFile(f, str + file, { encoding: "utf-8" }) + } + } + +} \ No newline at end of file