Running Japa tests on subdomain (tenant) #3712
-
Hi everyone, I have a route group that I want to run Japa tests towards. The issue I have is that all of my routes are behind a domain configuration, such as When I run $ node ace test
[ info ] running tests...
{ ... "msg":"started server on 0.0.0.0:62054"} When my HTTP tests are being executed using The test requests will return I tried to configure
...
import { domain } from 'Config/...' // domain is set to 'localhost'
const testUrl = `http://test.${domain}`
export const plugins: Config['plugins'] = [assert(), runFailedTests(), apiClient(testUrl)] If i then run $ node ace test
[ info ] running tests...
{ ... "msg":"started server on 0.0.0.0:62792"}
...
connect ECONNREFUSED 127.0.0.1:80
at TCPConnectWrap.afterConnect [as oncomplete] net.js:1159 I guess this makes sense, because the test server is running on a random port, while the tests are pointing towards my But before I venture into that rabbit hole I wanted to ask here -- Am I going down the correct path? 😅 Thanks! See project code snippets below:
import Route from '@ioc:Adonis/Core/Route'
import Config from '@ioc:Adonis/Core/Config'
// this is just a config variable that allows me to set a dynamic domain, such as "mycompany.com"
const domain = Config.get('els.domain')
Route.group(() => {
Route.post(':projectId', 'StorageController.store')
})
// example: tenant.mycompany.com
.domain(`:tenant.${domain}`)
.prefix('storage')
import { test } from '@japa/runner'
test.group('Storage', () => {
test('Store payload', async ({ client }) => {
const response = await client
.post('storage/test-project')
.json({
metadata: {
message: 'hi mom'
}
})
response.dump()
})
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Ok, I got it working by adding the port to my
...
const port = Env.get('PORT')
const testUrl = `http://test.${domain}:${port}`
export const plugins: Config['plugins'] = [assert(), runFailedTests(), apiClient(testUrl)]
... I hope this is useful for someone else too. Let me know if there's a better way. Thanks! |
Beta Was this translation helpful? Give feedback.
Ok, I got it working by adding the port to my
apiClient
configuration:tests/bootstrap.ts
I hope this is useful for someone else too. Let me know if there's a better way. Thanks!