Skip to content

Commit 1aba52b

Browse files
atian25popomore
authored andcommitted
fix: use file link && cp ua (#11)
1 parent 360133b commit 1aba52b

File tree

13 files changed

+81
-24
lines changed

13 files changed

+81
-24
lines changed

progressive/step3/example-app/README.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

progressive/step3/example-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"egg": "*",
7-
"egg-ua": "*"
7+
"egg-ua": "../egg-ua"
88
},
99
"devDependencies": {
1010
"egg-bin": "1",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
module.exports = {
4+
get isIOS() {
5+
const iosReg = /iphone|ipad|ipod/i;
6+
return iosReg.test(this.get('user-agent'));
7+
},
8+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "egg-ua",
3+
"version": "1.0.0",
4+
"eggPlugin": {
5+
"name": "ua"
6+
},
7+
"devDependencies": {
8+
"egg": "*",
9+
"egg-bin": "1",
10+
"egg-mock": "2",
11+
"supertest": "2"
12+
},
13+
"scripts": {
14+
"start": "egg-bin dev",
15+
"test": "egg-bin test",
16+
"cov": "egg-bin cov"
17+
}
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
module.exports = app => {
4+
app.get('/', function* () {
5+
this.body = `isIOS: ${this.isIOS}`;
6+
});
7+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "test-app",
3+
"version": "1.0.0"
4+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const request = require('supertest');
4+
const mm = require('egg-mock');
5+
6+
describe('test/ua.test.js', () => {
7+
let app;
8+
9+
before(() => {
10+
app = mm.app({
11+
baseDir: 'test-app',
12+
});
13+
return app.ready();
14+
});
15+
16+
after(() => app.close());
17+
afterEach(mm.restore);
18+
19+
it('should GET / with iOS', () => {
20+
return request(app.callback())
21+
.get('/')
22+
.set('user-agent', 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1')
23+
.expect(200)
24+
.expect('isIOS: true');
25+
});
26+
27+
it('should GET / with non iOS', () => {
28+
return request(app.callback())
29+
.get('/')
30+
.expect(200)
31+
.expect('isIOS: false');
32+
});
33+
});

progressive/step4/example-app/README.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

progressive/step4/example-app/app/router.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ module.exports = app => {
44
app.get('/', function* () {
55
this.body = `isIOS: ${this.isIOS}`;
66
});
7+
8+
app.get('/framework', function* () {
9+
this.body = this.app.config.framework.name;
10+
});
711
};

progressive/step4/example-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"framework": "example-framework"
77
},
88
"dependencies": {
9-
"example-framework": "*"
9+
"example-framework": "../example-framework"
1010
},
1111
"devDependencies": {
1212
"egg-bin": "1",

0 commit comments

Comments
 (0)