@adonisjs/assembler 5.5.3-0 → 5.6.1

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');
@@ -111,8 +115,43 @@ class Configure extends standalone_1.BaseCommand {
111
115
  },
112
116
  ],
113
117
  });
118
+ rcFile.addProvider('@japa/preset-adonis/TestsProvider');
114
119
  rcFile.commit();
115
120
  sink_1.logger.action('update').succeeded('.adonisrc.json');
121
+ /**
122
+ * Create ".env.test" file
123
+ */
124
+ const testEnvFile = new sink_1.files.NewLineFile(this.application.appRoot, '.env.test');
125
+ if (!testEnvFile.exists()) {
126
+ testEnvFile.add('NODE_ENV=test');
127
+ /**
128
+ * Set additional .env variables for "web" boilerplate
129
+ */
130
+ if (this.appType === 'web') {
131
+ testEnvFile.add(['ASSETS_DRIVER=fake', 'SESSION_DRIVER=memory']);
132
+ }
133
+ testEnvFile.commit();
134
+ sink_1.logger.action('create').succeeded('.env.test');
135
+ }
136
+ /**
137
+ * Update "tsconfig.json"
138
+ */
139
+ const tsConfig = new sink_1.files.JsonFile(this.application.appRoot, 'tsconfig.json');
140
+ const existingTypes = tsConfig.get('compilerOptions.types') || [];
141
+ if (!existingTypes.includes('@japa/preset-adonis/build/adonis-typings')) {
142
+ existingTypes.push('@japa/preset-adonis/build/adonis-typings');
143
+ }
144
+ tsConfig.set('compilerOptions.types', existingTypes);
145
+ tsConfig.commit();
146
+ sink_1.logger.action('update').succeeded('tsconfig.json');
147
+ /**
148
+ * Set additional .env variables for "web" boilerplate
149
+ */
150
+ if (this.appType === 'web') {
151
+ testEnvFile.add(['ASSETS_DRIVER=fake', 'SESSION_DRIVER=memory']);
152
+ }
153
+ testEnvFile.commit();
154
+ sink_1.logger.action('create').succeeded('.env.test');
116
155
  /**
117
156
  * Install required dependencies
118
157
  */
@@ -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
  }
@@ -44,6 +44,10 @@ export declare class TestsServer {
44
44
  */
45
45
  private isTestFile;
46
46
  constructor(appRoot: string, filters: JapaFlags, nodeArgs?: string[], logger?: typeof uiLogger);
47
+ /**
48
+ * Clear terminal screen
49
+ */
50
+ private clearScreen;
47
51
  /**
48
52
  * Returns the glob paths for test suites. Returns all if no
49
53
  * filter is applied. Otherwise only the filtered suites
@@ -54,6 +58,11 @@ export declare class TestsServer {
54
58
  * Kill current process
55
59
  */
56
60
  private kill;
61
+ /**
62
+ * Returns the HOST and the PORT environment variables
63
+ * for the HTTP server
64
+ */
65
+ private getEnvironmentVariables;
57
66
  /**
58
67
  * Run tests. Use [[watch]] to also watch for file
59
68
  * 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
@@ -77,6 +79,12 @@ class TestsServer {
77
79
  });
78
80
  };
79
81
  }
82
+ /**
83
+ * Clear terminal screen
84
+ */
85
+ clearScreen() {
86
+ process.stdout.write('\u001Bc');
87
+ }
80
88
  /**
81
89
  * Returns the glob paths for test suites. Returns all if no
82
90
  * filter is applied. Otherwise only the filtered suites
@@ -99,6 +107,26 @@ class TestsServer {
99
107
  kill() {
100
108
  process.exit();
101
109
  }
110
+ /**
111
+ * Returns the HOST and the PORT environment variables
112
+ * for the HTTP server
113
+ */
114
+ async getEnvironmentVariables() {
115
+ const envParser = new EnvParser_1.EnvParser('.env.test');
116
+ await envParser.parse(this.appRoot);
117
+ const envOptions = envParser.asEnvObject(['PORT', 'TZ', 'HOST']);
118
+ const HOST = process.env.HOST || envOptions.HOST || '0.0.0.0';
119
+ let PORT = Number(process.env.PORT || envOptions.PORT);
120
+ /**
121
+ * Use the port defined inside ".env.test" file or use
122
+ * a random port
123
+ */
124
+ PORT = await (0, get_port_1.default)({
125
+ port: !isNaN(PORT) ? [PORT] : [],
126
+ host: HOST,
127
+ });
128
+ return { HOST, PORT: String(PORT) };
129
+ }
102
130
  /**
103
131
  * Run tests. Use [[watch]] to also watch for file
104
132
  * changes
@@ -107,6 +135,7 @@ class TestsServer {
107
135
  if (this.busy) {
108
136
  return;
109
137
  }
138
+ this.clearScreen();
110
139
  const filters = { ...this.filters };
111
140
  /**
112
141
  * Overwrite files filter when a specific file path
@@ -116,7 +145,7 @@ class TestsServer {
116
145
  filters['--files'] = [filePath];
117
146
  }
118
147
  this.busy = true;
119
- const { hasErrors } = await new process_1.TestProcess(paths_1.TESTS_ENTRY_FILE, this.appRoot, filters, this.nodeArgs, this.logger, {}).run();
148
+ const { hasErrors } = await new process_1.TestProcess(paths_1.TESTS_ENTRY_FILE, this.appRoot, filters, this.nodeArgs, this.logger, await this.getEnvironmentVariables()).run();
120
149
  this.busy = false;
121
150
  if (!this.watchingFileSystem) {
122
151
  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
+ })
@@ -12,7 +12,7 @@ declare module '@japa/runner' {
12
12
  // Extend context
13
13
  }
14
14
 
15
- interface Test<DataSet> {
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.5.3-0",
3
+ "version": "5.6.1",
4
4
  "description": "Core commands to compiler and build AdonisJs project",
5
5
  "main": "build/ace-manifest.json",
6
6
  "files": [
@@ -45,7 +45,7 @@
45
45
  "homepage": "https://github.com/adonisjs/assembler#readme",
46
46
  "devDependencies": {
47
47
  "@adonisjs/ace": "^11.2.3",
48
- "@adonisjs/core": "^5.6.2",
48
+ "@adonisjs/core": "^5.7.3",
49
49
  "@adonisjs/mrm-preset": "^5.0.3",
50
50
  "@poppinss/dev-utils": "^2.0.3",
51
51
  "@types/node": "^17.0.23",
@@ -54,7 +54,7 @@
54
54
  "cross-env": "^7.0.3",
55
55
  "cz-conventional-changelog": "^3.3.0",
56
56
  "del-cli": "^4.0.1",
57
- "eslint": "^8.12.0",
57
+ "eslint": "^8.13.0",
58
58
  "eslint-config-prettier": "^8.5.0",
59
59
  "eslint-plugin-adonis": "^2.1.0",
60
60
  "eslint-plugin-prettier": "^4.0.0",
@@ -89,14 +89,14 @@
89
89
  "anyBranch": false
90
90
  },
91
91
  "dependencies": {
92
- "@adonisjs/application": "^5.2.1",
93
- "@adonisjs/env": "^3.0.8",
92
+ "@adonisjs/application": "^5.2.3",
93
+ "@adonisjs/env": "^3.0.9",
94
94
  "@adonisjs/ioc-transformer": "^2.3.3",
95
95
  "@adonisjs/require-ts": "^2.0.11",
96
96
  "@adonisjs/sink": "^5.2.2",
97
97
  "@poppinss/chokidar-ts": "^3.3.5",
98
98
  "@poppinss/cliui": "^3.0.2",
99
- "@poppinss/utils": "^4.0.3",
99
+ "@poppinss/utils": "^4.0.4",
100
100
  "cpy": "^8.1.2",
101
101
  "emittery": "^0.10.2",
102
102
  "execa": "^5.1.1",
@@ -112,7 +112,7 @@
112
112
  },
113
113
  "publishConfig": {
114
114
  "access": "public",
115
- "tag": "next"
115
+ "tag": "latest"
116
116
  },
117
117
  "mrmConfig": {
118
118
  "core": true,