diff options
Diffstat (limited to 'packages/create-astro/test/utils.js')
-rw-r--r-- | packages/create-astro/test/utils.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/create-astro/test/utils.js b/packages/create-astro/test/utils.js new file mode 100644 index 000000000..c5519c7bf --- /dev/null +++ b/packages/create-astro/test/utils.js @@ -0,0 +1,40 @@ +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, + }; +} |