|
| 1 | +#!/usr/bin/env node |
| 2 | +/* eslint-env node */ |
| 3 | + |
| 4 | +import { cd, fs, $ } from 'zx' |
| 5 | + |
| 6 | +const projectPath = await fs.realpath(process.env.PROJECT_PATH) |
| 7 | + |
| 8 | +cd(projectPath) |
| 9 | + |
| 10 | +describe('crwa', () => { |
| 11 | + test('--help', async () => { |
| 12 | + const p = await $`yarn create-redwood-app --help` |
| 13 | + |
| 14 | + expect(p.exitCode).toEqual(0) |
| 15 | + expect(p.stdout).toMatchInlineSnapshot(` |
| 16 | + "------------------------------------------------------------------ |
| 17 | + 🌲⚡️ Welcome to RedwoodJS! ⚡️🌲 |
| 18 | + ------------------------------------------------------------------ |
| 19 | + Usage: create-redwood-app <project directory> [option] |
| 20 | +
|
| 21 | + Options: |
| 22 | + --help Show help [boolean] |
| 23 | + --typescript, --ts Generate a TypeScript project. |
| 24 | + [boolean] [default: null] |
| 25 | + --overwrite Create even if target directory isn't empty |
| 26 | + [boolean] [default: false] |
| 27 | + --telemetry Enables sending telemetry events for this create |
| 28 | + command and all Redwood CLI commands |
| 29 | + https://telemetry.redwoodjs.com |
| 30 | + [boolean] [default: true] |
| 31 | + --git-init, --git Initialize a git repository. [boolean] [default: null] |
| 32 | + -m, --commit-message Commit message for the initial commit. |
| 33 | + [string] [default: null] |
| 34 | + -y, --yes Skip prompts and use defaults. |
| 35 | + [boolean] [default: null] |
| 36 | + --version Show version number [boolean] |
| 37 | +
|
| 38 | + Examples: |
| 39 | + create-redwood-app newapp |
| 40 | + [?25l[?25h" |
| 41 | + `) |
| 42 | + expect(p.stderr).toMatchInlineSnapshot(`"[?25l[?25h"`) |
| 43 | + }) |
| 44 | + |
| 45 | + test('--version', async () => { |
| 46 | + const p = await $`yarn create-redwood-app --version` |
| 47 | + |
| 48 | + expect(p.exitCode).toEqual(0) |
| 49 | + expect(p.stdout).toMatchInlineSnapshot(` |
| 50 | + "------------------------------------------------------------------ |
| 51 | + 🌲⚡️ Welcome to RedwoodJS! ⚡️🌲 |
| 52 | + ------------------------------------------------------------------ |
| 53 | + 6.0.7 |
| 54 | + [?25l[?25h" |
| 55 | + `) |
| 56 | + expect(p.stderr).toMatchInlineSnapshot(`"[?25l[?25h"`) |
| 57 | + }) |
| 58 | + |
| 59 | + test('--yes, -y', async () => { |
| 60 | + const p = await $`yarn create-redwood-app ./redwood-app --yes` |
| 61 | + |
| 62 | + // await $`yarn create-redwood-app redwood-app -y` |
| 63 | + // # `yarn pack` seems to ignore `.yarnrc.yml` |
| 64 | + // # cp "$SCRIPT_DIR/templates/ts/.yarnrc.yml" "$CRWA_ESM_TESTING_DIR" |
| 65 | + |
| 66 | + expect(p.exitCode).toEqual(0) |
| 67 | + expect(p.stdout).toMatchInlineSnapshot(` |
| 68 | + "------------------------------------------------------------------ |
| 69 | + 🌲⚡️ Welcome to RedwoodJS! ⚡️🌲 |
| 70 | + ------------------------------------------------------------------ |
| 71 | + [?25l⠋ Checking node and yarn compatibility |
| 72 | + [?25h[?25l✔ Compatibility checks passed |
| 73 | + [?25h✔ Creating your Redwood app in ./redwood-app based on command line argument |
| 74 | + ✔ Using TypeScript based on command line flag |
| 75 | + ✔ Will initialize a git repo based on command line flag |
| 76 | + [?25l⠋ Creating project files |
| 77 | + [?25h[?25l✔ Project files created |
| 78 | + [?25h[?25l⠋ Initializing a git repo |
| 79 | + [?25h[?25l✔ Initialized a git repo with commit message "Initial commit" |
| 80 | + [?25h |
| 81 | + Thanks for trying out Redwood! |
| 82 | +
|
| 83 | + ⚡️ Get up and running fast with this Quick Start guide: https://redwoodjs.com/quick-start |
| 84 | +
|
| 85 | + Fire it up! 🚀 |
| 86 | +
|
| 87 | + > cd redwood-app |
| 88 | + > yarn install |
| 89 | + > yarn rw dev |
| 90 | +
|
| 91 | + [?25l✔ Initialized a git repo with commit message "Initial commit" |
| 92 | + [?25h" |
| 93 | + `) |
| 94 | + expect(p.stderr).toMatchInlineSnapshot(`"[?25l[?25h[?25l[?25h[?25l[?25h[?25l[?25h[?25l[?25h[?25l[?25h[?25l[?25h"`) |
| 95 | + |
| 96 | + await fs.rm('./redwood-app', { recursive: true, force: true }) |
| 97 | + }) |
| 98 | + |
| 99 | + test.failing('fails on unknown options', async () => { |
| 100 | + try { |
| 101 | + await $`yarn create-redwood-app --unknown-options`.timeout(2500) |
| 102 | + // Fail the test if the function didn't throw. |
| 103 | + expect(true).toEqual(false) |
| 104 | + } catch (p) { |
| 105 | + expect(p.exitCode).toEqual(1) |
| 106 | + } |
| 107 | + }) |
| 108 | +}) |
0 commit comments