diff --git a/package-lock.json b/package-lock.json index 20866c5..0364067 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/core", - "version": "5.1.0", + "version": "5.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/core", - "version": "5.1.0", + "version": "5.2.0", "license": "MIT", "dependencies": { "pretty-repl": "^3.1.2", @@ -16,7 +16,7 @@ "@athenna/artisan": "^5.1.0", "@athenna/common": "^5.0.0", "@athenna/config": "^5.0.0", - "@athenna/cron": "^5.1.0", + "@athenna/cron": "^5.2.0", "@athenna/http": "^5.1.0", "@athenna/ioc": "^5.0.0", "@athenna/logger": "^5.0.0", @@ -148,9 +148,9 @@ } }, "node_modules/@athenna/cron": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@athenna/cron/-/cron-5.1.0.tgz", - "integrity": "sha512-y4XyzaVKhD9l4OMS9QpJwklx7ziG259DjAklCenBbS6mkfamCM7AWqC1NE9Lys+dRx0Pmyr5z3AwT72PKobuwA==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@athenna/cron/-/cron-5.2.0.tgz", + "integrity": "sha512-GnXB1l0v/6yTqhtZMf8gnd/SD9qwqNr2uuPrCa6NVySdoRmoibKdZ67IIktVvkwaRJEArANpYy1YsmDndYWqjw==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index e67127d..7307e6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/core", - "version": "5.1.0", + "version": "5.2.0", "description": "One foundation for multiple applications.", "license": "MIT", "author": "João Lenon ", @@ -62,6 +62,7 @@ "./commands/BuildCommand": "./src/commands/BuildCommand.js", "./commands/InstallCommand": "./src/commands/InstallCommand.js", "./testing/BaseHttpTest": "./src/testing/BaseHttpTest.js", + "./testing/BaseCronTest": "./src/testing/BaseCronTest.js", "./testing/BaseConsoleTest": "./src/testing/BaseConsoleTest.js" }, "imports": { @@ -83,7 +84,7 @@ "@athenna/artisan": "^5.1.0", "@athenna/common": "^5.0.0", "@athenna/config": "^5.0.0", - "@athenna/cron": "^5.1.0", + "@athenna/cron": "^5.2.0", "@athenna/http": "^5.1.0", "@athenna/ioc": "^5.0.0", "@athenna/logger": "^5.0.0", @@ -212,6 +213,7 @@ "test": "./templates/test.edge", "test-console": "./templates/test-console.edge", "test-http": "./templates/test-http.edge", + "test-cron": "./templates/test-cron.edge", "test-fn": "./templates/test-fn.edge", "command": "node_modules/@athenna/artisan/templates/command.edge", "controller": "node_modules/@athenna/http/templates/controller.edge", diff --git a/src/commands/MakeTestCommand.ts b/src/commands/MakeTestCommand.ts index c78258a..8744c6b 100644 --- a/src/commands/MakeTestCommand.ts +++ b/src/commands/MakeTestCommand.ts @@ -37,6 +37,13 @@ export class MakeTestCommand extends BaseCommand { }) public isConsole: boolean + @Option({ + description: 'Create a Cron test.', + signature: '-cr, --cron', + default: false + }) + public isCron: boolean + @Option({ description: 'Create the test as function instead of class.', signature: '--function', @@ -58,6 +65,7 @@ export class MakeTestCommand extends BaseCommand { let template = 'test' if (this.isConsole) template = 'test-console' + else if (this.isCron) template = 'test-cron' else if (this.isHttp) template = 'test-http' else if (this.isUnit) template = 'test' // This is necessary to avoid multiple options case. diff --git a/src/testing/BaseCronTest.ts b/src/testing/BaseCronTest.ts new file mode 100644 index 0000000..bd7470c --- /dev/null +++ b/src/testing/BaseCronTest.ts @@ -0,0 +1,47 @@ +/** + * @athenna/core + * + * (c) João Lenon + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { CronImpl } from '@athenna/cron' +import { Path, Options } from '@athenna/common' +import { AfterAll, BeforeAll } from '@athenna/test' +import { Ignite, type CronOptions, type IgniteOptions } from '#src' + +export class BaseCronTest { + public ignite: Ignite + public cron: CronImpl + public cronOptions: CronOptions = {} + public igniteOptions: IgniteOptions = {} + + @BeforeAll() + public async baseBeforeAll() { + this.ignite = await new Ignite().load( + Path.toHref(Path.bin(`test.${Path.ext()}`)), + this.getIgniteOptions() + ) + + this.cron = await this.ignite.cron(this.getCronOptions()) + } + + @AfterAll() + public async baseAfterAll() { + await this.cron.close() + } + + private getCronOptions() { + return Options.create(this.cronOptions, {}) + } + + private getIgniteOptions() { + return Options.create(this.igniteOptions, { + bootLogs: false, + loadConfigSafe: false, + environments: ['test'] + }) + } +} diff --git a/templates/test-cron.edge b/templates/test-cron.edge new file mode 100644 index 0000000..4ecf41b --- /dev/null +++ b/templates/test-cron.edge @@ -0,0 +1,9 @@ +import { Test, type Context } from '@athenna/test' +import { BaseCronTest } from '@athenna/core/testing/BaseCronTest' + +export default class {{ namePascal }} extends BaseCronTest { + @Test() + public async shouldBeAbleToRunSchedulers({ scheduler }: Context) { + await scheduler.runByName('MySchedulerClassName') + } +} diff --git a/tests/unit/commands/MakeTestCommandTest.ts b/tests/unit/commands/MakeTestCommandTest.ts index a66f490..75d0dd7 100644 --- a/tests/unit/commands/MakeTestCommandTest.ts +++ b/tests/unit/commands/MakeTestCommandTest.ts @@ -56,6 +56,19 @@ export default class MakeTestCommandTest extends BaseCommandTest { assert.isTrue(await File.exists(Path.tests('e2e/TestTest.ts'))) } + @Test() + public async shouldBeAbleToCreateATestFileUsingCronTemplate({ assert, command }: Context) { + const output = await command.run('make:test TestTest --cron') + + console.log(output.output) + + output.assertSucceeded() + output.assertLogged('[ MAKING TEST ]') + output.assertLogged('[ success ] Test "TestTest" successfully created.') + + assert.isTrue(await File.exists(Path.tests('e2e/TestTest.ts'))) + } + @Test() public async shouldBeAbleToCreateATestFileUsingFunctionalTemplate({ assert, command }: Context) { const output = await command.run('make:test TestTest --function')