@adonisjs/assembler 5.5.2-0 → 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/commands/Invoke.d.ts +1 -0
- package/build/commands/Invoke.js +20 -1
- package/build/config/paths.d.ts +1 -1
- package/build/config/paths.js +1 -1
- package/build/src/EnvParser/index.d.ts +2 -0
- package/build/src/EnvParser/index.js +3 -2
- package/build/src/Test/index.d.ts +5 -0
- package/build/src/Test/index.js +23 -1
- package/build/templates/test-entrypoint.txt +1 -1
- package/build/templates/tests/bootstrap.txt +69 -0
- package/build/templates/tests/functional/hello_world_api.spec.txt +8 -0
- package/build/templates/tests/functional/hello_world_slim.spec.txt +8 -0
- package/build/templates/tests/functional/hello_world_web.spec.txt +8 -0
- package/build/templates/tests-contract.txt +2 -2
- package/package.json +3 -3
package/build/commands/Invoke.js
CHANGED
|
@@ -25,6 +25,10 @@ const Manifest_1 = require("../src/Manifest");
|
|
|
25
25
|
* Configure a package
|
|
26
26
|
*/
|
|
27
27
|
class Configure extends standalone_1.BaseCommand {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.appType = process.env['ADONIS_CREATE_APP_BOILERPLATE'] || 'web';
|
|
31
|
+
}
|
|
28
32
|
/**
|
|
29
33
|
* Configure encore
|
|
30
34
|
*/
|
|
@@ -85,7 +89,7 @@ class Configure extends standalone_1.BaseCommand {
|
|
|
85
89
|
/**
|
|
86
90
|
* Create "tests/functional/hello_world.spec.ts" file
|
|
87
91
|
*/
|
|
88
|
-
const helloWorldTestFile = new sink_1.files.MustacheFile(this.application.appRoot, 'tests/functional/hello_world.spec.ts', (0, path_1.join)(__dirname, '..',
|
|
92
|
+
const helloWorldTestFile = new sink_1.files.MustacheFile(this.application.appRoot, 'tests/functional/hello_world.spec.ts', (0, path_1.join)(__dirname, '..', `templates/tests/functional/hello_world_${this.appType}.spec.txt`));
|
|
89
93
|
if (!helloWorldTestFile.exists()) {
|
|
90
94
|
helloWorldTestFile.apply({}).commit();
|
|
91
95
|
sink_1.logger.action('create').succeeded('tests/functional/hello_world.spec.ts');
|
|
@@ -113,6 +117,21 @@ class Configure extends standalone_1.BaseCommand {
|
|
|
113
117
|
});
|
|
114
118
|
rcFile.commit();
|
|
115
119
|
sink_1.logger.action('update').succeeded('.adonisrc.json');
|
|
120
|
+
/**
|
|
121
|
+
* Create ".env.test" file
|
|
122
|
+
*/
|
|
123
|
+
const testEnvFile = new sink_1.files.NewLineFile(this.application.appRoot, '.env.test');
|
|
124
|
+
if (!testEnvFile.exists()) {
|
|
125
|
+
testEnvFile.add('NODE_ENV=test');
|
|
126
|
+
/**
|
|
127
|
+
* Set additional .env variables for "web" boilerplate
|
|
128
|
+
*/
|
|
129
|
+
if (this.appType === 'web') {
|
|
130
|
+
testEnvFile.add(['ASSETS_DRIVER=fake', 'SESSION_DRIVER=memory']);
|
|
131
|
+
}
|
|
132
|
+
testEnvFile.commit();
|
|
133
|
+
sink_1.logger.action('create').succeeded('.env.test');
|
|
134
|
+
}
|
|
116
135
|
/**
|
|
117
136
|
* Install required dependencies
|
|
118
137
|
*/
|
package/build/config/paths.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export declare const DEFAULT_BUILD_DIR = "build";
|
|
|
3
3
|
export declare const RCFILE_NAME = ".adonisrc.json";
|
|
4
4
|
export declare const ENV_FILES: string[];
|
|
5
5
|
export declare const SERVER_ENTRY_FILE = "server.ts";
|
|
6
|
-
export declare const TESTS_ENTRY_FILE = "
|
|
6
|
+
export declare const TESTS_ENTRY_FILE = "test.ts";
|
|
7
7
|
export declare const TSCONFIG_FILE_NAME = "tsconfig.json";
|
package/build/config/paths.js
CHANGED
|
@@ -14,5 +14,5 @@ exports.DEFAULT_BUILD_DIR = 'build';
|
|
|
14
14
|
exports.RCFILE_NAME = '.adonisrc.json';
|
|
15
15
|
exports.ENV_FILES = ['.env', '.env.testing'];
|
|
16
16
|
exports.SERVER_ENTRY_FILE = 'server.ts';
|
|
17
|
-
exports.TESTS_ENTRY_FILE = '
|
|
17
|
+
exports.TESTS_ENTRY_FILE = 'test.ts';
|
|
18
18
|
exports.TSCONFIG_FILE_NAME = 'tsconfig.json';
|
|
@@ -16,7 +16,8 @@ const env_1 = require("@adonisjs/env");
|
|
|
16
16
|
* Parses the env file inside the project root.
|
|
17
17
|
*/
|
|
18
18
|
class EnvParser {
|
|
19
|
-
constructor() {
|
|
19
|
+
constructor(envFileName = '.env') {
|
|
20
|
+
this.envFileName = envFileName;
|
|
20
21
|
this.envContents = {};
|
|
21
22
|
this.parser = new env_1.EnvParser(false);
|
|
22
23
|
}
|
|
@@ -25,7 +26,7 @@ class EnvParser {
|
|
|
25
26
|
*/
|
|
26
27
|
async parse(rootDir) {
|
|
27
28
|
try {
|
|
28
|
-
this.envContents = this.parser.parse(await (0, fs_extra_1.readFile)((0, path_1.join)(rootDir,
|
|
29
|
+
this.envContents = this.parser.parse(await (0, fs_extra_1.readFile)((0, path_1.join)(rootDir, this.envFileName), 'utf-8'));
|
|
29
30
|
}
|
|
30
31
|
catch { }
|
|
31
32
|
}
|
|
@@ -54,6 +54,11 @@ export declare class TestsServer {
|
|
|
54
54
|
* Kill current process
|
|
55
55
|
*/
|
|
56
56
|
private kill;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the HOST and the PORT environment variables
|
|
59
|
+
* for the HTTP server
|
|
60
|
+
*/
|
|
61
|
+
private getEnvironmentVariables;
|
|
57
62
|
/**
|
|
58
63
|
* Run tests. Use [[watch]] to also watch for file
|
|
59
64
|
* changes
|
package/build/src/Test/index.js
CHANGED
|
@@ -21,6 +21,8 @@ const RcFile_1 = require("../RcFile");
|
|
|
21
21
|
const Manifest_1 = require("../Manifest");
|
|
22
22
|
const process_1 = require("./process");
|
|
23
23
|
const paths_1 = require("../../config/paths");
|
|
24
|
+
const EnvParser_1 = require("../EnvParser");
|
|
25
|
+
const get_port_1 = __importDefault(require("get-port"));
|
|
24
26
|
/**
|
|
25
27
|
* Exposes the API to watch project for compilition changes and
|
|
26
28
|
* run/re-run tests
|
|
@@ -99,6 +101,26 @@ class TestsServer {
|
|
|
99
101
|
kill() {
|
|
100
102
|
process.exit();
|
|
101
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns the HOST and the PORT environment variables
|
|
106
|
+
* for the HTTP server
|
|
107
|
+
*/
|
|
108
|
+
async getEnvironmentVariables() {
|
|
109
|
+
const envParser = new EnvParser_1.EnvParser('.env.test');
|
|
110
|
+
await envParser.parse(this.appRoot);
|
|
111
|
+
const envOptions = envParser.asEnvObject(['PORT', 'TZ', 'HOST']);
|
|
112
|
+
const HOST = process.env.HOST || envOptions.HOST || '0.0.0.0';
|
|
113
|
+
let PORT = Number(process.env.PORT || envOptions.PORT);
|
|
114
|
+
/**
|
|
115
|
+
* Use the port defined inside ".env.test" file or use
|
|
116
|
+
* a random port
|
|
117
|
+
*/
|
|
118
|
+
PORT = await (0, get_port_1.default)({
|
|
119
|
+
port: !isNaN(PORT) ? [PORT] : [],
|
|
120
|
+
host: HOST,
|
|
121
|
+
});
|
|
122
|
+
return { HOST, PORT: String(PORT) };
|
|
123
|
+
}
|
|
102
124
|
/**
|
|
103
125
|
* Run tests. Use [[watch]] to also watch for file
|
|
104
126
|
* changes
|
|
@@ -116,7 +138,7 @@ class TestsServer {
|
|
|
116
138
|
filters['--files'] = [filePath];
|
|
117
139
|
}
|
|
118
140
|
this.busy = true;
|
|
119
|
-
const { hasErrors } = await new process_1.TestProcess(paths_1.TESTS_ENTRY_FILE, this.appRoot, filters, this.nodeArgs, this.logger,
|
|
141
|
+
const { hasErrors } = await new process_1.TestProcess(paths_1.TESTS_ENTRY_FILE, this.appRoot, filters, this.nodeArgs, this.logger, await this.getEnvironmentVariables()).run();
|
|
120
142
|
this.busy = false;
|
|
121
143
|
if (!this.watchingFileSystem) {
|
|
122
144
|
if (hasErrors) {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File source: https://bit.ly/3ukaHTz
|
|
3
|
+
*
|
|
4
|
+
* Feel free to let us know via PR, if you find something broken in this contract
|
|
5
|
+
* file.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Config } from '@japa/runner'
|
|
9
|
+
import TestUtils from '@ioc:Adonis/Core/TestUtils'
|
|
10
|
+
import { assert, runFailedTests, specReporter, apiClient } from '@japa/preset-adonis'
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
|--------------------------------------------------------------------------
|
|
14
|
+
| Japa Plugins
|
|
15
|
+
|--------------------------------------------------------------------------
|
|
16
|
+
|
|
|
17
|
+
| Japa plugins allows you to add additional features to Japa. By default
|
|
18
|
+
| we register the assertion plugin.
|
|
19
|
+
|
|
|
20
|
+
| Feel free to remove existing plugins or add more.
|
|
21
|
+
|
|
|
22
|
+
*/
|
|
23
|
+
export const plugins: Config['plugins'] = [assert(), runFailedTests(), apiClient()]
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
|--------------------------------------------------------------------------
|
|
27
|
+
| Japa Reporters
|
|
28
|
+
|--------------------------------------------------------------------------
|
|
29
|
+
|
|
|
30
|
+
| Japa reporters displays/saves the progress of tests as they are executed.
|
|
31
|
+
| By default, we register the spec reporter to show a detailed report
|
|
32
|
+
| of tests on the terminal.
|
|
33
|
+
|
|
|
34
|
+
*/
|
|
35
|
+
export const reporters: Config['reporters'] = [specReporter()]
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
|--------------------------------------------------------------------------
|
|
39
|
+
| Runner hooks
|
|
40
|
+
|--------------------------------------------------------------------------
|
|
41
|
+
|
|
|
42
|
+
| Runner hooks are executed after booting the AdonisJS app and
|
|
43
|
+
| before the test files are imported.
|
|
44
|
+
|
|
|
45
|
+
| You can perform actions like starting the HTTP server or running migrations
|
|
46
|
+
| within the runner hooks
|
|
47
|
+
|
|
|
48
|
+
*/
|
|
49
|
+
export const runnerHooks: Required<Pick<Config, 'setup' | 'teardown'>> = {
|
|
50
|
+
setup: [() => TestUtils.ace().loadCommands()],
|
|
51
|
+
teardown: [],
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
|--------------------------------------------------------------------------
|
|
56
|
+
| Configure individual suites
|
|
57
|
+
|--------------------------------------------------------------------------
|
|
58
|
+
|
|
|
59
|
+
| The configureSuite method gets called for every test suite registered
|
|
60
|
+
| within ".adonisrc.json" file.
|
|
61
|
+
|
|
|
62
|
+
| You can use this method to configure suites. For example: Only start
|
|
63
|
+
| the HTTP server when it is a functional suite.
|
|
64
|
+
*/
|
|
65
|
+
export const configureSuite: Config['configureSuite'] = (suite) => {
|
|
66
|
+
if (suite.name === 'functional') {
|
|
67
|
+
suite.setup(() => TestUtils.httpServer().start())
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Contract source: https://
|
|
2
|
+
* Contract source: https://bit.ly/3DP1ypf
|
|
3
3
|
*
|
|
4
4
|
* Feel free to let us know via PR, if you find something broken in this contract
|
|
5
5
|
* file.
|
|
@@ -12,7 +12,7 @@ declare module '@japa/runner' {
|
|
|
12
12
|
// Extend context
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
interface Test<
|
|
15
|
+
interface Test<TestData> {
|
|
16
16
|
// Extend test
|
|
17
17
|
}
|
|
18
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/assembler",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Core commands to compiler and build AdonisJs project",
|
|
5
5
|
"main": "build/ace-manifest.json",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"lint": "eslint . --ext=.ts",
|
|
20
20
|
"clean": "del build",
|
|
21
21
|
"compile": "npm run lint && npm run clean && tsc",
|
|
22
|
-
"build": "npm run compile && node build/bin/index.js && copyfiles \"templates
|
|
22
|
+
"build": "npm run compile && node build/bin/index.js && copyfiles \"templates/**\" build",
|
|
23
23
|
"commit": "git-cz",
|
|
24
24
|
"release": "np --message=\"chore(release): %s\"",
|
|
25
25
|
"version": "npm run build",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
},
|
|
113
113
|
"publishConfig": {
|
|
114
114
|
"access": "public",
|
|
115
|
-
"tag": "
|
|
115
|
+
"tag": "latest"
|
|
116
116
|
},
|
|
117
117
|
"mrmConfig": {
|
|
118
118
|
"core": true,
|