2022-04-26 10:24:24 -05:00
|
|
|
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;
|
2022-04-26 10:25:23 -05:00
|
|
|
});
|
2022-04-26 10:24:24 -05:00
|
|
|
this.afterAll(() => {
|
|
|
|
process.env.npm_config_user_agent = initialEnvValue;
|
2022-04-26 10:25:23 -05:00
|
|
|
});
|
2022-04-26 10:24:24 -05:00
|
|
|
|
2022-04-26 10:25:23 -05:00
|
|
|
it('should respect package manager in prompt', function () {
|
2022-04-29 10:45:43 -05:00
|
|
|
const { stdout, stdin } = setup([tempDir]);
|
2022-04-26 10:24:24 -05:00
|
|
|
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);
|
2022-04-29 10:45:43 -05:00
|
|
|
// respond with "enter key"
|
2022-04-26 10:24:24 -05:00
|
|
|
stdin.write('\x0D');
|
|
|
|
}
|
|
|
|
if (!seen.has(installPrompt) && chunk.includes(installPrompt)) {
|
|
|
|
seen.add(installPrompt);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-26 10:25:23 -05:00
|
|
|
it('should respect package manager in next steps', function () {
|
2022-04-29 10:45:43 -05:00
|
|
|
const { stdout, stdin } = setup([tempDir]);
|
2022-04-26 10:24:24 -05:00
|
|
|
return promiseWithTimeout((resolve) => {
|
|
|
|
const seen = new Set();
|
|
|
|
const installPrompt = PROMPT_MESSAGES.install(FAKE_PACKAGE_MANAGER);
|
2022-04-27 19:58:18 -05:00
|
|
|
const astroAddPrompt = PROMPT_MESSAGES.astroAdd();
|
2022-04-26 10:24:24 -05:00
|
|
|
stdout.on('data', (chunk) => {
|
|
|
|
if (!seen.has(PROMPT_MESSAGES.template) && chunk.includes(PROMPT_MESSAGES.template)) {
|
|
|
|
seen.add(PROMPT_MESSAGES.template);
|
2022-04-29 10:45:43 -05:00
|
|
|
// respond with "enter key"
|
2022-04-26 10:24:24 -05:00
|
|
|
stdin.write('\x0D');
|
|
|
|
}
|
|
|
|
if (!seen.has(installPrompt) && chunk.includes(installPrompt)) {
|
2022-04-26 10:25:23 -05:00
|
|
|
seen.add(installPrompt);
|
2022-04-29 10:45:43 -05:00
|
|
|
// respond with "no, then enter key"
|
2022-04-26 10:24:24 -05:00
|
|
|
stdin.write('n\x0D');
|
|
|
|
}
|
2022-04-27 19:58:18 -05:00
|
|
|
if (!seen.has(astroAddPrompt) && chunk.includes(astroAddPrompt)) {
|
|
|
|
seen.add(astroAddPrompt);
|
2022-04-29 10:45:43 -05:00
|
|
|
stdin.write('n\x0D');
|
|
|
|
}
|
|
|
|
if (!seen.has(PROMPT_MESSAGES.git) && chunk.includes(PROMPT_MESSAGES.git)) {
|
|
|
|
seen.add(PROMPT_MESSAGES.git);
|
2022-04-27 19:58:18 -05:00
|
|
|
stdin.write('\x0D');
|
|
|
|
}
|
2022-04-26 10:24:24 -05:00
|
|
|
if (chunk.includes('banana dev')) {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-04-26 10:25:23 -05:00
|
|
|
});
|