Skip to content

Commit

Permalink
test: add more tests (#283)
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**
- Enhanced test command to support running tests from multiple files
simultaneously
- Added example demonstrating how to specify multiple test files in a
single command

- **Documentation**
- Updated command examples to clarify usage of test and coverage
commands with multiple files

- **Tests**
- Added new test case to validate running tests with multiple file
inputs

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Jan 3, 2025
1 parent e91ccbe commit fe6738f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/commands/cov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class Cov<T extends typeof Cov> extends Test<T> {
static override examples = [
'<%= config.bin %> <%= command.id %>',
'<%= config.bin %> <%= command.id %> test/index.test.ts',
'<%= config.bin %> <%= command.id %> test/index.test.ts,test/user.test.ts,...',
];

static override flags = {
Expand Down
1 change: 1 addition & 0 deletions src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class Test<T extends typeof Test> extends BaseCommand<T> {
static override examples = [
'<%= config.bin %> <%= command.id %>',
'<%= config.bin %> <%= command.id %> test/index.test.ts',
'<%= config.bin %> <%= command.id %> test/index.test.ts,test/user.test.ts,...',
'<%= config.bin %> <%= command.id %> --json',
'<%= config.bin %> <%= command.id %> --log-level debug',
];
Expand Down
23 changes: 20 additions & 3 deletions test/commands/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('test/commands/test.test.ts', () => {
describe('egg-bin test', () => {
it('should success js', () => {
return coffee.fork(eggBin, [ 'test' ], { cwd })
.debug()
// .debug()
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /b\/b\.test\.js/)
Expand All @@ -20,12 +20,29 @@ describe('test/commands/test.test.ts', () => {
.end();
});

it('should success with some files', async () => {
await coffee.fork(eggBin, [ 'test', 'test/a.test.js' ], { cwd })
// .debug()
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /2 passing \(/)
.expect('code', 0)
.end();
await coffee.fork(eggBin, [ 'test', 'test/a.test.js,test/ignore.test.js' ], { cwd })
// .debug()
.expect('stdout', /should success/)
.expect('stdout', /a\.test\.js/)
.expect('stdout', /ignore\.test\.js/)
.expect('code', 0)
.end();
});

it('should work on auto require @eggjs/mock/register on CommonJS', () => {
if (process.platform === 'win32') return;
return coffee.fork(eggBin, [ 'test' ], {
cwd: getFixtures('test-demo-app'),
})
.debug()
// .debug()
.expect('stdout', /should work/)
.expect('stdout', /a\.test\.js/)
.expect('code', 0)
Expand All @@ -37,7 +54,7 @@ describe('test/commands/test.test.ts', () => {
return coffee.fork(eggBin, [ 'test' ], {
cwd: getFixtures('test-demo-app-esm'),
})
.debug()
// .debug()
.expect('stdout', /should work/)
.expect('stdout', /a\.test\.js/)
.expect('code', 0)
Expand Down

0 comments on commit fe6738f

Please sign in to comment.