@adonisjs/assembler 5.5.3-0 → 5.5.4-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.
@@ -6,6 +6,7 @@ export default class Configure extends BaseCommand {
6
6
  static commandName: string;
7
7
  static description: string;
8
8
  static aliases: string[];
9
+ private appType;
9
10
  /**
10
11
  * Use yarn when building for production to install dependencies
11
12
  */
@@ -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, '..', 'templates/tests/functional/hello_world.spec.txt'));
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,20 @@ 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
+ sink_1.logger.action('create').succeeded('.env.test');
133
+ }
116
134
  /**
117
135
  * Install required dependencies
118
136
  */
@@ -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 = "tests.ts";
6
+ export declare const TESTS_ENTRY_FILE = "test.ts";
7
7
  export declare const TSCONFIG_FILE_NAME = "tsconfig.json";
@@ -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 = 'tests.ts';
17
+ exports.TESTS_ENTRY_FILE = 'test.ts';
18
18
  exports.TSCONFIG_FILE_NAME = 'tsconfig.json';
@@ -2,8 +2,10 @@
2
2
  * Parses the env file inside the project root.
3
3
  */
4
4
  export declare class EnvParser {
5
+ private envFileName;
5
6
  private envContents;
6
7
  private parser;
8
+ constructor(envFileName?: string);
7
9
  /**
8
10
  * Parse .env file contents
9
11
  */
@@ -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, '.env'), 'utf-8'));
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
@@ -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, {}).run();
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) {
@@ -12,7 +12,7 @@
12
12
  |
13
13
  */
14
14
 
15
- process.env.NODE_ENV = 'testing'
15
+ process.env.NODE_ENV = 'test'
16
16
 
17
17
  import 'reflect-metadata'
18
18
  import sourceMapSupport from 'source-map-support'
@@ -0,0 +1,8 @@
1
+ import { test } from '@japa/runner'
2
+
3
+ test('display welcome page', async ({ client }) => {
4
+ const response = await client.get('/')
5
+
6
+ response.assertStatus(200)
7
+ response.assertBodyContains({ hello: 'world' })
8
+ })
@@ -0,0 +1,8 @@
1
+ import { test } from '@japa/runner'
2
+
3
+ test('display welcome page', async ({ client }) => {
4
+ const response = await client.get('/')
5
+
6
+ response.assertStatus(200)
7
+ response.assertTextIncludes('hello world')
8
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/assembler",
3
- "version": "5.5.3-0",
3
+ "version": "5.5.4-0",
4
4
  "description": "Core commands to compiler and build AdonisJs project",
5
5
  "main": "build/ace-manifest.json",
6
6
  "files": [