Skip to content

Commit

Permalink
fix: support simple test on normal app (#179)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
	- Added "PRs Welcome" badge to README files.
	- Added Node.js version badge to Chinese README.
	- Introduced a simple GET route in the new "helloworld" application.
	- Established basic configuration for the "helloworld" application.
	- Created a new `package.json` for the "helloworld" application.
- Added a test suite for validating the bootstrap functionality of the
"helloworld" application.

- **Documentation**
	- Updated README files with project badges.

- **Chores**
	- Modified test configurations for ESM support.
	- Updated import paths in type definition files.
	- Created a new test fixture application "helloworld".

- **Refactor**
	- Removed `src/index.d.ts` type definitions.
	- Updated `src/bootstrap.ts` to export app instance.
	- Modified `src/lib/app_handler.ts` to ensure app return.
- Refactored test cases in `test/app.test.ts` for improved readability
and maintainability.
	- Updated test suite in `test/app_proxy.test.ts` to run all tests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Dec 29, 2024
1 parent 45a34bd commit 3b0957f
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 307 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest'
version: '18.19.0, 18, 20, 22, 23'
version: '18.19.0, 18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@eggjs/mock.svg?style=flat)](https://nodejs.org/en/download/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

[npm-image]: https://img.shields.io/npm/v/@eggjs/mock.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/mock
Expand Down
2 changes: 2 additions & 0 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[![Node.js CI](https://github.com/eggjs/mock/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/mock/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@eggjs/mock.svg?style=flat)](https://nodejs.org/en/download/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

[npm-image]: https://img.shields.io/npm/v/@eggjs/mock.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/mock
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"@types/mocha": "10",
"@types/node": "22",
"egg": "beta",
"egg-bin": "beta",
"egg-errors": "^2.2.1",
"egg-tracer": "^2.0.0",
"eslint": "8",
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ if (pkgInfo.eggPlugin) {
throw new Error('DO NOT USE bootstrap to test plugin');
}

setupApp();
const app = setupApp();

export {
assert,
getBootstrapApp,
app,
mm,
mock,
MockApplication,
Expand Down
193 changes: 0 additions & 193 deletions src/index.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/lib/app_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function setupApp() {
afterEach(restore);
}
}
return app;
}

let getAppCallback: (suite: unknown, test?: unknown) => any;
Expand Down
11 changes: 3 additions & 8 deletions test/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { strict as assert } from 'node:assert';
import mm, { MockApplication } from '../src/index.js';
import { getFixtures } from './helper.js';
import { pending } from 'pedding';

describe('test/app.test.ts', () => {
afterEach(mm.restore);
Expand Down Expand Up @@ -91,15 +90,11 @@ describe('test/app.test.ts', () => {
assert((app.options as any).test === 'abc');
});

it('should emit error when load Application fail', done => {
done = pending(2, done);
it('should emit error when load Application fail', async () => {
const baseDir = getFixtures('app-fail');
const app = mm.app({ baseDir, cache: false });
app.once('error', (err: any) => {
app.close().then(() => done);
assert(/load error/.test(err.message));
done();
});
await assert.rejects(app.ready(), /load error/);
await app.close();
});

it('should FrameworkErrorformater work during app boot', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/app_proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe('test/app_proxy.test.ts', () => {
});
});

describe.only('messenger binding on cluster() mode', () => {
describe('messenger binding on cluster() mode', () => {
let app: MockApplication;
const baseDir = getFixtures('messenger-binding');
before(() => {
Expand Down
Loading

0 comments on commit 3b0957f

Please sign in to comment.