Skip to content

Commit

Permalink
fix: set default installation directory to cwd (#5)
Browse files Browse the repository at this point in the history
* fix: set default installation directory to cwd

* refactor: remove cwd import

* fix: make destination argument optional

* test: install in current directory by default
  • Loading branch information
mensah-j committed Apr 29, 2024
1 parent 15d5599 commit 49d0cd3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/install_japa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import { Edge } from 'edge.js'
import { cwd } from 'node:process'
import { existsSync } from 'node:fs'
import gradient from 'gradient-string'
import { fileURLToPath } from 'node:url'
Expand Down Expand Up @@ -45,7 +44,7 @@ export class InstallJapa extends BaseCommand {
/**
* Destination directory
*/
@args.string({ description: 'Destination', default: 'process.cwd()' })
@args.string({ description: 'Destination', required: false })
declare destination: string

/**
Expand Down Expand Up @@ -335,7 +334,7 @@ export class InstallJapa extends BaseCommand {
this.packageManager = detectPackageManager()?.name || 'npm'
}
if (!this.destination) {
this.destination = cwd()
this.destination = process.cwd()
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/install.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { test } from '@japa/runner'
import { kernel } from '../index.js'
import { InstallJapa } from '../src/install_japa.js'
import { existsSync, mkdirSync } from 'node:fs'

function trapPrompts(command: InstallJapa) {
command.prompt.trap('Select the assertion library').replyWith('@japa/assert')
Expand All @@ -20,9 +21,11 @@ function trapPrompts(command: InstallJapa) {

test.group('install', (group) => {
group.each.setup(() => {
const projectRoot = process.cwd()
kernel.ui.switchMode('raw')
InstallJapa.fakePackageInstall()
return () => {
process.chdir(projectRoot)
kernel.ui.switchMode('normal')
InstallJapa.restorePackageInstall()
}
Expand Down Expand Up @@ -127,6 +130,22 @@ test.group('install', (group) => {
await assert.fileExists('bin/test.js')
})

test('configure inside current directory if destination is not set', async ({ assert, fs }) => {
mkdirSync(fs.basePath, { recursive: true })
process.chdir(fs.basePath)

const command = await kernel.create(InstallJapa, [])

command.prompt.trap('Select the assertion library').replyWith('@japa/assert')
command.prompt.trap('Select additional plugins').replyWith([])
command.prompt.trap('Select the project type').replyWith('javascript')
command.prompt.trap('Want us to create a sample test?').replyWith(false)

await command.exec()

assert.isTrue(existsSync('bin/test.js'))
})

test('add default files config', async ({ assert, fs }) => {
const command = await kernel.create(InstallJapa, [fs.basePath])

Expand Down

0 comments on commit 49d0cd3

Please sign in to comment.