Skip to content

Commit

Permalink
fix: fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Jan 23, 2019
1 parent 9879da5 commit de70efa
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/midway-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"main": "lib/command.js",
"devDependencies": {
"coffee": "^5.2.0",
"coffee": "^5.2.1",
"eslint": "^4.13.1",
"eslint-config-egg": "^7.0.0",
"intelli-espower-loader": "^1.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/midway-mock/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EggMock } from 'egg-mock';
import { MidwayApplicationOptions } from './interface';
import { MidwayApplicationOptions, MidwayMockApplication } from './interface';

const mock = require('egg-mock');

Expand All @@ -21,7 +21,7 @@ const mm2: MidwayMock = Object.assign({}, mock, {
container: mockContainer
});

mm2.app = (options) => {
mm2.app = (options): MidwayMockApplication => {
if (process.env.MIDWAY_BASE_DIR && !options.baseDir) options.baseDir = process.env.MIDWAY_BASE_DIR;
if (process.env.MIDWAY_FRAMEWORK_PATH && !options.framework) options.framework = process.env.MIDWAY_FRAMEWORK_PATH;
return mock.app(Object.assign({
Expand Down
5 changes: 5 additions & 0 deletions packages/midway-mock/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { MockApplication } from 'egg-mock';

export interface MidwayApplicationOptions {
baseDir?: string;
framework?: string;
plugins?: any;
container?: any;
typescript?: boolean;
}

export interface MidwayMockApplication extends MockApplication {
}
1 change: 1 addition & 0 deletions packages/midway-mock/test/.setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
// set plugin dir
process.env.PLUGIN_PATH = path.join(__dirname, '../../../');
process.env.MIDWAY_FRAMEWORK_PATH = path.join(__dirname, '../../midway-web/dist/midway.js');
11 changes: 5 additions & 6 deletions packages/midway-mock/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as path from 'path';
const fixtures = path.join(__dirname, 'fixtures');
// app dir
process.env.MIDWAY_BASE_DIR = path.join(fixtures, 'base-app-decorator');
// midway dir
process.env.MIDWAY_FRAMEWORK_PATH = path.join(__dirname, '../../midway');

import { app, mm } from '../bootstrap';
const assert = require('assert');
Expand Down Expand Up @@ -31,28 +29,29 @@ describe('test/index.test.ts', () => {
assert(service.getData() !== 'hello' + ts);
});

it('should use mm.cluster to get app', () => {
it('should use mm.app to get app', () => {
const app = mock.app({
baseDir: process.env.MIDWAY_BASE_DIR,
framework: process.env.MIDWAY_FRAMEWORK_PATH,
});
return app.ready();
});

it('should use mm.cluster to get app', () => {
xit('should use mm.cluster to get app by default options', () => {
mm(process.env, 'MIDWAY_FRAMEWORK_PATH', path.join(__dirname, '../../midway'));
const app = mock.cluster({});
return app.ready();
});

it('should use mm.cluster to get app', () => {
xit('should use mm.cluster to get app', () => {
const app = mock.cluster({
baseDir: process.env.MIDWAY_BASE_DIR,
framework: process.env.MIDWAY_FRAMEWORK_PATH,
});
return app.ready();
});

it('should use mm.cluster to get app', async () => {
it('should init container from app', async () => {
const app = new MockContainer({
baseDir: process.env.MIDWAY_BASE_DIR,
framework: process.env.MIDWAY_FRAMEWORK_PATH,
Expand Down
5 changes: 0 additions & 5 deletions packages/midway-mock/test/mock_container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ const fixtures = path.join(__dirname, 'fixtures');

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

before(() => {
// midway dir
process.env.MIDWAY_FRAMEWORK_PATH = path.join(__dirname, '../../midway');
});

describe('test base app decorator', () => {
let container;
before(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/midway-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
],
"license": "MIT",
"devDependencies": {
"egg-mock": "^3.20.1",
"midway-bin": "^1.0.2",
"midway-mock": "^1.0.5",
"pedding": "^1.1.0"
},
"dependencies": {
Expand Down
6 changes: 4 additions & 2 deletions packages/midway-web/test/enhance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ describe('/test/enhance.test.ts', () => {
describe('auto load js-app-xml test', () => {
let app;
before(() => {
app = utils.app('enhance/js-app-xml',
{baseDir: path.join(__dirname, 'fixtures/enhance/js-app-xml')});
app = utils.app('enhance/js-app-xml', {
baseDir: path.join(__dirname, 'fixtures/enhance/js-app-xml'),
typescript: false,
});
return app.ready();
});

Expand Down
5 changes: 3 additions & 2 deletions packages/midway-web/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const fs = require('fs');
const path = require('path');
const mm = require('egg-mock');
import { mm } from 'midway-mock';

const logDir = path.join(__dirname, '../logs');

process.setMaxListeners(0);
Expand All @@ -14,7 +15,7 @@ if (!fs.existsSync(logDir)) {
export function app(name, options) {
options = formatOptions(name, options);
// mm.consoleLevel(options.consoleLevel || 'NONE');
const app = mm.app(options);
const app: any = mm.app(options);
app.close = () => {
fs.rmdirSync(path.join(app.baseDir, 'run'));
return app.close;
Expand Down
4 changes: 2 additions & 2 deletions packages/midway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Node.js >= 8.0.0 required.
- ✔︎ Sophisticated group Middleware Architecture and compatibility
- ✔︎ Scalable plug-in capabilities and group plug-in Ecology
- ✔︎ Good application layering and decoupling capability
- ✔︎ A good development experience for the future
- ✔︎ Good development experience for the future
- ✔︎ Support Egg plugins and koa middleware


Expand Down Expand Up @@ -79,4 +79,4 @@ This project exists thanks to all the people who contribute. [[Contribute](CONTR

## License

[MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
[MIT](http://github.com/midwayjs/midway/blob/master/LICENSE)

0 comments on commit de70efa

Please sign in to comment.