Skip to content

Commit

Permalink
Merge pull request #75 from AthennaIO/develop
Browse files Browse the repository at this point in the history
Move project to TS
  • Loading branch information
jlenon7 committed Mar 9, 2023
2 parents 2fd414f + dedcfa1 commit bafd8b4
Show file tree
Hide file tree
Showing 78 changed files with 3,310 additions and 12,075 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github: [jlenon7, txsoura]
open_collective: athennaio
13 changes: 12 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -20,9 +20,20 @@ jobs:

- name: Install dependencies
run: npm install

- name: Transpile code
run: npm run build

- name: Install jq
run: sudo apt-get -y install jq

- name: Change import aliases to build
run: jq '.imports."#src"="./build/index.js" | .imports."#src/*"="./build/*.js"' package.json > tmp.json && mv tmp.json package.json

- name: Automatic GitHub Release
uses: justincy/github-action-npm-release@2.0.1
id: release

- name: Publish to NPM Registry
run: npm publish --access public
if: steps.release.outputs.released == 'true'
Expand Down
40 changes: 39 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ on:
- develop

jobs:
qodana:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@main
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

linux:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 14.15.4
- 16.13.1
- 18.x
steps:
- uses: actions/checkout@v2
Expand All @@ -27,5 +38,32 @@ jobs:

- name: Install dependencies
run: npm install

- name: Run tests
run: npm run test:coverage

- name: Test code transpilation
run: npm run build

windows:
runs-on: windows-latest
strategy:
matrix:
node-version:
- 16.13.1
- 18.x
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Run tests
run: npm run test:coverage

- name: Test code transpilation
run: npm run build
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ out
.yarn/install-state.gz
.pnp.*

# Transpiled code path
dist
build

# IDE
.idea
.fleet
.vscode

# Environment variables file
Expand Down
52 changes: 52 additions & 0 deletions bin/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @athenna/test
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { Path, File, Exec } from '@athenna/common'

/*
|--------------------------------------------------------------------------
| TypeScript build file path
|--------------------------------------------------------------------------
|
| Where the TypeScript build file will be saved.
*/

const path = Path.nodeModules('@athenna/tsconfig.build.json')

/*
|--------------------------------------------------------------------------
| TypeScript Config
|--------------------------------------------------------------------------
|
| Create the tsconfig file for building the project.
*/

const tsconfig = await new File('../tsconfig.json').getContentAsJson()

delete tsconfig['ts-node']

tsconfig.compilerOptions.rootDir = '../../src'
tsconfig.compilerOptions.outDir = '../../build'

tsconfig.include = ['../../src']
tsconfig.exclude = ['../../bin', '../../node_modules', '../../tests']

/*
|--------------------------------------------------------------------------
| Compilation
|--------------------------------------------------------------------------
|
| Saving the file in some path, deleting old "build" folder, executing
| compilation and deleting the tsconfig file generated.
*/

const file = new File(path, '')
await file.setContent(JSON.stringify(tsconfig))
await Exec.command(`rimraf ../build && tsc --project ${path}`)
await file.remove()
91 changes: 91 additions & 0 deletions bin/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* @athenna/test
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { Importer } from '#src'
import { assert } from '@japa/assert'
import { specReporter } from '@japa/spec-reporter'
import { configure, processCliArgs, run } from '@japa/runner'

/*
|--------------------------------------------------------------------------
| Japa types
|--------------------------------------------------------------------------
|
| Declare customized japa types.
*/

declare module '@japa/assert' {
export interface Assert {
throws(fn: () => any, errType: any, message?: string): void
doesNotThrows(fn: () => any, errType: any, message?: string): void
rejects(
fn: () => any | Promise<any>,
errType: any,
message?: string,
): Promise<any>
doesNotRejects(
fn: () => any | Promise<any>,
errType: any,
message?: string,
): Promise<any>
}
}

declare module '@japa/runner' {
interface TestContext {
assert: import('@japa/assert').Assert
}
}

/*
|--------------------------------------------------------------------------
| Set IS_TS env.
|--------------------------------------------------------------------------
|
| Set the IS_TS environement variable to true. Very useful when using the
| Path helper.
*/

process.env.IS_TS = 'true'

/*
|--------------------------------------------------------------------------
| Configure tests
|--------------------------------------------------------------------------
|
| The configure method accepts the configuration to configure the Japa
| tests runner.
|
| The first method call "processCliArgs" process the command line arguments
| and turns them into a config object. Using this method is not mandatory.
|
| Please consult japa.dev/runner-config for the config docs.
*/

configure({
...processCliArgs(process.argv.slice(2)),
...{
files: ['tests/**/*Test.ts'],
plugins: [assert()],
reporters: [specReporter()],
importer: Importer.import,
},
timeout: 10000,
})

/*
|--------------------------------------------------------------------------
| Run tests
|--------------------------------------------------------------------------
|
| The following "run" method is required to execute all the tests.
|
*/

run()
Loading

0 comments on commit bafd8b4

Please sign in to comment.