Skip to content

Commit 59d697e

Browse files
author
xiaochen.gaoxc
committed
feat: add egg-ons plugin
1 parent 83bd685 commit 59d697e

File tree

6 files changed

+43
-51
lines changed

6 files changed

+43
-51
lines changed

.autod.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module.exports = {
44
write: true,
55
prefix: '^',
6+
plugin: 'autod-egg',
67
test: [
78
'test',
89
'benchmark',
@@ -17,10 +18,9 @@ module.exports = {
1718
devdep: [
1819
'egg-bin',
1920
'autod',
21+
'autod-egg',
2022
'eslint',
2123
'eslint-config-egg',
22-
'supertest',
23-
'ali-oss',
2424
],
2525
exclude: [
2626
'./test/fixtures',

.eslintrc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"extends": "eslint-config-egg",
3-
"rules": {
4-
"no-unused-vars": "off"
5-
}
6-
}
2+
"extends": "eslint-config-egg"
3+
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sudo: false
22
language: node_js
33
node_js:
44
- '6'
5-
- '7'
5+
- '8'
66
install:
77
- npm i npminstall && npminstall
88
script:

config/plugin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ module.exports = {
1313
enable: true,
1414
package: 'egg-mysql',
1515
},
16-
16+
ons: {
17+
enable: true,
18+
package: 'egg-ons',
19+
},
1720
nunjucks: {
1821
enable: true,
1922
package: 'egg-view-nunjucks',

package.json

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "1.0.0",
44
"description": "egg framework for aliyun",
55
"keywords": [
6-
"egg", "egg-framework", "aliyun"
6+
"egg",
7+
"egg-framework",
8+
"aliyun"
79
],
810
"files": [
911
"index.js",
@@ -13,40 +15,41 @@
1315
"config"
1416
],
1517
"dependencies": {
16-
"egg": "^1.0.0-rc.3",
17-
"egg-alinode": "^1.1.0",
18-
"egg-mysql": "^2.0.0",
19-
"egg-oss": "^1.0.1",
20-
"egg-view-nunjucks": "^2.0.0"
18+
"egg": "^1.9.0",
19+
"egg-alinode": "^1.1.1",
20+
"egg-mysql": "^3.0.0",
21+
"egg-ons": "^1.0.0",
22+
"egg-oss": "^1.1.0",
23+
"egg-view-nunjucks": "^2.1.4"
2124
},
2225
"devDependencies": {
23-
"ali-oss": "^4.8.0",
24-
"autod": "^2.7.1",
25-
"egg-bin": "^2.4.0",
26-
"egg-mock": "^3.2.0",
27-
"eslint": "^3.17.1",
28-
"eslint-config-egg": "^3.2.0",
29-
"rimraf": "^2.6.1",
30-
"supertest": "^3.0.0"
26+
"autod": "^2.10.1",
27+
"autod-egg": "^1.0.0",
28+
"egg-bin": "^4.3.5",
29+
"egg-mock": "^3.13.1",
30+
"eslint": "^4.9.0",
31+
"eslint-config-egg": "^5.1.1",
32+
"rimraf": "^2.6.2"
3133
},
3234
"engines": {
3335
"node": ">=6.0.0"
3436
},
3537
"scripts": {
38+
"autod": "autod",
39+
"pkgfiles": "egg-bin pkgfiles --check",
3640
"test": "npm run lint -- --fix && npm run test-local",
3741
"test-local": "egg-bin test ",
3842
"cov": "egg-bin cov",
39-
"lint": "eslint .",
40-
"ci": "npm run lint && npm run cov",
41-
"autod": "autod"
43+
"lint": "eslint . --fix",
44+
"ci": "npm run autod -- --check && npm run pkgfiles && npm run lint && npm run cov"
4245
},
4346
"ci": {
44-
"version": "6, 7"
47+
"version": "6, 8"
4548
},
4649
"repository": {
4750
"type": "git",
4851
"url": "https://github.com/eggjs/aliyun-egg"
4952
},
5053
"author": "jtyjty99999 <[email protected]> (http://github.com/jtyjty99999)",
5154
"license": "MIT"
52-
}
55+
}

test/aliyun-egg.test.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
'use strict';
22

3-
const request = require('supertest');
43
const mm = require('egg-mock');
5-
const oss = require('ali-oss');
6-
const config = require('./fixtures/apps/oss/config/config.default').oss.client;
74
const assert = require('assert');
85
const env = process.env;
96
const region = env.ALI_SDK_OSS_REGION || 'oss-cn-hangzhou';
@@ -16,15 +13,17 @@ describe('test/aliyun-egg.test.js', () => {
1613
app = utils.createApp('apps/web');
1714
return app.ready();
1815
});
16+
afterEach(mm.restore);
17+
after(() => app.close());
1918

2019
it('should render', () => {
21-
return request(app.callback())
20+
return app.httpRequest()
2221
.get('/home')
2322
.expect('world')
2423
.expect(200);
2524
});
2625
it('should render by default template nunjucks', () => {
27-
return request(app.callback())
26+
return app.httpRequest()
2827
.get('/home2')
2928
.expect('world2')
3029
.expect(200);
@@ -34,34 +33,22 @@ describe('test/aliyun-egg.test.js', () => {
3433
describe('oss plugin test', () => {
3534
let app;
3635
let lastUploadFileName;
37-
let url;
36+
const bucket = 'ali-oss-test-bucket-test99';
37+
const url = 'http://' + bucket + '.' + region + '.aliyuncs.com';
3838
before(function* () {
39-
const ossConfig = {
40-
accessKeyId: config.accessKeyId,
41-
accessKeySecret: config.accessKeySecret,
42-
endpoint: config.endpoint,
43-
region,
44-
callbackServer: 'http://d.rockuw.com:4567',
45-
};
46-
const store = oss(ossConfig);
47-
const bucket = 'ali-oss-test-bucket-test99';
48-
url = 'http://' + bucket + '.' + region + '.aliyuncs.com';
49-
const result = yield store.putBucket(bucket, region);
50-
assert(result.bucket === bucket);
51-
assert(result.res.status === 200);
5239
app = utils.createApp('apps/oss');
5340
return app.ready();
5441
});
55-
42+
afterEach(mm.restore);
5643
after(function* () {
5744
if (lastUploadFileName) {
5845
yield app.oss.delete(lastUploadFileName);
5946
}
60-
app.close();
47+
yield app.close();
6148
});
6249

6350
it('should upload file stream to oss', function* () {
64-
const result = yield request(app.callback()).get('/uploadtest').expect(200);
51+
const result = yield app.httpRequest().get('/uploadtest').expect(200);
6552
lastUploadFileName = result.body.name;
6653
const reg = new RegExp('^' + url);
6754
assert(typeof result.body.name === 'string');
@@ -76,9 +63,11 @@ describe('test/aliyun-egg.test.js', () => {
7663
app = utils.createApp('apps/mysqlapp-new');
7764
return app.ready();
7865
});
66+
afterEach(mm.restore);
67+
after(() => app.close());
7968

8069
it('should query', () => {
81-
return request(app.callback())
70+
return app.httpRequest()
8271
.get('/')
8372
.expect(200);
8473
});

0 commit comments

Comments
 (0)