0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/create-astro/test/utils.js
Ben Holmes 38e5e9e982
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
2022-04-26 11:24:24 -04:00

40 lines
1.1 KiB
JavaScript

import { execa } from 'execa'
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?',
// TODO: remove when framework selector is removed
frameworks: 'Which frameworks would you like to use?',
install: (pkgManager) => `Would you like us to run "${pkgManager} install?"`,
};
export function setup(args = []) {
const { stdout, stdin } = execa('../create-astro.mjs', args, { cwd: testDir });
return {
stdin,
stdout,
};
}