Skip to content

Commit

Permalink
[koot] polish code of previous update
Browse files Browse the repository at this point in the history
  • Loading branch information
Diablohu committed Mar 28, 2019
1 parent 25984dd commit 60d52c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/koot-webpack/plugins/spa-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
14 changes: 13 additions & 1 deletion test/cases/react-spa/need-in-order.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const commandTestBuild = 'koot-buildtest'

//

//

/**
* 向 package.json 里添加 npm 命令
* @async
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = `<!--:::KOOT:::TEST:::`
+ chunkmap['.files'][checkFilename]
+ fs.readFileSync(path.resolve(dist, chunkmap['.files'][checkFilename]), 'utf-8')
+ `-->`
expect(content.includes(checkString)).toBe(true)
}
})

Expand Down
4 changes: 2 additions & 2 deletions test/projects/standard/server/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ export default {
performanceInfos: () => `<!-- rendered: ${(new Date()).toISOString()} -->`,
spaInjectTest: () => {
if (__SPA__) {
return `<!-- `
return `<!--:::KOOT:::TEST:::`
+ require('koot/utils/get-client-file-path')('specialEntry.js')
+ require('koot/utils/read-client-file')('specialEntry.js')
+ ` -->`
+ `-->`
}
}
}

0 comments on commit 60d52c2

Please sign in to comment.