Skip to content

Commit fa72a7a

Browse files
committed
refactor: customize hello world test for each boilerplate
1 parent c3b6b17 commit fa72a7a

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

commands/Invoke.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export default class Configure extends BaseCommand {
2121
public static description = 'Configure one or more AdonisJS packages'
2222
public static aliases = ['invoke']
2323

24+
private appType = process.env['ADONIS_CREATE_APP_BOILERPLATE'] || 'web'
25+
2426
/**
2527
* Use yarn when building for production to install dependencies
2628
*/
@@ -110,7 +112,7 @@ export default class Configure extends BaseCommand {
110112
const helloWorldTestFile = new files.MustacheFile(
111113
this.application.appRoot,
112114
'tests/functional/hello_world.spec.ts',
113-
join(__dirname, '..', 'templates/tests/functional/hello_world.spec.txt')
115+
join(__dirname, '..', `templates/tests/functional/hello_world_${this.appType}.spec.txt`)
114116
)
115117
if (!helloWorldTestFile.exists()) {
116118
helloWorldTestFile.apply({}).commit()
@@ -147,6 +149,23 @@ export default class Configure extends BaseCommand {
147149
rcFile.commit()
148150
logger.action('update').succeeded('.adonisrc.json')
149151

152+
/**
153+
* Create ".env.test" file
154+
*/
155+
const testEnvFile = new files.NewLineFile(this.application.appRoot, '.env.test')
156+
if (!testEnvFile.exists()) {
157+
testEnvFile.add('NODE_ENV=test')
158+
159+
/**
160+
* Set additional .env variables for "web" boilerplate
161+
*/
162+
if (this.appType === 'web') {
163+
testEnvFile.add(['ASSETS_DRIVER=fake', 'SESSION_DRIVER=memory'])
164+
}
165+
166+
logger.action('create').succeeded('.env.test')
167+
}
168+
150169
/**
151170
* Install required dependencies
152171
*/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from '@japa/runner'
2+
3+
test('display welcome page', async ({ client }) => {
4+
const response = await client.get('/')
5+
6+
response.assertStatus(200)
7+
response.assertBodyContains({ hello: 'world' })
8+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from '@japa/runner'
2+
3+
test('display welcome page', async ({ client }) => {
4+
const response = await client.get('/')
5+
6+
response.assertStatus(200)
7+
response.assertTextIncludes('hello world')
8+
})
File renamed without changes.

0 commit comments

Comments
 (0)