0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/packages/create-astro/test/install-step.test.js
Ben Holmes b7cd695884
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"
2022-04-27 20:58:18 -04:00

66 lines
2.1 KiB
JavaScript

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(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);
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(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();
}
});
});
});
});