2022-04-26 15:25:23 +00:00
|
|
|
import { execa } from 'execa';
|
2022-04-26 15:24:24 +00:00
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
import { dirname } from 'path';
|
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
export const testDir = dirname(__filename);
|
|
|
|
export const timeout = 5000;
|
|
|
|
|
|
|
|
const createAstroError = new Error(
|
|
|
|
'Timed out waiting for create-astro to respond with expected output.'
|
|
|
|
);
|
|
|
|
|
|
|
|
export function promiseWithTimeout(testFn) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const timeoutEvent = setTimeout(() => {
|
|
|
|
reject(createAstroError);
|
|
|
|
}, timeout);
|
|
|
|
function resolver() {
|
|
|
|
clearTimeout(timeoutEvent);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
testFn(resolver);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export const PROMPT_MESSAGES = {
|
|
|
|
directory: 'Where would you like to create your app?',
|
|
|
|
template: 'Which app template would you like to use?',
|
|
|
|
install: (pkgManager) => `Would you like us to run "${pkgManager} install?"`,
|
2022-04-28 00:59:36 +00:00
|
|
|
astroAdd: (astroAddCommand = 'npx astro@latest add --yes') =>
|
|
|
|
`Run "${astroAddCommand}?" This lets you optionally add component frameworks (ex. React), CSS frameworks (ex. Tailwind), and more.`,
|
2022-04-29 15:45:43 +00:00
|
|
|
git: 'Initialize a git repository?',
|
2022-04-26 15:24:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function setup(args = []) {
|
2022-04-29 15:45:43 +00:00
|
|
|
const { stdout, stdin } = execa('../create-astro.mjs', [...args, '--dryrun'], { cwd: testDir });
|
2022-04-26 15:24:24 +00:00
|
|
|
return {
|
|
|
|
stdin,
|
|
|
|
stdout,
|
|
|
|
};
|
|
|
|
}
|