Skip to content

Commit

Permalink
fix: fix app.root
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Nov 5, 2018
1 parent b1c9b51 commit 33d730c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
1 change: 0 additions & 1 deletion packages/context/src/factory/applicationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ export class BaseApplicationContext extends EventEmitter implements IApplication

try {
return g.to_dot();
// fs.writeSync(imagePath, g.to_dot());
} catch (err) {
console.error('generate injection dependency tree fail, err = ', err.message);
}
Expand Down
10 changes: 10 additions & 0 deletions packages/midway-core/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,14 @@ export class MidwayLoader extends EggLoader {
// 插件加载完毕
this.pluginLoaded = true;
}

getAppInfo() {
if (!this.appInfo) {
const appInfo = super.getAppInfo();
this.appInfo = Object.assign(appInfo, {
root: appInfo.env === 'local' || appInfo.env === 'unittest' ? this.appDir : appInfo.root
});
}
return this.appInfo;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path');
import * as path from 'path';

module.exports = {
// 默认开启的插件
Expand All @@ -10,4 +10,4 @@ module.exports = {
enable: true,
path: path.join(__dirname, '../plugins/plugin2'),
}
};
};
8 changes: 6 additions & 2 deletions packages/midway-core/test/loader.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const assert = require('assert');
const request = require('supertest');
const utils = require('./utils');
const mm = require('mm');
import * as path from 'path';

describe('/test/loader.test.ts', () => {

Expand All @@ -16,6 +16,10 @@ describe('/test/loader.test.ts', () => {

after(() => app.close());

it('should get config merge', () => {
assert(app.config.rundir, path.join(__dirname, './fixtures/enhance/base-app/run'));
});

it('should load ts directory', (done) => {
request(app.callback())
.get('/api')
Expand Down Expand Up @@ -190,7 +194,7 @@ describe('/test/loader.test.ts', () => {
it('disable js app loader should be ok', async () => {
try {
const reqCtx = await app.applicationContext.getAsync('requestContext');
reqCtx.updateContext({ logger: new Console });
reqCtx.updateContext({ logger: console });
reqCtx.get('ctx');
reqCtx.getAsync('logger');
} catch (e) {
Expand Down
4 changes: 4 additions & 0 deletions packages/midway-web/test/enhance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ describe('/test/enhance.test.ts', () => {

after(() => app.close());

it('should get config merge', () => {
assert(app.config.rundir, path.join(__dirname, './fixtures/enhance/base-app/run'));
});

it('should load ts directory', (done) => {
request(app.callback())
.get('/api')
Expand Down

0 comments on commit 33d730c

Please sign in to comment.