Skip to content

Commit

Permalink
fix: jest support (#466)
Browse files Browse the repository at this point in the history
* fix: jest support

* fix: jest exit

* fix: midway-mock test

* feat: add editorconfig
  • Loading branch information
Lxxyx committed Apr 9, 2020
1 parent 222b6db commit 2d176cf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
@@ -0,0 +1,11 @@
# 🎨 editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 1 addition & 1 deletion docs/en/guide.md
Expand Up @@ -836,7 +836,7 @@ module.exports = {
```json
{
"scripts": {
"test": "jest"
"test": "jest --forceExit"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/guide.md
Expand Up @@ -857,7 +857,7 @@ module.exports = {
```json
{
"scripts": {
"test": "jest"
"test": "jest --forceExit"
}
}
```
Expand Down
1 change: 1 addition & 0 deletions packages/midway-bin/jest/env.js
Expand Up @@ -10,6 +10,7 @@ class JestEnvironment extends NodeEnvironment {
async setup() {
require('ts-node/register');
this.global.process.env.MIDWAY_TS_MODE = 'true';
this.global.process.env.MIDWAY_JEST_MODE = 'true';
await super.setup();
}

Expand Down
11 changes: 9 additions & 2 deletions packages/midway-mock/src/bootstrap.ts
Expand Up @@ -2,12 +2,19 @@ import * as assert from 'power-assert';
import { MidwayMockApplication } from './interface';
import { MidwayMock, mm as mock } from './mock';

const isJest = process.env.MIDWAY_JEST_MODE === 'true';

// 由于使用Object.assign,丢了默认的mm执行函数,所以使用default输出mm
export const mm: MidwayMock['default'] = mock.default;

export const app: MidwayMockApplication = mock.app({});
export const app: MidwayMockApplication = mock.app(isJest ? {typescript: true} : {});

if (isJest) {
(global as any).beforeAll(app.ready);
} else {
before(app.ready);
}

before(app.ready);
afterEach(mock.restore);

export {
Expand Down

0 comments on commit 2d176cf

Please sign in to comment.