Skip to content

Commit a7f01d8

Browse files
committed
refactor: use newer syntax for test suites
1 parent 39d2ad3 commit a7f01d8

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

commands/Test.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import { BaseCommand, flags } from '@adonisjs/core/build/standalone'
10+
import { BaseCommand, flags, args } from '@adonisjs/core/build/standalone'
1111
import { JapaFlags } from '../src/Contracts'
1212

1313
/**
@@ -20,6 +20,9 @@ export default class Test extends BaseCommand {
2020
stayAlive: true,
2121
}
2222

23+
@args.spread({ description: 'Run tests for only the specified suites', required: false })
24+
public suites: string[]
25+
2326
/**
2427
* Allows watching for file changes
2528
*/
@@ -44,24 +47,27 @@ export default class Test extends BaseCommand {
4447
@flags.array({ description: 'CLI options to pass to the node command line' })
4548
public nodeArgs: string[] = []
4649

47-
@flags.array({ description: 'Run tests for only specified tags' })
50+
/**
51+
* Filter by tags
52+
*/
53+
@flags.array({ description: 'Filter tests by tags' })
4854
public tags: string[]
4955

50-
@flags.array({ description: 'Run all the tests except the tests using specified tags' })
56+
/**
57+
* Filter by tags
58+
*/
59+
@flags.array({ description: 'Filter tests by ignoring tags' })
5160
public ignoreTags: string[]
5261

53-
@flags.number({ description: 'Define timeout for tests' })
62+
/**
63+
* Customize tests timeout
64+
*/
65+
@flags.number({ description: 'Customize tests timeout' })
5466
public timeout: number
5567

56-
@flags.array({ description: 'Run tests for only the specified suites' })
57-
public suites: string[]
58-
59-
@flags.array({ description: 'Run tests for only the specified groups' })
60-
public groups: string[]
61-
62-
@flags.array({ description: 'Run tests with the specified titles' })
63-
public tests: string[]
64-
68+
/**
69+
* Force exit the tests runner
70+
*/
6571
@flags.boolean({ description: 'Force exit the tests runner process' })
6672
public forceExit: boolean
6773

@@ -78,20 +84,12 @@ export default class Test extends BaseCommand {
7884
filters['--timeout'] = this.timeout
7985
}
8086

81-
if (this.tests) {
82-
filters['--tests'] = this.tests
83-
}
84-
85-
if (this.groups) {
86-
filters['--groups'] = this.groups
87+
if (this.tags) {
88+
filters['--tags'] = this.tags
8789
}
8890

8991
if (this.suites) {
90-
filters['--suites'] = this.suites
91-
}
92-
93-
if (this.tags) {
94-
filters['--tags'] = this.tags
92+
filters._ = this.suites
9593
}
9694

9795
if (this.ignoreTags) {

src/Contracts/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
*/
99

1010
export type JapaFlags = Partial<{
11-
'--tests': string[]
11+
'_': string[]
1212
'--tags': string[]
13-
'--groups': string[]
1413
'--ignore-tags': string[]
1514
'--files': string[]
1615
'--timeout': number
17-
'--suites': string[]
1816
'--force-exit': boolean
1917
}>

src/Test/process.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,32 @@ export class TestProcess {
2626
private logger: typeof uiLogger,
2727
private env: { [key: string]: string } = {}
2828
) {
29-
this.nodeArgs = nodeArgs.reduce((result, arg) => {
29+
this.nodeArgs = nodeArgs.reduce<string[]>((result, arg) => {
3030
result = result.concat(arg.split(' '))
3131
return result
32-
}, [] as string[])
32+
}, [])
3333
}
3434

3535
/**
3636
* Start the HTTP server as a child process.
3737
*/
3838
public async run() {
3939
this.logger.info('running tests...')
40-
const filters = Object.keys(this.filters).reduce((result, filter) => {
40+
const filters = Object.keys(this.filters).reduce<string[]>((result, filter) => {
4141
const value = this.filters[filter]
4242

43-
result.push(filter)
43+
if (filter !== '_') {
44+
result.push(filter)
45+
}
46+
4447
if (Array.isArray(value)) {
4548
result.push(...value)
4649
} else {
4750
result.push(value)
4851
}
4952

5053
return result
51-
}, [] as string[])
54+
}, [])
5255

5356
try {
5457
await execa.node(this.sourceFile, filters, {

0 commit comments

Comments
 (0)