mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
0408376281
* feat(create-astro): add houston, improve prompts * refactor(create-astro): move to giget * chore: add changeset * chore: update lockfile * test(create-astro): update tests to match new output * chore: prefer named functions * fix: update template prompt * fix: update typescript message * chore: add explicit --skip-houston flag * test(create-astro): skip flaky typescript test Co-authored-by: Nate Moore <nate@astro.build>
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import { execa } from 'execa';
|
|
import { dirname } from 'path';
|
|
import stripAnsi from 'strip-ansi';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
export const testDir = dirname(__filename);
|
|
export const timeout = 5000;
|
|
|
|
const timeoutError = function (details) {
|
|
let errorMsg = 'Timed out waiting for create-astro to respond with expected output.';
|
|
if (details) {
|
|
errorMsg += '\nLast output: "' + details + '"';
|
|
}
|
|
return new Error(errorMsg);
|
|
};
|
|
|
|
export function promiseWithTimeout(testFn) {
|
|
return new Promise((resolve, reject) => {
|
|
let lastStdout;
|
|
function onStdout(chunk) {
|
|
lastStdout = stripAnsi(chunk.toString()).trim() || lastStdout;
|
|
}
|
|
|
|
const timeoutEvent = setTimeout(() => {
|
|
reject(timeoutError(lastStdout));
|
|
}, timeout);
|
|
function resolver() {
|
|
clearTimeout(timeoutEvent);
|
|
resolve();
|
|
}
|
|
|
|
testFn(resolver, onStdout);
|
|
});
|
|
}
|
|
|
|
export const PROMPT_MESSAGES = {
|
|
directory: 'Where would you like to create your new project?',
|
|
template: 'How would you like to setup your new project?',
|
|
typescript: 'How would you like to setup TypeScript?',
|
|
typescriptSucceed: 'next',
|
|
};
|
|
|
|
export function setup(args = []) {
|
|
const { stdout, stdin } = execa('../create-astro.mjs', [...args, '--skip-houston', '--dryrun'], { cwd: testDir });
|
|
return {
|
|
stdin,
|
|
stdout,
|
|
};
|
|
}
|