Skip to content

Commit

Permalink
test: migrate to the new Japa (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 authored Mar 3, 2022
1 parent 5e9ddf4 commit cb15d56
Show file tree
Hide file tree
Showing 42 changed files with 2,163 additions and 2,035 deletions.
11 changes: 0 additions & 11 deletions .bin/test.js

This file was deleted.

7 changes: 7 additions & 0 deletions bin/japaTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Assert } from '@japa/assert'

declare module '@japa/runner' {
interface TestContext {
assert: Assert
}
}
44 changes: 44 additions & 0 deletions bin/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { assert } from '@japa/assert'
import { specReporter } from '@japa/spec-reporter'
import { runFailedTests } from '@japa/run-failed-tests'
import { processCliArgs, configure, run } from '@japa/runner'
import { remove } from 'fs-extra'
import { join } from 'path'

/*
|--------------------------------------------------------------------------
| 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: ['test/**/*.spec.ts', '!test/database/drop-table.spec.ts'],
plugins: [assert(), runFailedTests()],
reporters: [specReporter()],
importer: (filePath: string) => import(filePath),
teardown: [
async () => {
await remove(join(__dirname, 'test-helpers', 'tmp'))
},
],
},
})

/*
|--------------------------------------------------------------------------
| Run tests
|--------------------------------------------------------------------------
|
| The following "run" method is required to execute all the tests.
|
*/
run()
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test:better_sqlite": "cross-env DB=better_sqlite FORCE_COLOR=true node ./.bin/test.js",
"test:sqlite": "cross-env DB=sqlite FORCE_COLOR=true node ./.bin/test.js",
"test:mysql": "cross-env DB=mysql FORCE_COLOR=true node ./.bin/test.js",
"test:mysql_legacy": "cross-env DB=mysql_legacy FORCE_COLOR=true node ./.bin/test.js",
"test:mssql": "cross-env DB=mssql FORCE_COLOR=true node ./.bin/test.js",
"test:pg": "cross-env DB=pg FORCE_COLOR=true node ./.bin/test.js",
"test:better_sqlite": "cross-env DB=better_sqlite FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts",
"test:sqlite": "cross-env DB=sqlite FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts",
"test:mysql": "cross-env DB=mysql FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts",
"test:mysql_legacy": "cross-env DB=mysql_legacy FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts",
"test:mssql": "cross-env DB=mssql FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts",
"test:pg": "cross-env DB=pg FORCE_COLOR=true node -r @adonisjs/require-ts/build/register ./bin/test.ts",
"test:docker": "npm run test:mysql && npm run test:mysql_legacy && npm run test:pg && npm run test:mssql",
"test": "docker-compose -f docker-compose.yml -f docker-compose-test.yml build && docker-compose -f docker-compose.yml -f docker-compose-test.yml run --rm test && npm run test:sqlite && npm run test:better_sqlite",
"lint": "eslint . --ext=.ts",
Expand Down Expand Up @@ -69,6 +69,10 @@
"@adonisjs/repl": "^3.1.8",
"@adonisjs/require-ts": "^2.0.10",
"@adonisjs/sink": "^5.2.2",
"@japa/assert": "^1.2.3",
"@japa/run-failed-tests": "^1.0.3",
"@japa/runner": "^1.2.0",
"@japa/spec-reporter": "^1.1.7",
"@poppinss/dev-utils": "^2.0.2",
"@types/luxon": "^2.0.9",
"@types/node": "^17.0.21",
Expand All @@ -90,7 +94,6 @@
"fs-extra": "^10.0.1",
"github-label-sync": "^2.0.1",
"husky": "^7.0.4",
"japa": "^4.0.0",
"mrm": "^3.0.10",
"mysql": "^2.18.1",
"np": "^7.6.0",
Expand Down
2 changes: 2 additions & 0 deletions src/Dialects/Mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export class MysqlDialect implements DialectContract {
public async dropAllTables() {
let tables = await this.getAllTables()

if (!tables.length) return

/**
* Add backquote around table names to avoid syntax errors
* in case of a table name with a reserved keyword
Expand Down
Loading

0 comments on commit cb15d56

Please sign in to comment.