Skip to content

Commit

Permalink
Fix broken project CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Castro, Mario committed Dec 6, 2024
1 parent 123e787 commit 71fa4ed
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/services/project-initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function generateRootDirectory(config: ProjectInitializerConfig): P

export async function initializeGit(config: ProjectInitializerConfig): Promise<void> {
try {
await command('git init && git add -A && git commit -m "Initial commit"', { cwd: projectDir(config) })
await command('git init && git add -A && git commit -m "Initial commit"', { cwd: projectDir(config), shell: true })
} catch (e) {
throw wrapExecError(e, 'Could not initialize git repository')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
readFileContent,
removeFolders,
} from '../../helper/file-helper'
import { ChildProcess } from 'child_process'
import { overrideWithBoosterLocalDependencies } from '../../helper/deps-helper'
import { expect } from '../../helper/expect'
import { ChildProcess, exec as cpExec } from 'child_process'

// The Booster CLI version used should match the integration tests' version
const BOOSTER_VERSION = require('../../../package.json').version
Expand Down Expand Up @@ -95,8 +95,21 @@ describe('Project', () => {
})

cliProcess.stdout.on('end', () => {
cliProcess.stdin?.end()
resolve()
//
// if (cliProcess.stdin) {
// console.log('Attempting to end stdin')
// try {
// cliProcess.stdin.end()
// console.log('stdin ended')
// } catch (error) {
// console.error('Error ending stdin:', error)
// }
// } else {
// resolve()
// }
// cliProcess.stdin?.end()
// resolve()
})

cliProcess.stdout.on('error', () => {
Expand All @@ -114,17 +127,22 @@ describe('Project', () => {
flags: Array<string> = [],
promptAnswers?: PromptAnswers
): Promise<{ stdout: string; stderr: string }> => {
const cliProcess = command(`${cliPath} new:project ${projectName} ${flags.join(' ')}`, {
cwd: SANDBOX_INTEGRATION_DIR,
shell: true,
})

if (promptAnswers) {
await handlePrompt(cliProcess, promptAnswers)
}
return new Promise((resolve, reject) => {
const cliProcess = cpExec(
`${cliPath} new:project ${projectName} ${flags.join(' ')}`,
{
cwd: SANDBOX_INTEGRATION_DIR,
},
(error, stdout, stderr) => {
if (error) reject(error)
else resolve({ stdout, stderr })
}
)

const { stdout, stderr } = await cliProcess
return { stdout, stderr }
if (promptAnswers) {
handlePrompt(cliProcess, promptAnswers).catch(reject)
}
})
}

const packageJsonAssertions = (
Expand Down Expand Up @@ -243,13 +261,20 @@ describe('Project', () => {
it('should create a new project using short flags to configure it', async () => {
const projectName = 'cart-demo-short-flags'
const flags = [
`-a "${AUTHOR}"`,
`-d "${DESCRIPTION}"`,
`-H "${HOMEPAGE}"`,
`-l "${LICENSE}"`,
`-p "${PROVIDER}"`,
`-r "${REPO_URL}"`,
`-v "${VERSION}"`,
'-a',
`"${AUTHOR}"`,
'-d',
`"${DESCRIPTION}"`,
'-H',
`"${HOMEPAGE}"`,
'-l',
`"${LICENSE}"`,
'-p',
`"${PROVIDER}"`,
'-r',
`"${REPO_URL}"`,
'-v',
`"${VERSION}"`,
// We skip dependencies and git installation to make this test faster
'--skipInstall',
'--skipGit',
Expand All @@ -262,13 +287,20 @@ describe('Project', () => {
it('should create a new project using long flags to configure it', async () => {
const projectName = 'cart-demo-long-flags'
const flags = [
`--author "${AUTHOR}"`,
`--description "${DESCRIPTION}"`,
`--homepage "${HOMEPAGE}"`,
`--license "${LICENSE}"`,
`--providerPackageName "${PROVIDER}"`,
`--repository "${REPO_URL}"`,
`--version "${VERSION}"`,
'--author',
`"${AUTHOR}"`,
'--description',
`"${DESCRIPTION}"`,
'--homepage',
`"${HOMEPAGE}"`,
'--license',
`"${LICENSE}"`,
'--providerPackageName',
`"${PROVIDER}"`,
'--repository',
`"${REPO_URL}"`,
'--version',
`"${VERSION}"`,
// We skip dependencies and git installation to make this test faster
'--skipInstall',
'--skipGit',
Expand Down Expand Up @@ -375,8 +407,10 @@ describe('Project', () => {
license: LICENSE,
}
const flags = [
`--providerPackageName "${PROVIDER}"`,
`--repository "${REPO_URL}"`,
'--providerPackageName',
`"${PROVIDER}"`,
'--repository',
`"${REPO_URL}"`,
// We skip dependencies and git installation to make this test faster
'--skipInstall',
'--skipGit',
Expand Down Expand Up @@ -404,13 +438,20 @@ describe('Project', () => {
)

const flags = [
`--author "${AUTHOR}"`,
`--description "${DESCRIPTION}"`,
`--homepage "${HOMEPAGE}"`,
`--license "${LICENSE}"`,
'--providerPackageName "invalid-provider"',
`--repository "${REPO_URL}"`,
`--version "${VERSION}"`,
'--author',
`"${AUTHOR}"`,
'--description',
`"${DESCRIPTION}"`,
'--homepage',
`"${HOMEPAGE}"`,
'--license',
`"${LICENSE}"`,
'--providerPackageName',
'"invalid-provider"',
'--repository',
`"${REPO_URL}"`,
'--version',
`"${VERSION}"`,
// We skip dependencies and git installation to make this test faster
'--skipInstall',
'--skipGit',
Expand Down

0 comments on commit 71fa4ed

Please sign in to comment.