-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes eggjs#16
- Loading branch information
Showing
425 changed files
with
7,886 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
test/fixtures | ||
test/benchmark | ||
examples/**/app/public | ||
logs | ||
run |
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 |
---|---|---|
|
@@ -12,3 +12,5 @@ run | |
.tmp | ||
docs/CONTRIBUTING.md | ||
docs/README.md | ||
|
||
!test/fixtures/apps/loader-plugin/node_modules |
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ install: | |
script: | ||
- npm run ci | ||
after_script: | ||
- npm i codecov && codecov | ||
- npminstall codecov && codecov |
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,47 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const request = require('supertest-as-promised'); | ||
const mm = require('egg-mock'); | ||
|
||
describe('example cookie test', () => { | ||
let app; | ||
|
||
before(() => { | ||
const baseDir = path.dirname(__dirname); | ||
const customEgg = path.join(baseDir, '../..'); | ||
app = mm.app({ | ||
baseDir, | ||
customEgg, | ||
}); | ||
return app.ready(); | ||
}); | ||
|
||
after(() => app.close()); | ||
|
||
it('should GET / show "remember me" checkbox when cookie.remember not exists', () => { | ||
return request(app.callback()) | ||
.get('/') | ||
.expect(200) | ||
.expect(/<input type="checkbox" name="remember"\/> remember me<\/label>/); | ||
}); | ||
|
||
it('should POST /remember to set cookie.remember = 1', () => { | ||
return request(app.callback()) | ||
.post('/remember') | ||
.send({ | ||
remember: 'true', | ||
}) | ||
.expect(302) | ||
.expect('Location', '/') | ||
.expect('Set-Cookie', /^remember=1; path=\/; expires=[^;]+; httponly,remember\.sig=[^;]+; path=\/; expires=[^;]+; httponly$/); | ||
}); | ||
|
||
it('should GET /forget to delete cookie.remember', () => { | ||
return request(app.callback()) | ||
.get('/forget') | ||
.expect(302) | ||
.expect('Location', '/') | ||
.expect('Set-Cookie', /^remember=; path=\/; expires=[^;]+; httponly$/); | ||
}); | ||
}); |
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,43 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const request = require('supertest-as-promised'); | ||
const mm = require('egg-mock'); | ||
|
||
describe('example cookie_session test', () => { | ||
let app; | ||
let cookie; | ||
|
||
before(() => { | ||
const baseDir = path.dirname(__dirname); | ||
const customEgg = path.join(baseDir, '../..'); | ||
app = mm.app({ | ||
baseDir, | ||
customEgg, | ||
}); | ||
return app.ready(); | ||
}); | ||
|
||
after(() => app.close()); | ||
|
||
it('should GET / first time', () => { | ||
return request(app.callback()) | ||
.get('/') | ||
.expect(200) | ||
.expect(/^1 times/) | ||
.expect('Set-Cookie', /^EGG_SESS=[^;]+; path=\/; expires=[^;]+; httponly$/) | ||
.expect(res => { | ||
cookie = res.headers['set-cookie'][0].split(';')[0]; | ||
}); | ||
}); | ||
|
||
it('should GET / second time', () => { | ||
return request(app.callback()) | ||
.get('/') | ||
.set('Cookie', cookie) | ||
.expect(200) | ||
.expect(/^2 times/) | ||
// session.count change | ||
.expect('Set-Cookie', /^EGG_SESS=[^;]+; path=\/; expires=[^;]+; httponly$/); | ||
}); | ||
}); |
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,35 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const request = require('supertest-as-promised'); | ||
const mm = require('egg-mock'); | ||
|
||
describe('example helloworld test', () => { | ||
let app; | ||
|
||
before(() => { | ||
const baseDir = path.dirname(__dirname); | ||
const customEgg = path.join(baseDir, '../..'); | ||
app = mm.app({ | ||
baseDir, | ||
customEgg, | ||
}); | ||
return app.ready(); | ||
}); | ||
|
||
after(() => app.close()); | ||
|
||
it('should GET / 200', () => { | ||
return request(app.callback()) | ||
.get('/') | ||
.expect(200) | ||
.expect('Hello World'); | ||
}); | ||
|
||
it('should GET /foo', () => { | ||
return request(app.callback()) | ||
.get('/foo') | ||
.expect(200) | ||
.expect('Hello foo'); | ||
}); | ||
}); |
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 @@ | ||
'use strict'; | ||
|
||
exports.keys = 'my keys'; |
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,63 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const path = require('path'); | ||
const request = require('supertest-as-promised'); | ||
const mm = require('egg-mock'); | ||
const formstream = require('formstream'); | ||
const urllib = require('urllib'); | ||
|
||
describe.skip('example multipart test', () => { | ||
let app; | ||
let csrfToken; | ||
let cookies; | ||
let host; | ||
let server; | ||
|
||
before(() => { | ||
const baseDir = path.dirname(__dirname); | ||
const customEgg = path.join(baseDir, '../..'); | ||
app = mm.app({ | ||
baseDir, | ||
customEgg, | ||
}); | ||
server = app.listen(); | ||
}); | ||
|
||
after(() => app.close()); | ||
|
||
it('should GET / show upload form', () => { | ||
return request(server) | ||
.get('/') | ||
.expect(200) | ||
.expect(/<p>Image: <input type="file" name="image" \/><\/p>/) | ||
.expect(res => { | ||
console.log(res.headers, res.text); | ||
csrfToken = res.headers['x-csrf']; | ||
cookies = res.headers['set-cookie'].join(';'); | ||
host = `http://127.0.0.1:${server.address().port}`; | ||
}); | ||
}); | ||
|
||
it('should POST /upload success', done => { | ||
const form = formstream(); | ||
form.file('file', __filename); | ||
// other form fields | ||
form.field('title', 'fengmk2 test title') | ||
.field('love', 'egg'); | ||
|
||
const headers = form.headers(); | ||
headers.Cookie = cookies; | ||
urllib.request(`${host}/upload?_csrf=${csrfToken}`, { | ||
method: 'POST', | ||
headers, | ||
stream: form, | ||
dataType: 'json', | ||
}, (err, data, res) => { | ||
assert(!err, err && err.message); | ||
assert.equal(res.statusCode, 200); | ||
console.log(data); | ||
done(); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
app.get('/', 'home'); | ||
app.get('/', app.controller.home); | ||
}; |
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 @@ | ||
'use strict'; | ||
|
||
exports.keys = 'my keys'; |
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,35 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const request = require('supertest-as-promised'); | ||
const mm = require('egg-mock'); | ||
|
||
describe('example static test', () => { | ||
let app; | ||
|
||
before(() => { | ||
const baseDir = path.dirname(__dirname); | ||
const customEgg = path.join(baseDir, '../..'); | ||
app = mm.app({ | ||
baseDir, | ||
customEgg, | ||
}); | ||
return app.ready(); | ||
}); | ||
|
||
after(() => app.close()); | ||
|
||
it('should GET / 200', () => { | ||
return request(app.callback()) | ||
.get('/') | ||
.expect(200) | ||
.expect(/<li>Download <a href="\/public\/hi\.txt">hi\.txt<\/a>\.<\/li>/); | ||
}); | ||
|
||
it('should GET /public/hi.txt', () => { | ||
return request(app.callback()) | ||
.get('/public/hi.txt') | ||
.expect(200) | ||
.expect('hi egg.\n你好,蛋蛋。\n'); | ||
}); | ||
}); |
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
Oops, something went wrong.