Skip to content

Commit

Permalink
Merge pull request #71 from AthennaIO/develop
Browse files Browse the repository at this point in the history
Fix Is.Module()
  • Loading branch information
jlenon7 authored Sep 7, 2023
2 parents 1ec0cc8 + 043debf commit efc6af6
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 50 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/unit/FakeApiTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/FileTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/HttpClientTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -321,14 +321,14 @@ 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 })

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'))
}
}
2 changes: 2 additions & 0 deletions tests/unit/IsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/ModuleTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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)

Expand All @@ -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')

Expand Down Expand Up @@ -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')
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/PathTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit efc6af6

Please sign in to comment.