diff --git a/package.json b/package.json index 2ae6c17..5f4a0e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/artisan", - "version": "1.3.1", + "version": "1.3.2", "description": "The Athenna CLI application. Built on top of commander.", "license": "MIT", "author": "João Lenon ", @@ -35,6 +35,14 @@ "exports": { ".": "./src/index.js", "./facades/Artisan": "./src/Facades/Log.js", + "./commands/List": "./src/Commands/List.js", + "./commands/Serve": "./src/Commands/Serve.js", + "./commands/Eslint": "./src/Commands/Eslint/Fix.js", + "./commands/Make/Command": "./src/Commands/Make/Command.js", + "./commands/Make/Exception": "./src/Commands/Make/Exception.js", + "./commands/Make/Facade": "./src/Commands/Make/Facade.js", + "./commands/Make/Provider": "./src/Commands/Make/Provider.js", + "./commands/Make/Service": "./src/Commands/Make/Service.js", "./providers/ArtisanProvider": "./src/Providers/ArtisanProvider.js" }, "imports": { diff --git a/src/Commands/Make/Test.js b/src/Commands/Make/Test.js deleted file mode 100644 index 7dffea8..0000000 --- a/src/Commands/Make/Test.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @athenna/artisan - * - * (c) João Lenon - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -import { Path } from '@secjs/utils' -import { Artisan, Command } from '#src/index' -import { TemplateHelper } from '#src/Helpers/TemplateHelper' - -export class MakeTest extends Command { - /** - * The name and signature of the console command. - * - * @return {string} - */ - get signature() { - return 'make:test ' - } - - /** - * The console command description. - * - * @return {string} - */ - get description() { - return 'Make a new test file.' - } - - /** - * Set additional flags in the commander instance. - * This method is executed when registering your command. - * - * @param {import('commander').Command} commander - * @return {import('commander').Command} - */ - addFlags(commander) { - return commander - .option('-u, --unit', 'Create the test inside unit folder.', false) - .option('--no-lint', 'Do not run eslint in the facade.', true) - } - - /** - * Execute the console command. - * - * @param {string} name - * @param {any} options - * @return {Promise} - */ - async handle(name, options) { - const resource = 'Test' - let subPath = Path.tests('E2E') - - if (options.unit) { - subPath = Path.tests('Unit') - } - - this.simpleLog( - `[ MAKING ${resource.toUpperCase()} ]\n`, - 'rmNewLineStart', - 'bold', - 'green', - ) - - const file = await TemplateHelper.getResourceFile(name, resource, subPath) - - this.success(`${resource} ({yellow} "${file.name}") successfully created.`) - - if (options.lint) { - await Artisan.call(`eslint:fix ${file.path} --resource ${resource}`) - } - } -} diff --git a/src/Commands/Test.js b/src/Commands/Test.js deleted file mode 100644 index 816ff9b..0000000 --- a/src/Commands/Test.js +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @athenna/artisan - * - * (c) João Lenon - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -import { Path, Config } from '@secjs/utils' - -import { Command } from '#src/index' - -export class Test extends Command { - /** - * The name and signature of the console command. - * - * @return {string} - */ - get signature() { - return 'test' - } - - /** - * The console command description. - * - * @return {string} - */ - get description() { - return 'Run the tests of Athenna application.' - } - - /** - * Set additional flags in the commander instance. - * This method is executed when registering your command. - * - * @param {import('commander').Command} commander - * @return {import('commander').Command} - */ - addFlags(commander) { - return commander - .option('--debug', 'Enable debug mode to see more logs.', false) - .option('--unit', 'Run unit tests.', false) - .option('--e2e', 'Run e2e tests.', false) - .option( - '-e, --env ', - 'Change the environment where the test will run. Default is "test"', - 'test', - ) - } - - /** - * Execute the console command. - * - * @params {any} options - * @return {Promise} - */ - async handle(options) { - Config.configs.clear() - - process.env.NODE_ENV = options.env - process.env.BOOT_LOGS = 'false' - - const protectedArgs = ['--e2e', '--unit', '--debug'] - - process.argv = process.argv.filter(arg => !protectedArgs.includes(arg)) - - if (options.e2e) { - process.argv.push('E2E') - } - - if (options.unit) { - process.argv.push('Unit') - } - - if (options.debug) { - process.env.DEBUG = 'api:*' - } - - await import(Path.tests('main.js')) - } -} diff --git a/src/Helpers/ArtisanLoader.js b/src/Helpers/ArtisanLoader.js index 6562da1..b5418dd 100644 --- a/src/Helpers/ArtisanLoader.js +++ b/src/Helpers/ArtisanLoader.js @@ -6,11 +6,9 @@ export class ArtisanLoader { */ static loadCommands() { return [ - import('#src/Commands/Test'), import('#src/Commands/List'), import('#src/Commands/Serve'), import('#src/Commands/Eslint/Fix'), - import('#src/Commands/Make/Test'), import('#src/Commands/Make/Facade'), import('#src/Commands/Make/Service'), import('#src/Commands/Make/Command'), diff --git a/templates/__name__Test.js.ejs b/templates/__name__Test.js.ejs deleted file mode 100644 index 5ac63d7..0000000 --- a/templates/__name__Test.js.ejs +++ /dev/null @@ -1,7 +0,0 @@ -import { test } from '@japa/runner' - -test.group('<%= namePascal %>Test', () => { - test('should be able to run tests', async ({ assert }) => { - assert.equal(2 + 2, 4) - }) -}) diff --git a/tests/Unit/Commands/Make/TestTest.js b/tests/Unit/Commands/Make/TestTest.js deleted file mode 100644 index 3172831..0000000 --- a/tests/Unit/Commands/Make/TestTest.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @athenna/artisan - * - * (c) João Lenon - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -import { test } from '@japa/runner' -import { Config, File, Folder, Path } from '@secjs/utils' - -import { Artisan } from '#src/index' -import { Kernel } from '#tests/Stubs/app/Console/Kernel' -import { ArtisanProvider } from '#src/Providers/ArtisanProvider' -import { LoggerProvider } from '@athenna/logger/providers/LoggerProvider' - -test.group('MakeTestTest', group => { - group.each.setup(async () => { - await new Folder(Path.stubs('app')).copy(Path.app()) - await new Folder(Path.stubs('config')).copy(Path.config()) - - await new Config().safeLoad(Path.config('app.js')) - await new Config().safeLoad(Path.config('logging.js')) - - new LoggerProvider().register() - new ArtisanProvider().register() - - const kernel = new Kernel() - - await kernel.registerErrorHandler() - await kernel.registerCommands() - }) - - group.each.teardown(async () => { - await Folder.safeRemove(Path.app()) - await Folder.safeRemove(Path.config()) - await Folder.safeRemove(Path.providers()) - }) - - test('should be able to create a test file', async ({ assert }) => { - await Artisan.call('make:test FeatureTest') - - const path = Path.tests('E2E/FeatureTest.js') - - assert.isTrue(await File.exists(path)) - - await Folder.safeRemove(Path.tests('E2E')) - }).timeout(60000) - - test('should be able to create a unit test file', async ({ assert }) => { - await Artisan.call('make:test --unit UnitTest') - - const path = Path.tests('Unit/UnitTest.js') - - assert.isTrue(await File.exists(path)) - - await File.safeRemove(path) - }).timeout(60000) - - test('should throw an error when the file already exists', async ({ assert }) => { - await Artisan.call('make:test TestTest') - await Artisan.call('make:test TestTest') - - await Folder.safeRemove(Path.tests('E2E')) - }).timeout(60000) -})