-
Notifications
You must be signed in to change notification settings - Fork 91
test: add testcase #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,3 @@ | ||
| { | ||
| "extends": "eslint-config-egg", | ||
| "rules": { | ||
| "no-console": "off", | ||
| "no-magic-numbers": "off", | ||
| "generator-star-spacing": "off", | ||
| "prefer-template": "off", | ||
| "max-len": "off", | ||
| "dot-notation": "off" | ||
| } | ||
| "extends": "eslint-config-egg" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| /node_modules | ||
| coverage | ||
| .logs | ||
| test | ||
| npm-debug.log | ||
| npm-debug.log |
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| 'use strict'; | ||
|
|
||
| require('should'); | ||
| const path = require('path'); | ||
| const mm = require('mm'); | ||
| const utils = require('./utils'); | ||
| const BaseLoader = require('../index'); | ||
|
|
||
| describe('test/egg_loader.test.js', function() { | ||
|
|
||
| afterEach(mm.restore); | ||
|
|
||
| describe('.getServerEnv', function() { | ||
|
|
||
| it('should get from env EGG_SERVER_ENV', function() { | ||
| mm(process.env, 'EGG_SERVER_ENV', 'prod'); | ||
| const app = utils.createApp('serverenv'); | ||
| app.loader.serverEnv.should.equal('prod'); | ||
| }); | ||
|
|
||
| it('should use unittest when NODE_ENV = test', function() { | ||
| mm(process.env, 'NODE_ENV', 'test'); | ||
| const app = utils.createApp('serverenv'); | ||
| app.loader.serverEnv.should.equal('unittest'); | ||
| }); | ||
|
|
||
| it('should use default when NODE_ENV = production', function() { | ||
| mm(process.env, 'NODE_ENV', 'production'); | ||
| const app = utils.createApp('serverenv'); | ||
| app.loader.serverEnv.should.equal('default'); | ||
| }); | ||
|
|
||
| it('should use local when NODE_ENV is other', function() { | ||
| mm(process.env, 'NODE_ENV', 'development'); | ||
| const app = utils.createApp('serverenv'); | ||
| app.loader.serverEnv.should.equal('local'); | ||
| }); | ||
|
|
||
| it('should get from config/serverEnv', function() { | ||
| mm(process.env, 'NODE_ENV', 'production'); | ||
| mm(process.env, 'EGG_SERVER_ENV', 'test'); | ||
| const app = utils.createApp('serverenv-file'); | ||
| app.loader.serverEnv.should.equal('prod'); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| describe('eggPaths', function() { | ||
|
|
||
| it('should get from paramter', function() { | ||
| const app = utils.createApp('eggpath'); | ||
| app.loader.eggPath.should.equal(utils.getFilepath('egg')); | ||
| }); | ||
|
|
||
| it('should get from framework', function() { | ||
| const Application = require('./fixtures/framework'); | ||
| const app = new Application(); | ||
| app.coreLogger = console; | ||
| app.loader = new utils.Loader('eggpath', { app }); | ||
| app.loader.loadConfig(); | ||
| app.loader.eggPaths.should.eql([ | ||
| utils.getFilepath('egg'), | ||
| utils.getFilepath('framework/node_modules/framework2'), | ||
| utils.getFilepath('framework'), | ||
| ]); | ||
| return app; | ||
| }); | ||
|
|
||
| it('should get from framework using symbol', function() { | ||
| const Application = require('./fixtures/framework-symbol'); | ||
| const app = new Application(); | ||
| app.coreLogger = console; | ||
| app.loader = new utils.Loader('eggpath', { app }); | ||
| app.loader.loadConfig(); | ||
| app.loader.eggPaths.should.eql([ | ||
| utils.getFilepath('egg'), | ||
| utils.getFilepath('framework-symbol/node_modules/framework2'), | ||
| utils.getFilepath('framework-symbol'), | ||
| ]); | ||
| return app; | ||
| }); | ||
|
|
||
| it('frameworkPaths should not container eggPath', function() { | ||
| const eggPath = path.join(__dirname, 'fixtures/egg'); | ||
| const loader = new BaseLoader({ | ||
| baseDir: path.join(__dirname, 'fixtures/eggpath'), | ||
| eggPath, | ||
| customEgg: eggPath, | ||
| }); | ||
| loader.frameworkPaths.should.not.containEql(eggPath); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| describe('loadDirs', function() { | ||
|
|
||
| it('should get plugin dir', function() { | ||
| const app = utils.createApp('plugin'); | ||
| const dirs = app.loader.loadDirs(); | ||
| dirs.length.should.eql(10); | ||
| }); | ||
|
|
||
| it('should not get plugin dir', function() { | ||
| const loader = new utils.Loader('plugin'); | ||
| const dirs = loader.loadDirs(); | ||
| dirs.length.should.eql(2); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| describe('loadFile', function() { | ||
| it('should throw with filepath when file syntax error', function() { | ||
| (function() { | ||
| utils.createApp('syntaxerror'); | ||
| }).should.throw(/test\/fixtures\/syntaxerror\/app\.js error:/); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| foo: 'agent bar', | ||
| bar: 'foo' | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = {}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| a: true, | ||
| b: true, | ||
| }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "name": "application" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| const path = require('path'); | ||
|
|
||
| exports.foo = { | ||
| enable: true, | ||
| type: ['ali'], | ||
| path: path.join(__dirname, '../../../plugins/test-me') | ||
| }; | ||
|
|
||
| exports.fooalipay = { | ||
| enable: true, | ||
| type: ['alipay'], | ||
| path: path.join(__dirname, '../../../plugins/test-me2') | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "ali-plugin", | ||
| "chair": { | ||
| "type": "ali" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| foo: 'app bar', | ||
| bar: 'foo' | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = {}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| a: true, | ||
| b: true, | ||
| }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "name": "application" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| egg: 'config-default', | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "name": "config-env" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| 'use strict'; | ||
|
|
||
| var util = require('./util/a'); | ||
| module.exports = function() { | ||
| return { | ||
| a: function*() { | ||
| util.b(); | ||
| this.body = 'hello'; | ||
| } | ||
| }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module.exports = { | ||
| a: 1, | ||
| b: function() { | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| 'use strict'; | ||
| var util = require('./util/bar'); | ||
|
|
||
| module.exports = function() { | ||
| return { | ||
| bar: function*(ctx) { | ||
| console.log(ctx); | ||
| } | ||
| }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exports.a = 1; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| 'use strict'; | ||
|
|
||
| exports.loader = { | ||
| service: { ignore: 'util/**' }, | ||
| controller: { ignore: 'util/**' } | ||
| }; | ||
|
|
||
| exports.name = 'config-test'; | ||
|
|
||
| exports.test = 1; | ||
|
|
||
| exports.urllib = { | ||
| keepAlive: false | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "name": "loader_config" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = function(app) { | ||
| app.get('/', function*() { | ||
| this.body = { | ||
| customFoo: app.customFoo, | ||
| env: app.config.env, | ||
| eggPaths: app.loader.eggPaths, | ||
| frameworkPaths: app.loader.frameworkPaths, | ||
| eggPath: app.loader.eggPath, | ||
| }; | ||
| }); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个应该加回来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个主要是给单测时候用的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是,默认入口要加上,会去重的。