-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e81f155
commit b80fb82
Showing
8 changed files
with
245 additions
and
771 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
import { assert } from '@japa/assert' | ||
import { configure, processCLIArgs, run } from '@japa/runner' | ||
|
||
processCLIArgs(process.argv.splice(2)) | ||
import { fileSystem } from '@japa/file-system' | ||
import { expectTypeOf } from '@japa/expect-type' | ||
import { processCLIArgs, configure, run } from '@japa/runner' | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| 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. | ||
*/ | ||
processCLIArgs(process.argv.slice(2)) | ||
configure({ | ||
files: ['tests/**/*.spec.ts'], | ||
plugins: [assert()], | ||
plugins: [assert(), expectTypeOf(), fileSystem({ autoClean: true })], | ||
}) | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Run tests | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The following "run" method is required to execute all the tests. | ||
| | ||
*/ | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,64 @@ | ||
import { HttpContext } from '@adonisjs/core/http' | ||
import { test } from '@japa/runner' | ||
import { createTuyau } from '@tuyau/client' | ||
import { Serialize } from '@tuyau/utils/types' | ||
import { Simplify, ConvertReturnTypeToRecordStatusResponse } from '@tuyau/utils/types' | ||
import nock from 'nock' | ||
|
||
test.group('Example', () => { | ||
test('add two numbers', ({ assert }) => { | ||
assert.equal(1 + 1, 2) | ||
test.group('Typings', () => { | ||
test('status helpers methods', async ({ expectTypeOf }) => { | ||
function controllerMethod({ response }: HttpContext) { | ||
if (Math.random()) { | ||
return response.badRequest({ messageBadRequest: 'Invalid input' }) | ||
} else if (Math.random()) { | ||
return response.badGateway({ messageBadGateway: 'Cannot connect to the upstream server' }) | ||
} else if (Math.random()) { | ||
return { messageOkFirst: 'Hello world 2' as const } | ||
} else if (Math.random()) { | ||
return response.json({ messageOk: 'JSON' as const }) | ||
} | ||
|
||
return response.ok({ messageOk: 'Hello world' as const }) | ||
} | ||
|
||
const tuyau = createTuyau<{ | ||
auth: { | ||
login: { | ||
post: { | ||
request: { email: string; password: string } | ||
response: Simplify< | ||
Serialize< | ||
ConvertReturnTypeToRecordStatusResponse<ReturnType<typeof controllerMethod>> | ||
> | ||
> | ||
} | ||
} | ||
} | ||
}>('http://localhost:3333') | ||
|
||
nock('http://localhost:3333').post('/auth/login').reply(200, { token: '123' }) | ||
|
||
const res = await tuyau.auth.login.post({ email: '[email protected]', password: 'secret' }) | ||
|
||
if (res.data) { | ||
expectTypeOf(res.data).toEqualTypeOf< | ||
{ messageOk: 'Hello world' } | { messageOkFirst: 'Hello world 2' } | { messageOk: 'JSON' } | ||
>() | ||
|
||
if ('messageOk' in res.data) { | ||
expectTypeOf(res.data).toEqualTypeOf<{ messageOk: 'Hello world' } | { messageOk: 'JSON' }>() | ||
} | ||
|
||
if ('messageOkFirst' in res.data) { | ||
expectTypeOf(res.data).toEqualTypeOf<{ messageOkFirst: 'Hello world 2' }>() | ||
} | ||
} | ||
|
||
if (res.error) { | ||
expectTypeOf(res.error).toEqualTypeOf< | ||
| { status: 400; value: { messageBadRequest: string } } | ||
| { status: 502; value: { messageBadGateway: string } } | ||
>() | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.