From e3029a3d33910d082b46247584c121660dda1dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 7 Sep 2023 10:07:42 +0100 Subject: [PATCH 1/3] test(stubs): move to fixtures --- .gitignore | 6 +++--- tests/{stubs => fixtures}/config/app.ts | 0 tests/{stubs => fixtures}/controllers/app.controller.ts | 0 tests/{stubs => fixtures}/extensions/file.d.ts | 0 tests/{stubs => fixtures}/extensions/file.js.map | 0 tests/{stubs => fixtures}/no-export.ts | 0 .../{stubs => fixtures}/resources/fake-api/redirect.json | 0 .../resources/fake-api/service-unavailable.json | 0 .../resources/fake-api/users/delete-users.json | 0 .../resources/fake-api/users/get-users.json | 0 .../resources/fake-api/users/head-users.json | 0 .../resources/fake-api/users/patch-users.json | 0 .../resources/fake-api/users/post-users.json | 0 .../resources/fake-api/users/put-users.json | 0 tests/unit/FakeApiTest.ts | 2 +- tests/unit/FileTest.ts | 8 ++++---- tests/unit/HttpClientTest.ts | 6 +++--- tests/unit/ModuleTest.ts | 8 ++++---- tests/unit/PathTest.ts | 2 +- 19 files changed, 16 insertions(+), 16 deletions(-) rename tests/{stubs => fixtures}/config/app.ts (100%) rename tests/{stubs => fixtures}/controllers/app.controller.ts (100%) rename tests/{stubs => fixtures}/extensions/file.d.ts (100%) rename tests/{stubs => fixtures}/extensions/file.js.map (100%) rename tests/{stubs => fixtures}/no-export.ts (100%) rename tests/{stubs => fixtures}/resources/fake-api/redirect.json (100%) rename tests/{stubs => fixtures}/resources/fake-api/service-unavailable.json (100%) rename tests/{stubs => fixtures}/resources/fake-api/users/delete-users.json (100%) rename tests/{stubs => fixtures}/resources/fake-api/users/get-users.json (100%) rename tests/{stubs => fixtures}/resources/fake-api/users/head-users.json (100%) rename tests/{stubs => fixtures}/resources/fake-api/users/patch-users.json (100%) rename tests/{stubs => fixtures}/resources/fake-api/users/post-users.json (100%) rename tests/{stubs => fixtures}/resources/fake-api/users/put-users.json (100%) diff --git a/.gitignore b/.gitignore index d0a5509..6b64c32 100644 --- a/.gitignore +++ b/.gitignore @@ -120,9 +120,9 @@ build *.js *.d.ts *.js.map -!tests/stubs/**/*.js -!tests/stubs/**/*.d.ts -!tests/stubs/**/*.js.map +!tests/fixtures/**/*.js +!tests/fixtures/**/*.d.ts +!tests/fixtures/**/*.js.map # IDE .idea diff --git a/tests/stubs/config/app.ts b/tests/fixtures/config/app.ts similarity index 100% rename from tests/stubs/config/app.ts rename to tests/fixtures/config/app.ts diff --git a/tests/stubs/controllers/app.controller.ts b/tests/fixtures/controllers/app.controller.ts similarity index 100% rename from tests/stubs/controllers/app.controller.ts rename to tests/fixtures/controllers/app.controller.ts diff --git a/tests/stubs/extensions/file.d.ts b/tests/fixtures/extensions/file.d.ts similarity index 100% rename from tests/stubs/extensions/file.d.ts rename to tests/fixtures/extensions/file.d.ts diff --git a/tests/stubs/extensions/file.js.map b/tests/fixtures/extensions/file.js.map similarity index 100% rename from tests/stubs/extensions/file.js.map rename to tests/fixtures/extensions/file.js.map diff --git a/tests/stubs/no-export.ts b/tests/fixtures/no-export.ts similarity index 100% rename from tests/stubs/no-export.ts rename to tests/fixtures/no-export.ts diff --git a/tests/stubs/resources/fake-api/redirect.json b/tests/fixtures/resources/fake-api/redirect.json similarity index 100% rename from tests/stubs/resources/fake-api/redirect.json rename to tests/fixtures/resources/fake-api/redirect.json diff --git a/tests/stubs/resources/fake-api/service-unavailable.json b/tests/fixtures/resources/fake-api/service-unavailable.json similarity index 100% rename from tests/stubs/resources/fake-api/service-unavailable.json rename to tests/fixtures/resources/fake-api/service-unavailable.json diff --git a/tests/stubs/resources/fake-api/users/delete-users.json b/tests/fixtures/resources/fake-api/users/delete-users.json similarity index 100% rename from tests/stubs/resources/fake-api/users/delete-users.json rename to tests/fixtures/resources/fake-api/users/delete-users.json diff --git a/tests/stubs/resources/fake-api/users/get-users.json b/tests/fixtures/resources/fake-api/users/get-users.json similarity index 100% rename from tests/stubs/resources/fake-api/users/get-users.json rename to tests/fixtures/resources/fake-api/users/get-users.json diff --git a/tests/stubs/resources/fake-api/users/head-users.json b/tests/fixtures/resources/fake-api/users/head-users.json similarity index 100% rename from tests/stubs/resources/fake-api/users/head-users.json rename to tests/fixtures/resources/fake-api/users/head-users.json diff --git a/tests/stubs/resources/fake-api/users/patch-users.json b/tests/fixtures/resources/fake-api/users/patch-users.json similarity index 100% rename from tests/stubs/resources/fake-api/users/patch-users.json rename to tests/fixtures/resources/fake-api/users/patch-users.json diff --git a/tests/stubs/resources/fake-api/users/post-users.json b/tests/fixtures/resources/fake-api/users/post-users.json similarity index 100% rename from tests/stubs/resources/fake-api/users/post-users.json rename to tests/fixtures/resources/fake-api/users/post-users.json diff --git a/tests/stubs/resources/fake-api/users/put-users.json b/tests/fixtures/resources/fake-api/users/put-users.json similarity index 100% rename from tests/stubs/resources/fake-api/users/put-users.json rename to tests/fixtures/resources/fake-api/users/put-users.json diff --git a/tests/unit/FakeApiTest.ts b/tests/unit/FakeApiTest.ts index 6d691ef..071f1e4 100644 --- a/tests/unit/FakeApiTest.ts +++ b/tests/unit/FakeApiTest.ts @@ -13,7 +13,7 @@ import { Test, AfterAll, BeforeAll, AfterEach, type Context } from '@athenna/tes export default class FakeApiTest { @BeforeAll() public async beforeAll() { - await new Folder(Path.stubs('resources')).copy(Path.resources()) + await new Folder(Path.fixtures('resources')).copy(Path.resources()) } @AfterAll() diff --git a/tests/unit/FileTest.ts b/tests/unit/FileTest.ts index 07c7965..2b95379 100644 --- a/tests/unit/FileTest.ts +++ b/tests/unit/FileTest.ts @@ -85,7 +85,7 @@ export default class FileTest { @Test() public async shouldBeAbleToGenerateInstanceOfFilesThatHasDotsInThePath({ assert }: Context) { - const file = new File(Path.stubs('controllers/app.controller.ts')) + const file = new File(Path.fixtures('controllers/app.controller.ts')) assert.isTrue(file.fileExists) assert.equal(file.extension, '.ts') @@ -95,7 +95,7 @@ export default class FileTest { @Test() public async shouldBeAbleToGenerateInstanceOfFilesWithJsMapExtension({ assert }: Context) { - const file = new File(Path.stubs('extensions/file.js.map')) + const file = new File(Path.fixtures('extensions/file.js.map')) assert.isTrue(file.fileExists) assert.equal(file.name, 'file') @@ -105,7 +105,7 @@ export default class FileTest { @Test() public async shouldBeAbleToGenerateInstanceOfFilesWithDTsExtension({ assert }: Context) { - const file = new File(Path.stubs('extensions/file.d.ts')) + const file = new File(Path.fixtures('extensions/file.d.ts')) assert.isTrue(file.fileExists) assert.equal(file.name, 'file') @@ -362,7 +362,7 @@ export default class FileTest { @Test() public async shouldBeAbleToSafeImportSomeFileThatDoesNotExportAnythingWithoutErrors({ assert }: Context) { - const notFound = await new File(Path.stubs('no-export.ts')).safeImport() + const notFound = await new File(Path.fixtures('no-export.ts')).safeImport() assert.isNull(notFound) } diff --git a/tests/unit/HttpClientTest.ts b/tests/unit/HttpClientTest.ts index 351e5dc..456896a 100644 --- a/tests/unit/HttpClientTest.ts +++ b/tests/unit/HttpClientTest.ts @@ -18,7 +18,7 @@ export default class HttpClientTest { @BeforeAll() public async beforeAll() { - await FakeApi.start(8989, Path.stubs('resources/fake-api')) + await FakeApi.start(8989, Path.fixtures('resources/fake-api')) } @BeforeEach() @@ -321,7 +321,7 @@ export default class HttpClientTest { @Test() public async shouldBeAbleToMakeAGetRequestAndGetTheResponseAsStream({ assert }: Context) { const requestStream = HttpClient.builder().url('users').stream() - const file = new File(Path.stubs('streamed.json'), Buffer.from('')) + const file = new File(Path.fixtures('streamed.json'), Buffer.from('')) await this.pipeline(requestStream, file.createWriteStream()) await file.load({ withContent: true }) @@ -329,6 +329,6 @@ export default class HttpClientTest { assert.isTrue(file.fileExists) assert.deepEqual(file.content.toString(), '[{"id":1,"name":"Robson Trasel"},{"id":2,"name":"Victor Tesoura"}]') - await File.safeRemove(Path.stubs('streamed.json')) + await File.safeRemove(Path.fixtures('streamed.json')) } } diff --git a/tests/unit/ModuleTest.ts b/tests/unit/ModuleTest.ts index 955d93d..df2b546 100644 --- a/tests/unit/ModuleTest.ts +++ b/tests/unit/ModuleTest.ts @@ -14,7 +14,7 @@ import { NotFoundResolveException } from '#src/exceptions/NotFoundResolveExcepti export default class ModuleTest { @Test() public async shouldBeAbleToGetTheModuleFirstExportMatchOrDefault({ assert }: Context) { - const moduleDefault = await Module.get(import('../stubs/config/app.js')) + const moduleDefault = await Module.get(import('../fixtures/config/app.js')) assert.equal(moduleDefault.name, 'Athenna') @@ -25,7 +25,7 @@ export default class ModuleTest { @Test() public async shouldBeAbleToGetAllModulesFirstExportMatchOrDefault({ assert }: Context) { - const modules = [import('../stubs/config/app.js'), import('#src/helpers/Options')] + const modules = [import('../fixtures/config/app.js'), import('#src/helpers/Options')] const modulesResolved = await Module.getAll(modules) @@ -48,7 +48,7 @@ export default class ModuleTest { @Test() public async shouldBeAbleToGetTheModuleFirstExportMatchOrDefaultFromAnyPath({ assert }: Context) { - const moduleDefault = await Module.getFrom(Path.stubs('config/app.ts')) + const moduleDefault = await Module.getFrom(Path.fixtures('config/app.ts')) assert.equal(moduleDefault.name, 'Athenna') @@ -104,7 +104,7 @@ export default class ModuleTest { @Test() public async shouldBeAbleToResolveImportAliasWithDotsInThePathByMetaUrlAndImportIt({ assert }: Context) { - const AppController = await Module.resolve('#tests/stubs/controllers/app.controller', import.meta.url) + const AppController = await Module.resolve('#tests/fixtures/controllers/app.controller', import.meta.url) assert.equal(AppController.name, 'AppController') } diff --git a/tests/unit/PathTest.ts b/tests/unit/PathTest.ts index 9608f37..bd72c81 100644 --- a/tests/unit/PathTest.ts +++ b/tests/unit/PathTest.ts @@ -124,7 +124,7 @@ export default class PathTest { public async shouldGetTheSubOPathsOfTestsMainPath({ assert }: Context) { const mainPath = process.cwd().concat(sep, 'tests') - assert.equal(Path.stubs(), mainPath.concat(sep, 'stubs')) + assert.equal(Path.fixtures(), mainPath.concat(sep, 'fixtures')) } @Test() From 4703e343892c20ae9d9a4677557188a065db2953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 7 Sep 2023 10:09:18 +0100 Subject: [PATCH 2/3] chore(npm): update dependencies --- package-lock.json | 60 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 852dcf1..cd257ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3534,9 +3534,9 @@ } }, "node_modules/eslint-plugin-import/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -3883,9 +3883,9 @@ } }, "node_modules/execa/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true, "bin": { "semver": "bin/semver" @@ -6521,9 +6521,9 @@ } }, "node_modules/make-dir/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -6734,9 +6734,9 @@ } }, "node_modules/normalize-package-data/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true, "bin": { "semver": "bin/semver" @@ -8913,9 +8913,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, "engines": { "node": ">=0.10.0" @@ -11824,9 +11824,9 @@ } }, "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true } } @@ -12015,9 +12015,9 @@ "dev": true }, "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true }, "shebang-command": { @@ -14010,9 +14010,9 @@ }, "dependencies": { "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==" } } }, @@ -14191,9 +14191,9 @@ }, "dependencies": { "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true } } @@ -15792,9 +15792,9 @@ } }, "word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true }, "wordwrap": { From 043debf7c3ec210d3526349b509bb5fd4eee4792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 7 Sep 2023 10:29:26 +0100 Subject: [PATCH 3/3] fix(is): use endsWith to avoid problems --- package-lock.json | 4 ++-- package.json | 2 +- src/helpers/Is.ts | 2 +- tests/unit/IsTest.ts | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index cd257ae..e57ab69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/common", - "version": "4.10.0", + "version": "4.10.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@athenna/common", - "version": "4.10.0", + "version": "4.10.1", "license": "MIT", "dependencies": { "@fastify/formbody": "^7.4.0", diff --git a/package.json b/package.json index 9f636dc..7a225ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/common", - "version": "4.10.0", + "version": "4.10.1", "description": "The Athenna common helpers to use in any Node.js ESM project.", "license": "MIT", "author": "João Lenon ", diff --git a/src/helpers/Is.ts b/src/helpers/Is.ts index 49d4e0f..4110992 100644 --- a/src/helpers/Is.ts +++ b/src/helpers/Is.ts @@ -64,7 +64,7 @@ export class Is { return false } - if (value.includes('.js') || value.includes('.ts')) { + if (value.endsWith('.js') || value.endsWith('.ts')) { return true } diff --git a/tests/unit/IsTest.ts b/tests/unit/IsTest.ts index a81dc78..13e0e93 100644 --- a/tests/unit/IsTest.ts +++ b/tests/unit/IsTest.ts @@ -15,6 +15,8 @@ export default class IsTest { public async shouldVerifyIfIsAValidModule({ assert }: Context) { assert.isFalse(Is.Module('')) assert.isFalse(Is.Module('Hello')) + assert.isFalse(Is.Module('.json')) + assert.isFalse(Is.Module(Path.pwd('package.json'))) assert.isTrue(Is.Module('.js')) assert.isTrue(Is.Module('.ts')) assert.isTrue(Is.Module(Path.src('helpers/Clean.js')))