@adonisjs/core 5.5.3 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/adonis-typings/index.d.ts +1 -0
- package/build/adonis-typings/index.js +1 -0
- package/build/adonis-typings/tests.d.ts +13 -0
- package/build/{src/TestUtils/Ace/index.js → adonis-typings/tests.js} +4 -1
- package/build/commands/ListRoutes/Renderers/Base.d.ts +31 -0
- package/build/commands/ListRoutes/Renderers/Base.js +70 -0
- package/build/commands/ListRoutes/Renderers/PrettyRenderer.d.ts +51 -0
- package/build/commands/ListRoutes/Renderers/PrettyRenderer.js +135 -0
- package/build/commands/ListRoutes/Renderers/TableRenderer.d.ts +36 -0
- package/build/commands/ListRoutes/Renderers/TableRenderer.js +137 -0
- package/build/commands/ListRoutes/index.d.ts +73 -0
- package/build/commands/ListRoutes/index.js +164 -0
- package/build/commands/index.js +1 -1
- package/build/providers/AppProvider.d.ts +4 -0
- package/build/providers/AppProvider.js +10 -0
- package/build/src/Bindings/Repl.d.ts +1 -0
- package/build/src/Bindings/Tests.d.ts +6 -0
- package/build/src/Bindings/Tests.js +66 -0
- package/build/templates/contracts/tests.txt +16 -0
- package/build/templates/tests/bootstrap.txt +9 -11
- package/build/templates/tests.txt +44 -0
- package/package.json +22 -21
- package/build/commands/ListRoutes.d.ts +0 -28
- package/build/commands/ListRoutes.js +0 -116
- package/build/src/TestUtils/Ace/index.d.ts +0 -0
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
/// <reference path="assets-manager.d.ts" />
|
|
7
7
|
/// <reference path="container.d.ts" />
|
|
8
8
|
/// <reference path="test-utils.d.ts" />
|
|
9
|
+
/// <reference path="tests.d.ts" />
|
|
9
10
|
/// <reference types="@adonisjs/application/build/adonis-typings" />
|
|
10
11
|
/// <reference types="@adonisjs/events/build/adonis-typings" />
|
|
11
12
|
/// <reference types="@adonisjs/hash/build/adonis-typings" />
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '@japa/api-client';
|
|
2
|
+
declare module '@japa/api-client' {
|
|
3
|
+
interface ApiRequest {
|
|
4
|
+
/**
|
|
5
|
+
* Define encrypted cookie
|
|
6
|
+
*/
|
|
7
|
+
encryptedCookie(key: string, value: any): this;
|
|
8
|
+
/**
|
|
9
|
+
* Define plain cookie
|
|
10
|
+
*/
|
|
11
|
+
plainCookie(key: string, value: any): this;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*
|
|
2
3
|
* @adonisjs/core
|
|
3
4
|
*
|
|
4
|
-
* (c)
|
|
5
|
+
* (c) AdonisJS
|
|
5
6
|
*
|
|
6
7
|
* For the full copyright and license information, please view the LICENSE
|
|
7
8
|
* file that was distributed with this source code.
|
|
8
9
|
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
require("@japa/api-client");
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/build/standalone';
|
|
2
|
+
import ListRoutes from '..';
|
|
3
|
+
export declare class BaseRender {
|
|
4
|
+
protected command: ListRoutes;
|
|
5
|
+
constructor(command: ListRoutes);
|
|
6
|
+
/**
|
|
7
|
+
* The colors associated with each HTTP method
|
|
8
|
+
*/
|
|
9
|
+
private methodColors;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the color name for a HTTP method
|
|
12
|
+
*/
|
|
13
|
+
getHttpMethodColor(method: string): keyof BaseCommand['colors'];
|
|
14
|
+
/**
|
|
15
|
+
* Find if the route contains all the methods registered by
|
|
16
|
+
* the "Route.any" method
|
|
17
|
+
*/
|
|
18
|
+
hasAllMethods(methods: string[]): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Colorize the route methods
|
|
21
|
+
*/
|
|
22
|
+
colorizeRouteMethods(methods: string[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Colorize the route pattern
|
|
25
|
+
*/
|
|
26
|
+
colorizeRoutePattern(pattern: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the rendering width.
|
|
29
|
+
*/
|
|
30
|
+
getRenderingWidth(): number;
|
|
31
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* @adonisjs/core
|
|
4
|
+
*
|
|
5
|
+
* (c) AdonisJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.BaseRender = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Methods registered by "Route.any" method
|
|
14
|
+
*/
|
|
15
|
+
const ALL_METHODS = ['HEAD', 'OPTIONS', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
16
|
+
class BaseRender {
|
|
17
|
+
constructor(command) {
|
|
18
|
+
this.command = command;
|
|
19
|
+
/**
|
|
20
|
+
* The colors associated with each HTTP method
|
|
21
|
+
*/
|
|
22
|
+
this.methodColors = {
|
|
23
|
+
GET: 'cyan',
|
|
24
|
+
POST: 'green',
|
|
25
|
+
PUT: 'yellow',
|
|
26
|
+
PATCH: 'yellow',
|
|
27
|
+
DELETE: 'red',
|
|
28
|
+
HEAD: 'gray',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns the color name for a HTTP method
|
|
33
|
+
*/
|
|
34
|
+
getHttpMethodColor(method) {
|
|
35
|
+
const methodColor = this.methodColors[method];
|
|
36
|
+
return methodColor ? methodColor : 'gray';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Find if the route contains all the methods registered by
|
|
40
|
+
* the "Route.any" method
|
|
41
|
+
*/
|
|
42
|
+
hasAllMethods(methods) {
|
|
43
|
+
return ALL_METHODS.every((method) => methods.includes(method));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Colorize the route methods
|
|
47
|
+
*/
|
|
48
|
+
colorizeRouteMethods(methods) {
|
|
49
|
+
return this.hasAllMethods(methods)
|
|
50
|
+
? this.command.colors.cyan('ANY')
|
|
51
|
+
: methods
|
|
52
|
+
.map((method) => this.command.colors[this.getHttpMethodColor(method)](method))
|
|
53
|
+
.join(this.command.colors.gray('|'));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Colorize the route pattern
|
|
57
|
+
*/
|
|
58
|
+
colorizeRoutePattern(pattern) {
|
|
59
|
+
return pattern
|
|
60
|
+
.replace(/:([^/]+)/gm, `${this.command.colors.yellow('$&')}`)
|
|
61
|
+
.replace(/\*/gm, `${this.command.colors.red('$&')}`);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns the rendering width.
|
|
65
|
+
*/
|
|
66
|
+
getRenderingWidth() {
|
|
67
|
+
return this.command.maxWidth || process.stdout.columns || 80;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.BaseRender = BaseRender;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BaseRender } from './Base';
|
|
2
|
+
import ListRoutes from '../index';
|
|
3
|
+
/**
|
|
4
|
+
* Renders the routes as a pretty list
|
|
5
|
+
*/
|
|
6
|
+
export declare class RoutesPrettyRenderer extends BaseRender {
|
|
7
|
+
private routes;
|
|
8
|
+
private renderingWidth;
|
|
9
|
+
private longestMethodName;
|
|
10
|
+
constructor(command: ListRoutes);
|
|
11
|
+
/**
|
|
12
|
+
* Returns a list of serialized routes
|
|
13
|
+
*/
|
|
14
|
+
private serializeRotues;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the name of the longest method name
|
|
17
|
+
* across all the routes
|
|
18
|
+
*/
|
|
19
|
+
private findLongestMethodName;
|
|
20
|
+
/**
|
|
21
|
+
* Render a single route by concatenating and colorizing each part of it
|
|
22
|
+
*/
|
|
23
|
+
private outputRoute;
|
|
24
|
+
/**
|
|
25
|
+
* Log message
|
|
26
|
+
*/
|
|
27
|
+
private log;
|
|
28
|
+
/**
|
|
29
|
+
* Crop the handler name
|
|
30
|
+
*/
|
|
31
|
+
private cropHandlerName;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the whitespace to be rendered between the
|
|
34
|
+
* route methods and the route pattern
|
|
35
|
+
*/
|
|
36
|
+
private getWhiteSpace;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the rendering width with and without the
|
|
39
|
+
* route handler
|
|
40
|
+
*/
|
|
41
|
+
private getRenderingWidths;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the dashes to be rendered between pattern and the
|
|
44
|
+
* route handler name.
|
|
45
|
+
*/
|
|
46
|
+
private getDashes;
|
|
47
|
+
/**
|
|
48
|
+
* Renders routes to the console
|
|
49
|
+
*/
|
|
50
|
+
render(): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* @adonisjs/core
|
|
4
|
+
*
|
|
5
|
+
* (c) AdonisJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE.md
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.RoutesPrettyRenderer = void 0;
|
|
12
|
+
const Base_1 = require("./Base");
|
|
13
|
+
/**
|
|
14
|
+
* Renders the routes as a pretty list
|
|
15
|
+
*/
|
|
16
|
+
class RoutesPrettyRenderer extends Base_1.BaseRender {
|
|
17
|
+
constructor(command) {
|
|
18
|
+
super(command);
|
|
19
|
+
this.routes = this.serializeRotues();
|
|
20
|
+
this.renderingWidth = this.getRenderingWidth();
|
|
21
|
+
this.longestMethodName = this.findLongestMethodName();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns a list of serialized routes
|
|
25
|
+
*/
|
|
26
|
+
serializeRotues() {
|
|
27
|
+
const serializedRoutes = this.command.serializeRoutes();
|
|
28
|
+
return Object.keys(serializedRoutes)
|
|
29
|
+
.map((domain) => serializedRoutes[domain])
|
|
30
|
+
.flat();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns the name of the longest method name
|
|
34
|
+
* across all the routes
|
|
35
|
+
*/
|
|
36
|
+
findLongestMethodName() {
|
|
37
|
+
return (Math.max(...this.routes.map((route) => {
|
|
38
|
+
return this.hasAllMethods(route.methods) ? 'ANY'.length : route.methods.join('|').length;
|
|
39
|
+
})) - 1);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Render a single route by concatenating and colorizing each part of it
|
|
43
|
+
*/
|
|
44
|
+
outputRoute(route, renderingOptions) {
|
|
45
|
+
const methodsOutput = this.colorizeRouteMethods(route.methods);
|
|
46
|
+
const patternOutput = this.colorizeRoutePattern(route.pattern);
|
|
47
|
+
const nameAndHandlerOutput = this.command.colors.gray(route.handler);
|
|
48
|
+
const dashesOutput = this.command.colors.gray(renderingOptions.dashes);
|
|
49
|
+
this.log(methodsOutput + renderingOptions.spaces + patternOutput + dashesOutput + nameAndHandlerOutput);
|
|
50
|
+
/**
|
|
51
|
+
* Display middleware in verbose mode
|
|
52
|
+
*/
|
|
53
|
+
if (route.middleware.length && this.command.verbose) {
|
|
54
|
+
const middleware = route.middleware
|
|
55
|
+
.map((one) => {
|
|
56
|
+
const glyph = '├──';
|
|
57
|
+
const spaces = ' '.repeat(Math.max(this.longestMethodName + 5, 0));
|
|
58
|
+
return this.command.colors.gray(`${spaces} ${glyph} ${one}`);
|
|
59
|
+
})
|
|
60
|
+
.join('\n');
|
|
61
|
+
this.log(middleware);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Log message
|
|
66
|
+
*/
|
|
67
|
+
log(message) {
|
|
68
|
+
if (this.command.application.environment === 'test') {
|
|
69
|
+
this.command.logger.log(message);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.log(message);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Crop the handler name
|
|
77
|
+
*/
|
|
78
|
+
cropHandlerName(handlerName, totalLength) {
|
|
79
|
+
return handlerName.substring(0, this.renderingWidth - totalLength - 1) + '…';
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the whitespace to be rendered between the
|
|
83
|
+
* route methods and the route pattern
|
|
84
|
+
*/
|
|
85
|
+
getWhiteSpace(methods) {
|
|
86
|
+
return ' '.repeat(Math.max(this.longestMethodName + 5 - methods.length, 0));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the rendering width with and without the
|
|
90
|
+
* route handler
|
|
91
|
+
*/
|
|
92
|
+
getRenderingWidths(methods, spaces, pattern, nameAndHandler) {
|
|
93
|
+
const widthWithoutHandler = (methods + spaces + pattern).length + 1;
|
|
94
|
+
const totalWidth = widthWithoutHandler + nameAndHandler.length;
|
|
95
|
+
return { widthWithoutHandler, totalWidth };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns the dashes to be rendered between pattern and the
|
|
99
|
+
* route handler name.
|
|
100
|
+
*/
|
|
101
|
+
getDashes(totalWidth) {
|
|
102
|
+
return ` ${'─'.repeat(Math.max(this.renderingWidth - totalWidth, 0))}`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Renders routes to the console
|
|
106
|
+
*/
|
|
107
|
+
render() {
|
|
108
|
+
this.routes.forEach((route) => {
|
|
109
|
+
const methods = this.hasAllMethods(route.methods) ? 'ANY' : route.methods.join('|');
|
|
110
|
+
const pattern = route.domain !== 'root' ? `${route.domain}${route.pattern}` : route.pattern;
|
|
111
|
+
let handler = route.name ? ` ${route.name} › ${route.handler}` : ` ${route.handler}`;
|
|
112
|
+
const spaces = this.getWhiteSpace(methods);
|
|
113
|
+
const widths = this.getRenderingWidths(methods, spaces, pattern, handler);
|
|
114
|
+
const dashes = this.getDashes(widths.totalWidth);
|
|
115
|
+
/**
|
|
116
|
+
* If name and handler output is too long we crop it
|
|
117
|
+
*/
|
|
118
|
+
if (widths.totalWidth > this.renderingWidth) {
|
|
119
|
+
handler = this.cropHandlerName(handler, widths.widthWithoutHandler);
|
|
120
|
+
}
|
|
121
|
+
this.outputRoute({
|
|
122
|
+
pattern,
|
|
123
|
+
handler,
|
|
124
|
+
middleware: route.middleware,
|
|
125
|
+
methods: route.methods,
|
|
126
|
+
domain: route.domain,
|
|
127
|
+
name: route.name,
|
|
128
|
+
}, {
|
|
129
|
+
spaces,
|
|
130
|
+
dashes,
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.RoutesPrettyRenderer = RoutesPrettyRenderer;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import ListRoutes from '../index';
|
|
2
|
+
import { BaseRender } from './Base';
|
|
3
|
+
/**
|
|
4
|
+
* Renders the routes in a table
|
|
5
|
+
*/
|
|
6
|
+
export declare class RoutesTableRenderer extends BaseRender {
|
|
7
|
+
private routes;
|
|
8
|
+
private domains;
|
|
9
|
+
private columns;
|
|
10
|
+
private longestPatternName;
|
|
11
|
+
constructor(command: ListRoutes);
|
|
12
|
+
/**
|
|
13
|
+
* Returns the length of the longest pattern name among
|
|
14
|
+
* all the routes
|
|
15
|
+
*/
|
|
16
|
+
private getLongestPatterName;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the width for methods column. We limit them at 15 max and
|
|
19
|
+
* return the left over from the column size
|
|
20
|
+
*/
|
|
21
|
+
private getMethodsColumnWidth;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the width for all the columns.
|
|
24
|
+
*/
|
|
25
|
+
private getColumnsSize;
|
|
26
|
+
/**
|
|
27
|
+
* Distributing the left over from the methods column between
|
|
28
|
+
* the pattern column and the handler column.
|
|
29
|
+
*/
|
|
30
|
+
private distributeLeftOverBetweenColumns;
|
|
31
|
+
private getTable;
|
|
32
|
+
/**
|
|
33
|
+
* Render the serialized routes to the console
|
|
34
|
+
*/
|
|
35
|
+
render(): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* @adonisjs/core
|
|
4
|
+
*
|
|
5
|
+
* (c) AdonisJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE.md
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.RoutesTableRenderer = void 0;
|
|
12
|
+
const Base_1 = require("./Base");
|
|
13
|
+
/**
|
|
14
|
+
* Renders the routes in a table
|
|
15
|
+
*/
|
|
16
|
+
class RoutesTableRenderer extends Base_1.BaseRender {
|
|
17
|
+
constructor(command) {
|
|
18
|
+
super(command);
|
|
19
|
+
this.routes = this.command.serializeRoutes();
|
|
20
|
+
this.domains = Object.keys(this.routes);
|
|
21
|
+
this.columns = this.getColumnsSize();
|
|
22
|
+
this.longestPatternName = this.getLongestPatterName();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns the length of the longest pattern name among
|
|
26
|
+
* all the routes
|
|
27
|
+
*/
|
|
28
|
+
getLongestPatterName() {
|
|
29
|
+
return (Math.max(...this.domains.map((domain) => {
|
|
30
|
+
return Math.max(...this.routes[domain].map((route) => route.pattern.length));
|
|
31
|
+
})) + 2);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns the width for methods column. We limit them at 15 max and
|
|
35
|
+
* return the left over from the column size
|
|
36
|
+
*/
|
|
37
|
+
getMethodsColumnWidth(columnSize) {
|
|
38
|
+
return columnSize < 15
|
|
39
|
+
? { size: columnSize, leftOver: 0 }
|
|
40
|
+
: { size: 15, leftOver: columnSize - 15 };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the width for all the columns.
|
|
44
|
+
*/
|
|
45
|
+
getColumnsSize() {
|
|
46
|
+
/**
|
|
47
|
+
* Dividing equal column width between all the columns
|
|
48
|
+
*/
|
|
49
|
+
const columnSize = Math.round(this.getRenderingWidth() / 3) - 2;
|
|
50
|
+
/**
|
|
51
|
+
* Limiting the methods column width to 15 cells at max. 90% of the
|
|
52
|
+
* time methods fits within this width, for rest of the cases, they
|
|
53
|
+
* will truncate.
|
|
54
|
+
*/
|
|
55
|
+
const { size: methodsColumnSize, leftOver } = this.getMethodsColumnWidth(columnSize);
|
|
56
|
+
/**
|
|
57
|
+
* Starting wdith for the patterns column and the handlers column.
|
|
58
|
+
*/
|
|
59
|
+
const patternColumnSize = columnSize;
|
|
60
|
+
const handlerColumnSize = columnSize;
|
|
61
|
+
return {
|
|
62
|
+
methodsColumnSize,
|
|
63
|
+
patternColumnSize,
|
|
64
|
+
handlerColumnSize,
|
|
65
|
+
leftOver,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Distributing the left over from the methods column between
|
|
70
|
+
* the pattern column and the handler column.
|
|
71
|
+
*/
|
|
72
|
+
distributeLeftOverBetweenColumns() {
|
|
73
|
+
/**
|
|
74
|
+
* If the pattern width is smaller than the column width itself, then
|
|
75
|
+
* we just give all the left over to the handler column.
|
|
76
|
+
*/
|
|
77
|
+
if (this.longestPatternName < this.columns.patternColumnSize) {
|
|
78
|
+
this.columns.handlerColumnSize += this.columns.leftOver;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const cellsNeeded = this.longestPatternName - this.columns.patternColumnSize;
|
|
82
|
+
/**
|
|
83
|
+
* If the pattern column width execeeds the left over width, then
|
|
84
|
+
* we just give the left over to the pattern column. This will
|
|
85
|
+
* also make the pattern column truncate.
|
|
86
|
+
*/
|
|
87
|
+
if (cellsNeeded > this.columns.leftOver) {
|
|
88
|
+
this.columns.patternColumnSize += this.columns.leftOver;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Finally, we give the cells needed for the pattern column and
|
|
93
|
+
* give the rest to the handler column.
|
|
94
|
+
*/
|
|
95
|
+
this.columns.patternColumnSize += cellsNeeded;
|
|
96
|
+
this.columns.handlerColumnSize += this.columns.leftOver - cellsNeeded;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
getTable() {
|
|
100
|
+
if (this.columns.leftOver > 0) {
|
|
101
|
+
this.distributeLeftOverBetweenColumns();
|
|
102
|
+
}
|
|
103
|
+
return this.command.ui
|
|
104
|
+
.table()
|
|
105
|
+
.head(['Method', 'Route & Name', 'Handler & Middleware'])
|
|
106
|
+
.columnWidths([
|
|
107
|
+
this.columns.methodsColumnSize,
|
|
108
|
+
this.columns.patternColumnSize,
|
|
109
|
+
this.columns.handlerColumnSize,
|
|
110
|
+
]);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Render the serialized routes to the console
|
|
114
|
+
*/
|
|
115
|
+
render() {
|
|
116
|
+
const hasCustomDomains = this.domains.find((domain) => domain !== 'root');
|
|
117
|
+
const table = this.getTable();
|
|
118
|
+
this.domains.forEach((domain) => {
|
|
119
|
+
if (hasCustomDomains) {
|
|
120
|
+
table.row([{ colSpan: 3, content: this.command.colors.cyan(domain) }]);
|
|
121
|
+
}
|
|
122
|
+
const domainRoutes = this.routes[domain];
|
|
123
|
+
domainRoutes.forEach((route) => {
|
|
124
|
+
const methodsOutput = this.colorizeRouteMethods(route.methods);
|
|
125
|
+
const patternAndNameOutput = route.name
|
|
126
|
+
? `${this.colorizeRoutePattern(route.pattern)}\n${this.command.colors.gray(route.name)}`
|
|
127
|
+
: this.colorizeRoutePattern(route.pattern);
|
|
128
|
+
const handlerOutput = route.middleware.length
|
|
129
|
+
? `${route.handler}\n${this.command.colors.gray(route.middleware.join('\n'))}`
|
|
130
|
+
: route.handler;
|
|
131
|
+
table.row([methodsOutput, patternAndNameOutput, handlerOutput]);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
table.render();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.RoutesTableRenderer = RoutesTableRenderer;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/ace';
|
|
2
|
+
import type { RouteNode } from '@ioc:Adonis/Core/Route';
|
|
3
|
+
/**
|
|
4
|
+
* Shape of a route serialized by the ListRoute JSON serializer
|
|
5
|
+
*/
|
|
6
|
+
export declare type SerializedRoute = {
|
|
7
|
+
domain: string;
|
|
8
|
+
name: string;
|
|
9
|
+
pattern: string;
|
|
10
|
+
handler: string;
|
|
11
|
+
methods: string[];
|
|
12
|
+
middleware: string[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A command to display a list of routes
|
|
16
|
+
*/
|
|
17
|
+
export default class ListRoutes extends BaseCommand {
|
|
18
|
+
static commandName: string;
|
|
19
|
+
static description: string;
|
|
20
|
+
verbose: boolean;
|
|
21
|
+
reverse: boolean;
|
|
22
|
+
methodsFilter: string[];
|
|
23
|
+
patternsFilter: string[];
|
|
24
|
+
namesFilter: string[];
|
|
25
|
+
json: boolean;
|
|
26
|
+
table: boolean;
|
|
27
|
+
maxWidth: number;
|
|
28
|
+
/**
|
|
29
|
+
* Load application
|
|
30
|
+
*/
|
|
31
|
+
static settings: {
|
|
32
|
+
loadApp: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Returns the display handler name
|
|
36
|
+
*/
|
|
37
|
+
private getHandlerName;
|
|
38
|
+
/**
|
|
39
|
+
* Apply the method filter on the route
|
|
40
|
+
*/
|
|
41
|
+
private hasPassedMethodFilter;
|
|
42
|
+
/**
|
|
43
|
+
* Apply the pattern filter on the route
|
|
44
|
+
*/
|
|
45
|
+
private hasPassedPatternFilter;
|
|
46
|
+
/**
|
|
47
|
+
* Apply the name filter on the route
|
|
48
|
+
*/
|
|
49
|
+
private hasPassedNameFilter;
|
|
50
|
+
/**
|
|
51
|
+
* Log message
|
|
52
|
+
*/
|
|
53
|
+
private log;
|
|
54
|
+
/**
|
|
55
|
+
* Serialize route to JSON
|
|
56
|
+
*/
|
|
57
|
+
serializeRoute(route: RouteNode & {
|
|
58
|
+
methods: string[];
|
|
59
|
+
}, domain: string): {
|
|
60
|
+
domain: string;
|
|
61
|
+
name: string;
|
|
62
|
+
pattern: string;
|
|
63
|
+
methods: string[];
|
|
64
|
+
handler: string;
|
|
65
|
+
middleware: string[];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Returns an array of routes as JSON, filtered according to the
|
|
69
|
+
* flags passed to the command
|
|
70
|
+
*/
|
|
71
|
+
serializeRoutes(): Record<string, SerializedRoute[]>;
|
|
72
|
+
run(): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* @adonisjs/core
|
|
4
|
+
*
|
|
5
|
+
* (c) AdonisJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE.md
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
11
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
+
};
|
|
16
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
17
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
const ace_1 = require("@adonisjs/ace");
|
|
21
|
+
const TableRenderer_1 = require("./Renderers/TableRenderer");
|
|
22
|
+
const PrettyRenderer_1 = require("./Renderers/PrettyRenderer");
|
|
23
|
+
/**
|
|
24
|
+
* A command to display a list of routes
|
|
25
|
+
*/
|
|
26
|
+
class ListRoutes extends ace_1.BaseCommand {
|
|
27
|
+
/**
|
|
28
|
+
* Returns the display handler name
|
|
29
|
+
*/
|
|
30
|
+
getHandlerName(route) {
|
|
31
|
+
const resolvedHandler = route.meta.resolvedHandler;
|
|
32
|
+
if (resolvedHandler.type === 'function') {
|
|
33
|
+
return 'Closure';
|
|
34
|
+
}
|
|
35
|
+
const defaultControllersNamespace = this.application.namespacesMap.get('httpControllers');
|
|
36
|
+
return `${resolvedHandler.namespace.replace(new RegExp(`^${defaultControllersNamespace}\/`), '')}.${resolvedHandler.method}`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Apply the method filter on the route
|
|
40
|
+
*/
|
|
41
|
+
hasPassedMethodFilter(route) {
|
|
42
|
+
if (!this.methodsFilter || !this.methodsFilter.length) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return !!this.methodsFilter.find((filter) => route.methods.includes(filter.toUpperCase()));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Apply the pattern filter on the route
|
|
49
|
+
*/
|
|
50
|
+
hasPassedPatternFilter(route) {
|
|
51
|
+
if (!this.patternsFilter || !this.patternsFilter.length) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return !!this.patternsFilter.find((filter) => route.pattern.includes(filter));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Apply the name filter on the route
|
|
58
|
+
*/
|
|
59
|
+
hasPassedNameFilter(route) {
|
|
60
|
+
if (!this.namesFilter || !this.namesFilter.length) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return !!this.namesFilter.find((filter) => route.name.includes(filter));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Log message
|
|
67
|
+
*/
|
|
68
|
+
log(message) {
|
|
69
|
+
if (this.application.environment === 'test') {
|
|
70
|
+
this.logger.log(message);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
console.log(message);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Serialize route to JSON
|
|
78
|
+
*/
|
|
79
|
+
serializeRoute(route, domain) {
|
|
80
|
+
return {
|
|
81
|
+
domain,
|
|
82
|
+
name: route.name || '',
|
|
83
|
+
pattern: route.pattern,
|
|
84
|
+
methods: route.methods,
|
|
85
|
+
handler: this.getHandlerName(route),
|
|
86
|
+
middleware: route.middleware.map((one) => (typeof one === 'function' ? 'Closure' : one)),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns an array of routes as JSON, filtered according to the
|
|
91
|
+
* flags passed to the command
|
|
92
|
+
*/
|
|
93
|
+
serializeRoutes() {
|
|
94
|
+
const Router = this.application.container.use('Adonis/Core/Route');
|
|
95
|
+
Router.commit();
|
|
96
|
+
const routes = Router.toJSON();
|
|
97
|
+
return Object.keys(routes).reduce((result, domain) => {
|
|
98
|
+
const domainRoutes = routes[domain]
|
|
99
|
+
.map((route) => this.serializeRoute(route, domain))
|
|
100
|
+
.filter((route) => {
|
|
101
|
+
return (this.hasPassedMethodFilter(route) &&
|
|
102
|
+
this.hasPassedNameFilter(route) &&
|
|
103
|
+
this.hasPassedPatternFilter(route));
|
|
104
|
+
});
|
|
105
|
+
if (this.reverse) {
|
|
106
|
+
domainRoutes.reverse();
|
|
107
|
+
}
|
|
108
|
+
result[domain] = domainRoutes;
|
|
109
|
+
return result;
|
|
110
|
+
}, {});
|
|
111
|
+
}
|
|
112
|
+
async run() {
|
|
113
|
+
if (this.json) {
|
|
114
|
+
this.log(JSON.stringify(this.serializeRoutes(), null, 2));
|
|
115
|
+
}
|
|
116
|
+
else if (this.table) {
|
|
117
|
+
new TableRenderer_1.RoutesTableRenderer(this).render();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
new PrettyRenderer_1.RoutesPrettyRenderer(this).render();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
ListRoutes.commandName = 'list:routes';
|
|
125
|
+
ListRoutes.description = 'List application routes';
|
|
126
|
+
/**
|
|
127
|
+
* Load application
|
|
128
|
+
*/
|
|
129
|
+
ListRoutes.settings = {
|
|
130
|
+
loadApp: true,
|
|
131
|
+
};
|
|
132
|
+
__decorate([
|
|
133
|
+
ace_1.flags.boolean({ name: 'verbose', description: 'Display more information' }),
|
|
134
|
+
__metadata("design:type", Boolean)
|
|
135
|
+
], ListRoutes.prototype, "verbose", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
ace_1.flags.boolean({ alias: 'r', name: 'reverse', description: 'Reverse routes display' }),
|
|
138
|
+
__metadata("design:type", Boolean)
|
|
139
|
+
], ListRoutes.prototype, "reverse", void 0);
|
|
140
|
+
__decorate([
|
|
141
|
+
ace_1.flags.array({ alias: 'm', name: 'methods', description: 'Filter routes by method' }),
|
|
142
|
+
__metadata("design:type", Array)
|
|
143
|
+
], ListRoutes.prototype, "methodsFilter", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
ace_1.flags.array({ alias: 'p', name: 'patterns', description: 'Filter routes by the route pattern' }),
|
|
146
|
+
__metadata("design:type", Array)
|
|
147
|
+
], ListRoutes.prototype, "patternsFilter", void 0);
|
|
148
|
+
__decorate([
|
|
149
|
+
ace_1.flags.array({ alias: 'n', name: 'names', description: 'Filter routes by route name' }),
|
|
150
|
+
__metadata("design:type", Array)
|
|
151
|
+
], ListRoutes.prototype, "namesFilter", void 0);
|
|
152
|
+
__decorate([
|
|
153
|
+
ace_1.flags.boolean({ description: 'Output as JSON' }),
|
|
154
|
+
__metadata("design:type", Boolean)
|
|
155
|
+
], ListRoutes.prototype, "json", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
ace_1.flags.boolean({ description: 'Output as Table' }),
|
|
158
|
+
__metadata("design:type", Boolean)
|
|
159
|
+
], ListRoutes.prototype, "table", void 0);
|
|
160
|
+
__decorate([
|
|
161
|
+
ace_1.flags.number({ description: 'Specify maximum rendering width. Ignored for JSON Output' }),
|
|
162
|
+
__metadata("design:type", Number)
|
|
163
|
+
], ListRoutes.prototype, "maxWidth", void 0);
|
|
164
|
+
exports.default = ListRoutes;
|
package/build/commands/index.js
CHANGED
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.default = [
|
|
12
12
|
'@adonisjs/core/build/commands/DumpRc.js',
|
|
13
|
-
'@adonisjs/core/build/commands/ListRoutes.js',
|
|
13
|
+
'@adonisjs/core/build/commands/ListRoutes/index.js',
|
|
14
14
|
'@adonisjs/core/build/commands/GenerateKey.js',
|
|
15
15
|
];
|
|
@@ -53,6 +53,10 @@ export default class AppProvider {
|
|
|
53
53
|
* Define repl bindings
|
|
54
54
|
*/
|
|
55
55
|
protected defineReplBindings(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Define bindings for japa tests
|
|
58
|
+
*/
|
|
59
|
+
protected defineTestsBindings(): void;
|
|
56
60
|
/**
|
|
57
61
|
* Registering all required bindings to the container
|
|
58
62
|
*/
|
|
@@ -165,6 +165,15 @@ class AppProvider {
|
|
|
165
165
|
defineReplBindings(this.app, Repl);
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Define bindings for japa tests
|
|
170
|
+
*/
|
|
171
|
+
defineTestsBindings() {
|
|
172
|
+
this.app.container.withBindings(['Japa/Preset/ApiRequest', 'Japa/Preset/ApiClient', 'Adonis/Core/CookieClient'], (ApiRequest, ApiClient, CookieClient) => {
|
|
173
|
+
const { defineTestsBindings } = require('../src/Bindings/Tests');
|
|
174
|
+
defineTestsBindings(ApiRequest, ApiClient, CookieClient);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
168
177
|
/**
|
|
169
178
|
* Registering all required bindings to the container
|
|
170
179
|
*/
|
|
@@ -183,6 +192,7 @@ class AppProvider {
|
|
|
183
192
|
this.registerStaticAssetsHook();
|
|
184
193
|
this.registerHealthCheckers();
|
|
185
194
|
this.defineReplBindings();
|
|
195
|
+
this.defineTestsBindings();
|
|
186
196
|
}
|
|
187
197
|
}
|
|
188
198
|
exports.default = AppProvider;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ContainerBindings } from '@ioc:Adonis/Core/Application';
|
|
2
|
+
import { CookieClientContract } from '@ioc:Adonis/Core/CookieClient';
|
|
3
|
+
/**
|
|
4
|
+
* Define test bindings
|
|
5
|
+
*/
|
|
6
|
+
export declare function defineTestsBindings(ApiRequest: ContainerBindings['Japa/Preset/ApiRequest'], ApiClient: ContainerBindings['Japa/Preset/ApiClient'], CookieClient: CookieClientContract): void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* @adonisjs/core
|
|
4
|
+
*
|
|
5
|
+
* (c) AdonisJS
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.defineTestsBindings = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Define test bindings
|
|
14
|
+
*/
|
|
15
|
+
function defineTestsBindings(ApiRequest, ApiClient, CookieClient) {
|
|
16
|
+
/**
|
|
17
|
+
* Serializing for parsing response cookies
|
|
18
|
+
*/
|
|
19
|
+
ApiClient.cookiesSerializer({
|
|
20
|
+
/**
|
|
21
|
+
* The methods on the Request class encrypts and signs cookies.
|
|
22
|
+
* Therefore, the prepare method returns the value as it is
|
|
23
|
+
*/
|
|
24
|
+
prepare(_, value) {
|
|
25
|
+
return value;
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* Process the server response and convert cookie value to a
|
|
29
|
+
* plain string
|
|
30
|
+
*/
|
|
31
|
+
process(key, value) {
|
|
32
|
+
return CookieClient.parse(key, value);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Define cookie
|
|
37
|
+
*/
|
|
38
|
+
ApiRequest.macro('cookie', function (key, value) {
|
|
39
|
+
const signedValue = CookieClient.sign(key, value);
|
|
40
|
+
if (signedValue) {
|
|
41
|
+
this.cookiesJar[key] = { name: key, value: signedValue };
|
|
42
|
+
}
|
|
43
|
+
return this;
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Define encrypted cookie
|
|
47
|
+
*/
|
|
48
|
+
ApiRequest.macro('encryptedCookie', function (key, value) {
|
|
49
|
+
const encryptedValue = CookieClient.encrypt(key, value);
|
|
50
|
+
if (encryptedValue) {
|
|
51
|
+
this.cookiesJar[key] = { name: key, value: encryptedValue };
|
|
52
|
+
}
|
|
53
|
+
return this;
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* Define plain cookie
|
|
57
|
+
*/
|
|
58
|
+
ApiRequest.macro('plainCookie', function (key, value) {
|
|
59
|
+
const encodedValue = CookieClient.encode(key, value);
|
|
60
|
+
if (encodedValue) {
|
|
61
|
+
this.cookiesJar[key] = { name: key, value: encodedValue };
|
|
62
|
+
}
|
|
63
|
+
return this;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.defineTestsBindings = defineTestsBindings;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract source: https://github.com/adonisjs/core/blob/master/templates/contracts/tests.txt
|
|
3
|
+
*
|
|
4
|
+
* Feel free to let us know via PR, if you find something broken in this contract
|
|
5
|
+
* file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import '@japa/runner'
|
|
9
|
+
|
|
10
|
+
declare module '@japa/runner' {
|
|
11
|
+
interface TestContext {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Test<DataSet> {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -5,11 +5,9 @@
|
|
|
5
5
|
* file.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import type { Suite } from '@japa/core'
|
|
10
|
-
import { specReporter } from '@japa/spec-reporter'
|
|
8
|
+
import type { Config } from '@japa/runner'
|
|
11
9
|
import TestUtils from '@ioc:Adonis/Core/TestUtils'
|
|
12
|
-
import
|
|
10
|
+
import { assert, runFailedTests, specReporter } from '@japa/preset-adonis'
|
|
13
11
|
|
|
14
12
|
/*
|
|
15
13
|
|--------------------------------------------------------------------------
|
|
@@ -22,7 +20,7 @@ import type { PluginFn, RunnerHooksHandler, TestContext, ReporterContract } from
|
|
|
22
20
|
| Feel free to remove existing plugins or add more.
|
|
23
21
|
|
|
|
24
22
|
*/
|
|
25
|
-
export const plugins:
|
|
23
|
+
export const plugins: Config['plugins'] = [assert(), runFailedTests()]
|
|
26
24
|
|
|
27
25
|
/*
|
|
28
26
|
|--------------------------------------------------------------------------
|
|
@@ -34,7 +32,7 @@ export const plugins: PluginFn[] = [assert()]
|
|
|
34
32
|
| of tests on the terminal.
|
|
35
33
|
|
|
|
36
34
|
*/
|
|
37
|
-
export const reporters:
|
|
35
|
+
export const reporters: Config['reporters'] = [specReporter()]
|
|
38
36
|
|
|
39
37
|
/*
|
|
40
38
|
|--------------------------------------------------------------------------
|
|
@@ -48,8 +46,8 @@ export const reporters: ReporterContract[] = [specReporter()]
|
|
|
48
46
|
| within the runner hooks
|
|
49
47
|
|
|
|
50
48
|
*/
|
|
51
|
-
export const runnerHooks:
|
|
52
|
-
setup: [() => TestUtils.ace().loadCommands()],
|
|
49
|
+
export const runnerHooks: Required<Pick<Config, 'setup' | 'teardown'>> = {
|
|
50
|
+
setup: [() => TestUtils.ace().loadCommands(), () => TestUtils.db().migrate()],
|
|
53
51
|
teardown: [],
|
|
54
52
|
}
|
|
55
53
|
|
|
@@ -62,10 +60,10 @@ export const runnerHooks: { setup: RunnerHooksHandler[]; teardown: RunnerHooksHa
|
|
|
62
60
|
| within ".adonisrc.json" file.
|
|
63
61
|
|
|
|
64
62
|
| You can use this method to configure suites. For example: Only start
|
|
65
|
-
| the HTTP server when it is a
|
|
63
|
+
| the HTTP server when it is a functional suite.
|
|
66
64
|
*/
|
|
67
|
-
export const configureSuite = (suite
|
|
68
|
-
if (suite.name === '
|
|
65
|
+
export const configureSuite: Config['configureSuite'] = (suite) => {
|
|
66
|
+
if (suite.name === 'functional') {
|
|
69
67
|
suite.setup(() => TestUtils.httpServer().start())
|
|
70
68
|
}
|
|
71
69
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|--------------------------------------------------------------------------
|
|
3
|
+
| Tests
|
|
4
|
+
|--------------------------------------------------------------------------
|
|
5
|
+
|
|
|
6
|
+
| The contents in this file boots the AdonisJS application and configures
|
|
7
|
+
| the Japa tests runner.
|
|
8
|
+
|
|
|
9
|
+
| For the most part you will never edit this file. The configuration
|
|
10
|
+
| for the tests can be controlled via ".adonisrc.json" and
|
|
11
|
+
| "tests/bootstrap.ts" files.
|
|
12
|
+
|
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
process.env.NODE_ENV = 'testing'
|
|
16
|
+
|
|
17
|
+
import 'reflect-metadata'
|
|
18
|
+
import sourceMapSupport from 'source-map-support'
|
|
19
|
+
import { Ignitor } from '@adonisjs/core/build/standalone'
|
|
20
|
+
import { configure, processCliArgs, run, RunnerHooksHandler } from '@japa/runner'
|
|
21
|
+
|
|
22
|
+
sourceMapSupport.install({ handleUncaughtExceptions: false })
|
|
23
|
+
|
|
24
|
+
const kernel = new Ignitor(__dirname).kernel('test')
|
|
25
|
+
|
|
26
|
+
kernel
|
|
27
|
+
.boot()
|
|
28
|
+
.then(() => import('./tests/bootstrap'))
|
|
29
|
+
.then(({ runnerHooks, ...config }) => {
|
|
30
|
+
const app: RunnerHooksHandler[] = [() => kernel.start()]
|
|
31
|
+
|
|
32
|
+
configure({
|
|
33
|
+
...kernel.application.rcFile.tests,
|
|
34
|
+
...processCliArgs(process.argv.slice(2)),
|
|
35
|
+
...config,
|
|
36
|
+
...{
|
|
37
|
+
importer: (filePath) => import(filePath),
|
|
38
|
+
setup: app.concat(runnerHooks.setup),
|
|
39
|
+
teardown: runnerHooks.teardown,
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
run()
|
|
44
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Core of AdonisJS",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -63,38 +63,39 @@
|
|
|
63
63
|
},
|
|
64
64
|
"homepage": "https://github.com/adonisjs/core#readme",
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@adonisjs/assembler": "^5.4.
|
|
67
|
-
"@adonisjs/mrm-preset": "^5.0.
|
|
66
|
+
"@adonisjs/assembler": "^5.4.2",
|
|
67
|
+
"@adonisjs/mrm-preset": "^5.0.3",
|
|
68
68
|
"@adonisjs/repl": "^3.1.9",
|
|
69
69
|
"@adonisjs/require-ts": "^2.0.10",
|
|
70
70
|
"@adonisjs/sink": "^5.2.2",
|
|
71
|
-
"@japa/assert": "^1.2
|
|
72
|
-
"@japa/
|
|
73
|
-
"@japa/
|
|
74
|
-
"@japa/
|
|
71
|
+
"@japa/assert": "^1.3.2",
|
|
72
|
+
"@japa/preset-adonis": "^1.0.8",
|
|
73
|
+
"@japa/run-failed-tests": "^1.0.6",
|
|
74
|
+
"@japa/runner": "^2.0.5",
|
|
75
|
+
"@japa/spec-reporter": "^1.1.11",
|
|
75
76
|
"@poppinss/dev-utils": "^2.0.2",
|
|
76
|
-
"@types/node": "^17.0.
|
|
77
|
-
"@types/supertest": "^2.0.
|
|
77
|
+
"@types/node": "^17.0.23",
|
|
78
|
+
"@types/supertest": "^2.0.12",
|
|
78
79
|
"clear-module": "^4.1.2",
|
|
79
80
|
"commitizen": "^4.2.4",
|
|
80
81
|
"copyfiles": "^2.4.1",
|
|
81
82
|
"cz-conventional-changelog": "^3.3.0",
|
|
82
83
|
"del-cli": "^4.0.1",
|
|
83
|
-
"eslint": "^8.
|
|
84
|
+
"eslint": "^8.12.0",
|
|
84
85
|
"eslint-config-prettier": "^8.5.0",
|
|
85
86
|
"eslint-plugin-adonis": "^2.1.0",
|
|
86
87
|
"eslint-plugin-prettier": "^4.0.0",
|
|
87
88
|
"etag": "^1.8.1",
|
|
88
89
|
"github-label-sync": "^2.0.2",
|
|
89
90
|
"husky": "^7.0.4",
|
|
90
|
-
"mrm": "^
|
|
91
|
-
"np": "^7.6.
|
|
92
|
-
"prettier": "^2.
|
|
91
|
+
"mrm": "^4.0.0",
|
|
92
|
+
"np": "^7.6.1",
|
|
93
|
+
"prettier": "^2.6.1",
|
|
93
94
|
"reflect-metadata": "^0.1.13",
|
|
94
|
-
"strip-ansi": "^6.0.
|
|
95
|
+
"strip-ansi": "^6.0.1",
|
|
95
96
|
"supertest": "^6.2.2",
|
|
96
97
|
"test-console": "^2.0.0",
|
|
97
|
-
"typescript": "^4.6.
|
|
98
|
+
"typescript": "^4.6.3",
|
|
98
99
|
"youch": "^3.1.1",
|
|
99
100
|
"youch-terminal": "^2.1.3"
|
|
100
101
|
},
|
|
@@ -119,20 +120,20 @@
|
|
|
119
120
|
"dependencies": {
|
|
120
121
|
"@adonisjs/ace": "^11.2.2",
|
|
121
122
|
"@adonisjs/application": "^5.2.0",
|
|
122
|
-
"@adonisjs/bodyparser": "^8.1.
|
|
123
|
-
"@adonisjs/drive": "^2.0.
|
|
123
|
+
"@adonisjs/bodyparser": "^8.1.1",
|
|
124
|
+
"@adonisjs/drive": "^2.0.10",
|
|
124
125
|
"@adonisjs/encryption": "^4.0.7",
|
|
125
126
|
"@adonisjs/events": "^7.1.3",
|
|
126
127
|
"@adonisjs/hash": "^7.0.10",
|
|
127
|
-
"@adonisjs/http-server": "^5.
|
|
128
|
-
"@adonisjs/validator": "^12.2.
|
|
128
|
+
"@adonisjs/http-server": "^5.7.3",
|
|
129
|
+
"@adonisjs/validator": "^12.2.3",
|
|
129
130
|
"@poppinss/cliui": "^3.0.1",
|
|
130
131
|
"@poppinss/manager": "^5.0.1",
|
|
131
132
|
"@poppinss/utils": "^4.0.2",
|
|
132
133
|
"fs-extra": "^10.0.1",
|
|
133
|
-
"macroable": "^
|
|
134
|
+
"macroable": "^7.0.0",
|
|
134
135
|
"memfs": "^3.4.1",
|
|
135
|
-
"serve-static": "^1.
|
|
136
|
+
"serve-static": "^1.15.0",
|
|
136
137
|
"stringify-attributes": "^2.0.0"
|
|
137
138
|
},
|
|
138
139
|
"np": {
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from '@adonisjs/ace';
|
|
2
|
-
/**
|
|
3
|
-
* A command to display a list of routes
|
|
4
|
-
*/
|
|
5
|
-
export default class ListRoutes extends BaseCommand {
|
|
6
|
-
static commandName: string;
|
|
7
|
-
static description: string;
|
|
8
|
-
json: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Load application
|
|
11
|
-
*/
|
|
12
|
-
static settings: {
|
|
13
|
-
loadApp: boolean;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Returns an array of routes as JSON
|
|
17
|
-
*/
|
|
18
|
-
private outputJSON;
|
|
19
|
-
/**
|
|
20
|
-
* Output routes a table string
|
|
21
|
-
*/
|
|
22
|
-
private outputTable;
|
|
23
|
-
/**
|
|
24
|
-
* Log message
|
|
25
|
-
*/
|
|
26
|
-
private log;
|
|
27
|
-
run(): Promise<void>;
|
|
28
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/core
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
11
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
-
};
|
|
16
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
17
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
const ace_1 = require("@adonisjs/ace");
|
|
21
|
-
/**
|
|
22
|
-
* A command to display a list of routes
|
|
23
|
-
*/
|
|
24
|
-
class ListRoutes extends ace_1.BaseCommand {
|
|
25
|
-
/**
|
|
26
|
-
* Returns an array of routes as JSON
|
|
27
|
-
*/
|
|
28
|
-
outputJSON(router) {
|
|
29
|
-
const routes = router.toJSON();
|
|
30
|
-
return Object.keys(routes).reduce((result, domain) => {
|
|
31
|
-
result[domain] = routes[domain].map((route) => {
|
|
32
|
-
let handler = 'Closure';
|
|
33
|
-
const middleware = route
|
|
34
|
-
? route.middleware.map((one) => (typeof one === 'function' ? 'Closure' : one))
|
|
35
|
-
: [];
|
|
36
|
-
if (route.meta.resolvedHandler.type !== 'function' && route.meta.namespace) {
|
|
37
|
-
handler = `${route.meta.resolvedHandler['namespace']}.${route.meta.resolvedHandler['method']}`;
|
|
38
|
-
}
|
|
39
|
-
else if (route.meta.resolvedHandler.type !== 'function') {
|
|
40
|
-
const method = route.meta.resolvedHandler['method'];
|
|
41
|
-
const routeHandler = route.handler;
|
|
42
|
-
handler = `${routeHandler.replace(new RegExp(`.${method}$`), '')}.${method}`;
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
methods: route.methods,
|
|
46
|
-
name: route.name || '',
|
|
47
|
-
pattern: route.pattern,
|
|
48
|
-
handler: handler,
|
|
49
|
-
middleware: middleware,
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
return result;
|
|
53
|
-
}, {});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Output routes a table string
|
|
57
|
-
*/
|
|
58
|
-
outputTable(router) {
|
|
59
|
-
const routes = this.outputJSON(router);
|
|
60
|
-
const domains = Object.keys(routes);
|
|
61
|
-
const showDomainHeadline = domains.length > 1 || domains[0] !== 'root';
|
|
62
|
-
const table = this.ui.table().head(['Method', 'Route', 'Handler', 'Middleware', 'Name']);
|
|
63
|
-
domains.forEach((domain) => {
|
|
64
|
-
if (showDomainHeadline) {
|
|
65
|
-
table.row([{ colSpan: 5, content: `Domain ${this.colors.cyan(domain)}` }]);
|
|
66
|
-
}
|
|
67
|
-
routes[domain].forEach((route) => {
|
|
68
|
-
table.row([
|
|
69
|
-
this.colors.dim(route.methods.join(', ')),
|
|
70
|
-
route.pattern,
|
|
71
|
-
typeof route.handler === 'function' ? 'Closure' : route.handler,
|
|
72
|
-
route.middleware.join(','),
|
|
73
|
-
route.name,
|
|
74
|
-
]);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
table.render();
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Log message
|
|
81
|
-
*/
|
|
82
|
-
log(message) {
|
|
83
|
-
if (this.application.environment === 'test') {
|
|
84
|
-
this.logger.log(message);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
console.log(message);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async run() {
|
|
91
|
-
const Router = this.application.container.use('Adonis/Core/Route');
|
|
92
|
-
/**
|
|
93
|
-
* Commit routes before we can read them
|
|
94
|
-
*/
|
|
95
|
-
Router.commit();
|
|
96
|
-
if (this.json) {
|
|
97
|
-
this.log(JSON.stringify(this.outputJSON(Router), null, 2));
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this.outputTable(Router);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
ListRoutes.commandName = 'list:routes';
|
|
105
|
-
ListRoutes.description = 'List application routes';
|
|
106
|
-
/**
|
|
107
|
-
* Load application
|
|
108
|
-
*/
|
|
109
|
-
ListRoutes.settings = {
|
|
110
|
-
loadApp: true,
|
|
111
|
-
};
|
|
112
|
-
__decorate([
|
|
113
|
-
ace_1.flags.boolean({ description: 'Output as JSON' }),
|
|
114
|
-
__metadata("design:type", Boolean)
|
|
115
|
-
], ListRoutes.prototype, "json", void 0);
|
|
116
|
-
exports.default = ListRoutes;
|
|
File without changes
|