-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: auto import tsconfig-paths/register.js (#282)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a new `/foo` route in the application. - Introduced a `Foo` class with a `bar` method. - Enhanced TypeScript path resolution configuration. - **Tests** - Updated test cases to cover new functionality, including the `/foo` endpoint. - Improved test suite with additional assertions and updated expected outputs. - Updated mock dependency to version 6. - **Chores** - Updated TypeScript compiler settings to target ES2022 and refined module resolution strategies. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
10 changed files
with
62 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import { Controller } from 'egg'; | ||
|
||
import { Foo } from '@/module/foo'; | ||
export default class HomeController extends Controller { | ||
public async index() { | ||
const obj: PlainObject = {}; | ||
obj.text = 'hi, egg'; | ||
this.ctx.body = obj.text; | ||
} | ||
|
||
async foo() { | ||
const instance = new Foo(); | ||
this.ctx.body = instance.bar(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class Foo { | ||
public bar() { | ||
return 'bar'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "foo", | ||
"eggModule": { | ||
"name": "foo" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
"typescript": true | ||
}, | ||
"devDependencies": { | ||
"@eggjs/mock": "beta" | ||
"@eggjs/mock": "6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
// @ts-ignore | ||
import { strict as assert } from 'node:assert'; | ||
import { app } from '@eggjs/mock/bootstrap'; | ||
import { Foo } from '@/module/foo' | ||
|
||
describe('test/index.test.ts', () => { | ||
describe('example-ts/test/index.test.ts', () => { | ||
it('should work', async () => { | ||
await app.ready(); | ||
await app.httpRequest() | ||
.get('/') | ||
.expect('hi, egg') | ||
.expect(200); | ||
}); | ||
|
||
it('should paths work', async () => { | ||
await app.ready(); | ||
await app.httpRequest() | ||
.get('/foo') | ||
.expect('bar') | ||
.expect(200); | ||
}); | ||
|
||
it('should auto import tsconfig-paths/register', async () => { | ||
const instance = new Foo(); | ||
assert.equal(instance.bar(), 'bar'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
{ | ||
"extends": "@eggjs/tsconfig" | ||
"extends": "@eggjs/tsconfig", | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"declaration": false, | ||
"paths": { | ||
"@/module/*": ["./app/module/*"] | ||
}, | ||
"baseUrl": "." | ||
} | ||
} |