-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
const Controller = require('egg').Controller; | ||
|
||
class HomeController extends Controller { | ||
async index() { | ||
await this.ctx.render('index.js', { | ||
data: 1, | ||
}); | ||
} | ||
} | ||
|
||
module.exports = HomeController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
|
||
/* global window */ | ||
console.log('data:', window.context.data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { router, controller } = app; | ||
|
||
router.get('/', controller.home.index); | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
{{ helper.assets.getStyle() | safe }} | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script>window.atob = undefined;</script> | ||
{{ helper.assets.getContext() | safe }} | ||
{{ helper.assets.getScript() | safe }} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
exports.keys = '123456'; | ||
exports.view = { | ||
mapping: { | ||
'.js': 'assets', | ||
'.jsx': 'assets', | ||
}, | ||
}; | ||
exports.assets = { | ||
publicPath: '/public/', | ||
templateViewEngine: 'nunjucks', | ||
templatePath: path.join(__dirname, '../app/view/layout.html'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"index.js": "index.js", | ||
"index.css": "index.css" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
nunjucks: { | ||
enable: true, | ||
package: 'egg-view-nunjucks', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "egg-view-assets" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const mock = require('egg-mock'); | ||
const puppeteer = require('puppeteer'); | ||
const sleep = require('mz-modules/sleep'); | ||
const assert = require('assert'); | ||
|
||
|
||
describe('test/ui.test.js', () => { | ||
let app; | ||
before(() => { | ||
mock.env('default'); | ||
app = mock.cluster({ | ||
baseDir: 'apps/ui', | ||
port: 7001, | ||
}); | ||
app.debug(); | ||
return app.ready(); | ||
}); | ||
after(() => app.close()); | ||
after(mock.restore); | ||
|
||
it('should request index.js', async () => { | ||
await app.httpRequest() | ||
.get('/public/index.js') | ||
.expect(/window.context.data/) | ||
.expect(200); | ||
}); | ||
|
||
it('should render html', async () => { | ||
await app.httpRequest() | ||
.get('/') | ||
.expect(/var atob = window.atob || function\(input\) {/) | ||
.expect(200); | ||
}); | ||
|
||
it('should console', async () => { | ||
const browser = await puppeteer.launch({ | ||
args: [ '--no-sandbox', '--disable-setuid-sandbox' ], | ||
}); | ||
const page = await browser.newPage(); | ||
let text = ''; | ||
page.on('console', msg => (text += msg.text())); | ||
await page.goto('http://127.0.0.1:7001'); | ||
|
||
await sleep(5000); | ||
assert(text === 'data: 1'); | ||
}); | ||
|
||
}); |