diff options
author | 2022-04-27 20:58:18 -0400 | |
---|---|---|
committer | 2022-04-27 20:58:18 -0400 | |
commit | b7cd69588453cf874346bf2f14c41accd183129e (patch) | |
tree | 4d1feaf3bbc6f6eca552920415528a6a32117a21 /packages/create-astro/test/astro-add-step.test.js | |
parent | 79378523957462705ca4a32f69c14aacb1a8244b (diff) | |
download | astro-b7cd69588453cf874346bf2f14c41accd183129e.tar.gz astro-b7cd69588453cf874346bf2f14c41accd183129e.tar.zst astro-b7cd69588453cf874346bf2f14c41accd183129e.zip |
Feat: [create astro] replace component selector with "astro add" (#3223)
* feat: remove component framework selector
* feat: update templates to use "basics"
* feat: add "astro add" cli step
* tests: astro add step
* fix: reset env for pnpm tests
* fix: update install step test
* chore: remove "frameworks" step from tests
* deps: remove node-fetch from create-astro
* chore: changeset
* fix: use "preferLocal" for astro add command
* refactor: remove POSTPROCESS_FILES
* feat: add --yes flag to simplify astro add
* feat: bring back minimal option as "completely empty"
Diffstat (limited to 'packages/create-astro/test/astro-add-step.test.js')
-rw-r--r-- | packages/create-astro/test/astro-add-step.test.js | 66 |
1 files changed, 66 insertions, 0 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(); + } + }); + }); + }); +}); |