From 60d52c2fe446b5ef04004ab3d49fe78599e3ebb7 Mon Sep 17 00:00:00 2001 From: Diablohu Date: Thu, 28 Mar 2019 18:39:37 +0800 Subject: [PATCH] [koot] polish code of previous update --- packages/koot-webpack/plugins/spa-template.js | 6 ++++-- test/cases/react-spa/need-in-order.test.js | 14 +++++++++++++- test/projects/standard/server/inject.js | 4 ++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/koot-webpack/plugins/spa-template.js b/packages/koot-webpack/plugins/spa-template.js index 54b50ae3..3a70561a 100644 --- a/packages/koot-webpack/plugins/spa-template.js +++ b/packages/koot-webpack/plugins/spa-template.js @@ -125,8 +125,10 @@ class SpaTemplatePlugin { const html = renderTemplate({ template, - // inject: Object.assign({}, defaultInject, require(path.resolve(getCwd(), inject))), - inject: eval(fs.readFileSync(inject, 'utf-8')).default, + inject: { + ...defaultInject, + ...eval(fs.readFileSync(inject, 'utf-8')).default + }, compilation }) diff --git a/test/cases/react-spa/need-in-order.test.js b/test/cases/react-spa/need-in-order.test.js index 350dfec9..05ab7d6a 100644 --- a/test/cases/react-spa/need-in-order.test.js +++ b/test/cases/react-spa/need-in-order.test.js @@ -27,6 +27,8 @@ const commandTestBuild = 'koot-buildtest' // +// + /** * 向 package.json 里添加 npm 命令 * @async @@ -80,6 +82,7 @@ describe('测试: React SPA 项目', () => { const distDirName = 'dist-spa-test' const dist = path.resolve(dir, distDirName) const fileIndexHtml = path.resolve(dist, 'index.html') + const chunkmap = fs.readJsonSync(require('../../../packages/koot/utils/get-chunkmap-path')(dist)) if (fs.existsSync(dist)) fs.emptyDirSync(dist) @@ -113,11 +116,20 @@ describe('测试: React SPA 项目', () => { expect(exist).toBe(true) if (exist) { - const dom = new JSDOM(fs.readFileSync(fileIndexHtml)) + const content = fs.readFileSync(fileIndexHtml) + const dom = new JSDOM(content) const config = require(path.resolve(dir, 'koot.config.js')) expect( dom.window.document.querySelector('title').textContent ).toBe(config.name) + + // 测试: HTML 注入 (动态) + const checkFilename = 'specialEntry.js' + const checkString = `` + expect(content.includes(checkString)).toBe(true) } }) diff --git a/test/projects/standard/server/inject.js b/test/projects/standard/server/inject.js index c1af60c3..ca386f63 100644 --- a/test/projects/standard/server/inject.js +++ b/test/projects/standard/server/inject.js @@ -2,10 +2,10 @@ export default { performanceInfos: () => ``, spaInjectTest: () => { if (__SPA__) { - return `` + + `-->` } } }