summaryrefslogtreecommitdiff
path: root/packages/create-astro/test/install-step.test.js
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2022-04-26 11:24:24 -0400
committerGravatar GitHub <noreply@github.com> 2022-04-26 11:24:24 -0400
commit38e5e9e9825876cd0ae14a648b51bdf397e81169 (patch)
tree7e3432d7caa97984054cd634bbcf095eee0477b3 /packages/create-astro/test/install-step.test.js
parent8dd16e38c1cd0c953c84d00130df8c902e778886 (diff)
downloadastro-38e5e9e9825876cd0ae14a648b51bdf397e81169.tar.gz
astro-38e5e9e9825876cd0ae14a648b51bdf397e81169.tar.zst
astro-38e5e9e9825876cd0ae14a648b51bdf397e81169.zip
Feat: `create astro` add install step (#3190)
* feat: add instlal step with pkg manager detection * feat: add package emoji for style points * feat: update next steps to match pkg manager * refactor: extract some create-astro test utils * refactor: extract promp msgs to utils * chore: add install step tests * chore: changeset * fix: remove directory test skip * fix: unset env variables after install step test * deps: add execa to create-astro * refactor: use execa for install step * chore: remove old comment * fix: rework install step test for node 14? * chore: remove "politely stolen" footnote * temp: show stdout dialog * feat: remove debugging logs, add dryrun flag for testing * chore: more stray logs * fix: remove rmdir
Diffstat (limited to 'packages/create-astro/test/install-step.test.js')
-rw-r--r--packages/create-astro/test/install-step.test.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/packages/create-astro/test/install-step.test.js b/packages/create-astro/test/install-step.test.js
new file mode 100644
index 000000000..91e3bc66c
--- /dev/null
+++ b/packages/create-astro/test/install-step.test.js
@@ -0,0 +1,71 @@
+import { setup, promiseWithTimeout, timeout, PROMPT_MESSAGES } from './utils.js';
+import { sep } from 'path';
+import fs from 'fs';
+import os from 'os';
+
+const FAKE_PACKAGE_MANAGER = 'banana';
+let initialEnvValue = null;
+
+describe('[create-astro] install', 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 respect package manager in prompt', function() {
+ const { stdout, stdin } = setup([tempDir, '--dryrun']);
+ return promiseWithTimeout((resolve) => {
+ const seen = new Set();
+ const installPrompt = PROMPT_MESSAGES.install(FAKE_PACKAGE_MANAGER);
+ 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);
+ resolve();
+ }
+ });
+ });
+ });
+
+ it('should respect package manager in next steps', function() {
+ const { stdout, stdin } = setup([tempDir, '--dryrun']);
+ return promiseWithTimeout((resolve) => {
+ const seen = new Set();
+ const installPrompt = PROMPT_MESSAGES.install(FAKE_PACKAGE_MANAGER);
+ 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 (chunk.includes('banana dev')) {
+ resolve();
+ }
+ });
+ });
+ });
+})