diff options
Diffstat (limited to 'packages/create-astro/test')
-rw-r--r-- | packages/create-astro/test/astro-add-step.test.js | 66 | ||||
-rw-r--r-- | packages/create-astro/test/install-step.test.js | 15 | ||||
-rw-r--r-- | packages/create-astro/test/utils.js | 3 |
3 files changed, 72 insertions, 12 deletions
diff --git a/packages/create-astro/test/astro-add-step.test.js b/packages/create-astro/test/astro-add-step.test.js new file mode 100644 index 000000000..b46d836cc --- /dev/null +++ b/packages/create-astro/test/astro-add-step.test.js @@ -0,0 +1,66 @@ +import { setup, promiseWithTimeout, timeout, PROMPT_MESSAGES } from './utils.js'; +import { sep } from 'path'; +import fs from 'fs'; +import os from 'os'; + +// reset package manager in process.env +// prevents test issues when running with pnpm +const FAKE_PACKAGE_MANAGER = 'npm'; +let initialEnvValue = null; + +describe('[create-astro] astro add', function () { + this.timeout(timeout); + let tempDir = ''; + beforeEach(async () => { + tempDir = await fs.promises.mkdtemp(`${os.tmpdir()}${sep}`); + }); + this.beforeAll(() => { + initialEnvValue = process.env.npm_config_user_agent; + process.env.npm_config_user_agent = FAKE_PACKAGE_MANAGER; + }); + this.afterAll(() => { + process.env.npm_config_user_agent = initialEnvValue; + }); + + it('should use "astro add" when user has installed dependencies', function () { + const { stdout, stdin } = setup([tempDir, '--dryrun']); + return promiseWithTimeout((resolve) => { + const seen = new Set(); + const installPrompt = PROMPT_MESSAGES.install('npm'); + stdout.on('data', (chunk) => { + if (!seen.has(PROMPT_MESSAGES.template) && chunk.includes(PROMPT_MESSAGES.template)) { + seen.add(PROMPT_MESSAGES.template); + stdin.write('\x0D'); + } + if (!seen.has(installPrompt) && chunk.includes(installPrompt)) { + seen.add(installPrompt); + stdin.write('\x0D'); + } + if (chunk.includes(PROMPT_MESSAGES.astroAdd('astro add --yes'))) { + resolve(); + } + }); + }); + }); + + it('should use "npx astro@latest add" when use has NOT installed dependencies', function () { + const { stdout, stdin } = setup([tempDir, '--dryrun']); + return promiseWithTimeout((resolve) => { + const seen = new Set(); + const installPrompt = PROMPT_MESSAGES.install('npm'); + stdout.on('data', (chunk) => { + if (!seen.has(PROMPT_MESSAGES.template) && chunk.includes(PROMPT_MESSAGES.template)) { + seen.add(PROMPT_MESSAGES.template); + stdin.write('\x0D'); + } + if (!seen.has(installPrompt) && chunk.includes(installPrompt)) { + seen.add(installPrompt); + stdin.write('n\x0D'); + } + if (chunk.includes(PROMPT_MESSAGES.astroAdd('npx astro@latest add --yes'))) { + resolve(); + } + }); + }); + }); +}); diff --git a/packages/create-astro/test/install-step.test.js b/packages/create-astro/test/install-step.test.js index 10f27a1a8..fbd7f2249 100644 --- a/packages/create-astro/test/install-step.test.js +++ b/packages/create-astro/test/install-step.test.js @@ -30,11 +30,6 @@ describe('[create-astro] install', function () { seen.add(PROMPT_MESSAGES.template); stdin.write('\x0D'); } - if (!seen.has(PROMPT_MESSAGES.frameworks) && chunk.includes(PROMPT_MESSAGES.frameworks)) { - seen.add(PROMPT_MESSAGES.frameworks); - stdin.write('\x0D'); - } - if (!seen.has(installPrompt) && chunk.includes(installPrompt)) { seen.add(installPrompt); resolve(); @@ -48,20 +43,20 @@ describe('[create-astro] install', function () { return promiseWithTimeout((resolve) => { const seen = new Set(); const installPrompt = PROMPT_MESSAGES.install(FAKE_PACKAGE_MANAGER); + const astroAddPrompt = PROMPT_MESSAGES.astroAdd(); stdout.on('data', (chunk) => { if (!seen.has(PROMPT_MESSAGES.template) && chunk.includes(PROMPT_MESSAGES.template)) { seen.add(PROMPT_MESSAGES.template); stdin.write('\x0D'); } - if (!seen.has(PROMPT_MESSAGES.frameworks) && chunk.includes(PROMPT_MESSAGES.frameworks)) { - seen.add(PROMPT_MESSAGES.frameworks); - stdin.write('\x0D'); - } - if (!seen.has(installPrompt) && chunk.includes(installPrompt)) { seen.add(installPrompt); stdin.write('n\x0D'); } + if (!seen.has(astroAddPrompt) && chunk.includes(astroAddPrompt)) { + seen.add(astroAddPrompt); + stdin.write('\x0D'); + } if (chunk.includes('banana dev')) { resolve(); } diff --git a/packages/create-astro/test/utils.js b/packages/create-astro/test/utils.js index 4e0e2d5fc..8d7cf67c1 100644 --- a/packages/create-astro/test/utils.js +++ b/packages/create-astro/test/utils.js @@ -26,9 +26,8 @@ export function promiseWithTimeout(testFn) { export const PROMPT_MESSAGES = { directory: 'Where would you like to create your app?', template: 'Which app template would you like to use?', - // TODO: remove when framework selector is removed - frameworks: 'Which frameworks would you like to use?', install: (pkgManager) => `Would you like us to run "${pkgManager} install?"`, + astroAdd: (astroAddCommand = 'npx astro@latest add --yes') => `Run "${astroAddCommand}?" This lets you optionally add component frameworks (ex. React), CSS frameworks (ex. Tailwind), and more.`, }; export function setup(args = []) { |