From 915e84224e77e70643225c7a0e862bcec514722d Mon Sep 17 00:00:00 2001 From: David S Price Date: Tue, 6 Apr 2021 15:54:08 -0700 Subject: [PATCH 1/8] remove runners for testing --- .github/workflows/e2e.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 2c1b195d1a8d..1ac0f79f0ae3 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -11,7 +11,7 @@ jobs: if: github.repository == 'redwoodjs/redwood' strategy: matrix: - os: ['ubuntu-latest'] + os: ['windows-latest'] node-version: ['14'] fail-fast: true runs-on: ${{ matrix.os }} From c2c6ba704017a3733cbabdc57b37d4ec9e539a0c Mon Sep 17 00:00:00 2001 From: David S Price Date: Tue, 6 Apr 2021 15:54:16 -0700 Subject: [PATCH 2/8] remove runners for testing --- .github/dependabot.yml | 9 -- .github/workflows/build-eslint-jest.yaml | 47 ------- .github/workflows/codeql-analysis.yml | 67 ---------- .github/workflows/create_pr_artifact.yaml | 47 ------- .github/workflows/netlify-build.yaml | 21 ---- .github/workflows/publish-npm-canary.yaml | 47 ------- .github/workflows/publish_pr_packages.yaml | 82 ------------ .../integration/01-tutorial/tutorial.spec.js | 119 ------------------ .../02-cli/02-cli-commands.spec.js | 61 --------- 9 files changed, 500 deletions(-) delete mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/build-eslint-jest.yaml delete mode 100644 .github/workflows/codeql-analysis.yml delete mode 100644 .github/workflows/create_pr_artifact.yaml delete mode 100644 .github/workflows/netlify-build.yaml delete mode 100644 .github/workflows/publish-npm-canary.yaml delete mode 100644 .github/workflows/publish_pr_packages.yaml delete mode 100644 tasks/e2e/cypress/integration/02-cli/02-cli-commands.spec.js diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index f035a9970814..000000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,9 +0,0 @@ -version: 2 -updates: - - package-ecosystem: npm - versioning-strategy: "increase" - directory: "/" - schedule: - interval: "weekly" - day: "friday" - open-pull-requests-limit: 20 diff --git a/.github/workflows/build-eslint-jest.yaml b/.github/workflows/build-eslint-jest.yaml deleted file mode 100644 index abca6c6b0b55..000000000000 --- a/.github/workflows/build-eslint-jest.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: Lint, build and run tests - -on: - push: - branches: [main] - pull_request: - types: [opened, synchronize, reopened] - -jobs: - all: - strategy: - matrix: - os: ['ubuntu-latest', 'windows-latest'] - node-version: ['14'] - fail-fast: true - runs-on: ${{ matrix.os }} - name: ${{ matrix.os }} | Node ${{ matrix.node-version }} latest - steps: - - uses: actions/checkout@v2 - - - name: Setup node - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - - name: Cache "node_modules" - uses: actions/cache@v2 - if: matrix.os == 'ubuntu-latest' - with: - path: '**/node_modules' - key: node_modules_${{ runner.os }}_${{ hashFiles('**/yarn.lock') }} - - - name: Install dependencies - run: yarn install --frozen-lockfile - - - name: Build - run: yarn build - - - name: Run ESLint - run: yarn lint - env: - CI: true - - - name: Run tests - run: yarn test - env: - CI: true diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 6bfccfb61b1f..000000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ main ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ main ] - schedule: - - cron: '42 5 * * 3' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'javascript' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/create_pr_artifact.yaml b/.github/workflows/create_pr_artifact.yaml deleted file mode 100644 index b5eaf39070bc..000000000000 --- a/.github/workflows/create_pr_artifact.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: Create PR Artifact - -on: pull_request - -jobs: - create_pr_artifact: - name: Create PR Artifact - if: github.repository == 'redwoodjs/redwood' - runs-on: ubuntu-latest - defaults: - run: - shell: bash - - steps: - - name: Checkout PR - uses: actions/checkout@v2 - - - name: Setup node - uses: actions/setup-node@v2 - with: - node-version: 14 - - - name: Install dependencies - run: yarn install --frozen-lockfile - - - name: Build - run: yarn build - - - name: Create packages - run: | - dirName="bin/${{ github.event.number }}" - mkdir -p $dirName - for d in packages/*/ ; do - (cd "$d" && tgz=$(npm pack) && cp $tgz "../../$dirName/") - done - cd $dirName - sha="${{ github.event.pull_request.head.sha }}" - for f in * ; do - mv -- "$f" "${f%.tgz}-${sha:0:7}.tgz" - done - - - name: Upload artifact - uses: actions/upload-artifact@v2 - with: - name: pr-packages - path: bin/ - retention-days: 1 diff --git a/.github/workflows/netlify-build.yaml b/.github/workflows/netlify-build.yaml deleted file mode 100644 index b58463fb5e95..000000000000 --- a/.github/workflows/netlify-build.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Netlify deploy hook to add new docs on Redwoodjs.com - -on: - push: - branches: - - main - paths: - - '**.md' - release: - types: - - published - -jobs: - deploy_hook: - name: Starting Netlify Deploy - runs-on: ubuntu-latest - steps: - - name: POST build hook - run: | - set -e - curl -X POST https://api.netlify.com/build_hooks/5e72a1a0d832c03eb1f56934 diff --git a/.github/workflows/publish-npm-canary.yaml b/.github/workflows/publish-npm-canary.yaml deleted file mode 100644 index 2bb97eb984f1..000000000000 --- a/.github/workflows/publish-npm-canary.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: Publish canaray packages to npm - -on: - push: - branches: [main] - tags-ignore: - - v** - -jobs: - build: - if: github.repository == 'redwoodjs/redwood' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Required because lerna uses tags to determine the version. - - name: Setup node - uses: actions/setup-node@v2 - with: - node-version: '14' - - name: Print node and yarn versions - run: | - node --version - yarn --version - - name: Install dependencies - run: yarn install --frozen-lockfile --check-files - - - name: Build - run: yarn build - - - name: Run ESLint - run: yarn lint - env: - CI: true - - - name: Run tests - run: yarn test - env: - CI: true - - - name: Publish to npm - run: | - git fetch --depth=1 origin +refs/tags/*:refs/tags/* - echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc - ./tasks/publish-canary - env: - NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} diff --git a/.github/workflows/publish_pr_packages.yaml b/.github/workflows/publish_pr_packages.yaml deleted file mode 100644 index 9e13c933bd31..000000000000 --- a/.github/workflows/publish_pr_packages.yaml +++ /dev/null @@ -1,82 +0,0 @@ -name: Publish PR packages - -on: - workflow_run: - workflows: ["Create PR Artifact"] - types: - - completed - -jobs: - publish_pr_packages: - name: Publish PR packages - if: github.repository == 'redwoodjs/redwood' - runs-on: ubuntu-latest - defaults: - run: - shell: bash - - steps: - - name: Download artifact - uses: dawidd6/action-download-artifact@v2 - with: - workflow: ${{ github.event.workflow_run.workflow_id }} - workflow_conclusion: success - - - name: Get PR number - id: pr_number - run: | - ls -R - pr_number=$(ls pr-packages) - echo $pr_number - echo "::set-output name=pr_number::$pr_number" - - - name: copy files to s3 - env: - aws_key_id: ${{ secrets.AWS_KEY_ID }} - aws_secret_access_key: ${{ secrets.AWS_SECRET }} - run: | - sudo apt-get update && sudo apt-get -y install awscli - aws configure set aws_access_key_id $aws_key_id - aws configure set aws_secret_access_key $aws_secret_access_key - aws configure set default.region us-east-1 - aws s3 cp --recursive ./pr-packages/ s3://rw-pr-redwoodjs-com/ - - - name: Create comment msg - id: comment_msg - run: | - pr_number=${{ steps.pr_number.outputs.pr_number }} - cd pr-packages/$pr_number - v_sha=$(ls | grep "\.tgz$" | sed 's/\.tgz$//' | head -n1 | awk -F"-" '{ print $(NF-1)"-"$NF }') - msg="### đŸ“Ļ PR Packages%0A" - msg+="%0A" - msg+="
Click to Show Package Download Links%0A" - msg+="%0A" - for p in *; do - msg+="https://rw-pr-redwoodjs-com.s3.amazonaws.com/$pr_number/$p%0A" - done - msg+="
%0A" - msg+="%0A" - msg+="Install this PR by running \`yarn rw upgrade --pr $pr_number:$v_sha\`" - echo "::set-output name=msg::$msg" - - - name: Find Comment - uses: peter-evans/find-comment@v1 - id: fc - with: - issue-number: ${{ steps.pr_number.outputs.pr_number }} - comment-author: 'github-actions[bot]' - - - name: Create comment - if: ${{ steps.fc.outputs.comment-id == 0 }} - uses: peter-evans/create-or-update-comment@v1 - with: - issue-number: ${{ steps.pr_number.outputs.pr_number }} - body: ${{ steps.comment_msg.outputs.msg }} - - - name: Update comment - if: ${{ steps.fc.outputs.comment-id != 0 }} - uses: peter-evans/create-or-update-comment@v1 - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - body: ${{ steps.comment_msg.outputs.msg }} - edit-mode: replace diff --git a/tasks/e2e/cypress/integration/01-tutorial/tutorial.spec.js b/tasks/e2e/cypress/integration/01-tutorial/tutorial.spec.js index 184ba31250cc..8dd08ef02574 100644 --- a/tasks/e2e/cypress/integration/01-tutorial/tutorial.spec.js +++ b/tasks/e2e/cypress/integration/01-tutorial/tutorial.spec.js @@ -150,126 +150,7 @@ describe('The Redwood Tutorial - Golden path edition', () => { cy.get('input#title').type('Second post') cy.get('input#body').type('Hello world!') cy.get('button').contains('Save').click() - }) - - it('5. Cells', () => { - // https://redwoodjs.com/tutorial/cells - cy.visit('http://localhost:8910/') - - cy.exec(`cd ${BASE_DIR}; yarn rw g cell BlogPosts --force`) - cy.writeFile( - path.join(BASE_DIR, 'web/src/components/BlogPostsCell/BlogPostsCell.js'), - Step5_1_ComponentsCellBlogPost - ) - cy.writeFile( - path.join( - BASE_DIR, - 'web/src/components/BlogPostsCell/BlogPostsCell.test.js' - ), - Step5_2_ComponentsCellBlogPostTest - ) - cy.writeFile( - path.join(BASE_DIR, 'web/src/pages/HomePage/HomePage.js'), - Step5_3_PagesHome - ) - cy.get('main').should( - 'contain', - // [{"title":"Second post","body":"Hello world!","__typename":"Post"}] - '"body":"Hello world!"' - ) - }) - - it('6. Routing Params', () => { - // https://redwoodjs.com/tutorial/routing-params - cy.exec(`cd ${BASE_DIR}; yarn rw g page BlogPost --force`) - cy.exec(`cd ${BASE_DIR}; yarn rw g cell BlogPost --force`) - cy.exec(`cd ${BASE_DIR}; yarn rw g component BlogPost --force`) - - cy.writeFile(path.join(BASE_DIR, 'web/src/Routes.js'), Step6_1_Routes) - cy.writeFile( - path.join(BASE_DIR, 'web/src/pages/BlogPostPage/BlogPostPage.js'), - Step6_2_BlogPostPage - ) - cy.writeFile( - path.join(BASE_DIR, 'web/src/components/BlogPostCell/BlogPostCell.js'), - Step6_3_BlogPostCell - ) - cy.writeFile( - path.join( - BASE_DIR, - 'web/src/components/BlogPostCell/BlogPostCell.test.js' - ), - Step6_3_BlogPostCellTest - ) - cy.writeFile( - path.join(BASE_DIR, 'web/src/components/BlogPost/BlogPost.js'), - Step6_4_BlogPost - ) - cy.writeFile( - path.join(BASE_DIR, 'web/src/components/BlogPost/BlogPost.test.js'), - Step6_4_BlogPostTest - ) - cy.writeFile( - path.join(BASE_DIR, 'web/src/components/BlogPostsCell/BlogPostsCell.js'), - Step6_5_BlogPostsCell - ) - cy.writeFile( - path.join( - BASE_DIR, - 'web/src/components/BlogPostsCell/BlogPostsCell.mock.js' - ), - Step6_5_BlogPostsCellMock - ) - - // New entry - cy.visit('http://localhost:8910/posts') - cy.contains(' New Post').click() - cy.get('input#title').type('Third post') - cy.get('input#body').type('foo bar') - cy.get('button').contains('Save').click() - - cy.visit('http://localhost:8910/') - - // Detail Page - cy.contains('Second post').click() - cy.get('main').should('contain', 'Hello world!') - - cy.visit('http://localhost:8910/') - - cy.contains('Third post').click() - cy.get('main').should('contain', 'foo bar') - }) - - it("7. Everyone's Favorite Thing to Build: Forms", () => { - // https://redwoodjs.com/tutorial/everyone-s-favorite-thing-to-build-forms - cy.exec(`cd ${BASE_DIR}; yarn rw g page contact --force`) - cy.writeFile( - path.join(BASE_DIR, 'web/src/layouts/BlogLayout/BlogLayout.js'), - Step7_1_BlogLayout - ) - cy.writeFile( - path.join(BASE_DIR, 'web/src/pages/ContactPage/ContactPage.js'), - Step7_2_ContactPage - ) - cy.writeFile(path.join(BASE_DIR, 'web/src/index.css'), Step7_3_Css) - cy.writeFile(path.join(BASE_DIR, 'web/src/Routes.js'), Step7_4_Routes) - - cy.contains('Contact').click() - cy.contains('Save').click() - cy.get('main').should('contain', 'name is required') - cy.get('main').should('contain', 'email is required') - cy.get('main').should('contain', 'message is required') - - cy.get('input#email').type('foo bar') - cy.contains('Save').click() - cy.get('main').should('contain', 'Please enter a valid email address') - cy.get('input#name').type('test name') - cy.get('input#email').type('foo@bar.com') - cy.get('textarea#message').type('test message') - cy.contains('Save').click() - // console - // {name: "test name", email: "foo@bar.com", message: "test message"} cy.visit('http://localhost:8910/') }) }) diff --git a/tasks/e2e/cypress/integration/02-cli/02-cli-commands.spec.js b/tasks/e2e/cypress/integration/02-cli/02-cli-commands.spec.js deleted file mode 100644 index 88a4fdffa3fb..000000000000 --- a/tasks/e2e/cypress/integration/02-cli/02-cli-commands.spec.js +++ /dev/null @@ -1,61 +0,0 @@ -/* eslint-disable no-undef, camelcase */ -/// - -const BASE_DIR = Cypress.env('RW_PATH') - -describe('Check Redwood cli commands against tutorial', () => { - // These tests aren't visual, as they only run on the CLI - // Disable taking screenshots/videos for this spec - before(() => { - Cypress.config('record', false) - }) - - after(() => { - Cypress.config('record', true) - }) - it('Should run api tests successfully', () => { - cy.exec(`cd ${BASE_DIR}; yarn rw test api --no-watch`, { - timeout: 60000, - }) - .its('code') - .should('eq', 0) - }) - - // @TODO figure out why babel issues happen when linked - it.skip('Should run web tests successfully', () => { - cy.exec(`cd ${BASE_DIR}; yarn rw test web --no-watch`, { - timeout: 60000, - }) - .its('code') - .should('eq', 0) - }) - - it('Should run build successfully (no prerender)', () => { - // Check if webpack build on web, and babel build on api - // work correctly - cy.exec(`cd ${BASE_DIR}; yarn rw build --no-prerender`, { - timeout: 60000, - }) - .its('code') - .should('eq', 0) - }) - - it('Should prerender about and homepage', () => { - // Check if prerender is working - cy.exec(`cd ${BASE_DIR}; yarn rw prerender`, { - timeout: 60000, - }) - .its('code') - .should('eq', 0) - - const WEB_DIST = `${BASE_DIR}/web/dist` - - // Check prerendered files are generated - // Prerender prop added to routes in codemods/Step6_1_Routes.js - cy.readFile(`${WEB_DIST}/index.html`).should('contain', 'Redwood Blog') - cy.readFile(`${WEB_DIST}/about.html`).should( - 'contain', - 'This site was created to demonstrate my mastery of Redwood' - ) - }) -}) From d10fa19a7821f690aaaac2a929bdbe23069afc31 Mon Sep 17 00:00:00 2001 From: David S Price Date: Tue, 6 Apr 2021 16:54:03 -0700 Subject: [PATCH 3/8] use bash explicitly --- .github/workflows/e2e.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 1ac0f79f0ae3..e422f9ccd51f 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -30,14 +30,17 @@ jobs: - name: Create a temporary directory id: createpath + shell: bash run: | project_path=$(mktemp -d -t redwood.XXXXXX) echo "::set-output name=project_path::$project_path" - name: Create a RedwoodJS app + shell: bash run: ./tasks/run-e2e ${{ steps.createpath.outputs.project_path }} --no-start - name: Start server in background + shell: bash run: yarn rw dev & working-directory: ${{ steps.createpath.outputs.project_path }} From bcc1390e2c89a448abee2c8c3ad4922a70b3fff1 Mon Sep 17 00:00:00 2001 From: David S Price Date: Tue, 6 Apr 2021 17:19:19 -0700 Subject: [PATCH 4/8] no dev server; does Cypress start? --- .github/workflows/e2e.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index e422f9ccd51f..8b6788e5950f 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -39,12 +39,6 @@ jobs: shell: bash run: ./tasks/run-e2e ${{ steps.createpath.outputs.project_path }} --no-start - - name: Start server in background - shell: bash - run: yarn rw dev & - working-directory: ${{ steps.createpath.outputs.project_path }} - - - name: Cypress run uses: cypress-io/github-action@v2 env: From 5c195b2eafb542737e147689c9bc46bc7066c076 Mon Sep 17 00:00:00 2001 From: David S Price Date: Tue, 6 Apr 2021 17:56:43 -0700 Subject: [PATCH 5/8] re-add rw dev step --- .github/workflows/e2e.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 8b6788e5950f..dc70aeb32177 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -39,6 +39,11 @@ jobs: shell: bash run: ./tasks/run-e2e ${{ steps.createpath.outputs.project_path }} --no-start + - name: Start server in background + shell: bash + run: yarn rw dev & + working-directory: ${{ steps.createpath.outputs.project_path }} + - name: Cypress run uses: cypress-io/github-action@v2 env: From c7a2b41accf3dae2dd2e5a7a6e42d33ba70f0de6 Mon Sep 17 00:00:00 2001 From: David Price Date: Wed, 7 Apr 2021 14:52:56 -0700 Subject: [PATCH 6/8] Update .github/workflows/e2e.yaml --- .github/workflows/e2e.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index dc70aeb32177..d72e4027c210 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -41,8 +41,10 @@ jobs: - name: Start server in background shell: bash - run: yarn rw dev & - working-directory: ${{ steps.createpath.outputs.project_path }} + run: | + echo "${{ steps.createpath.outputs.project_path }}" + cd "${{ steps.createpath.outputs.project_path }}" + yarn rw dev & - name: Cypress run uses: cypress-io/github-action@v2 From 15bb07b65af94d871b9059ea4d7acbfb360e3836 Mon Sep 17 00:00:00 2001 From: David S Price Date: Thu, 8 Apr 2021 16:16:17 -0700 Subject: [PATCH 7/8] =?UTF-8?q?use=20cy.task=20=F0=9F=A4=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration/01-tutorial/tutorial.spec.js | 177 +++++++++++++++++- 1 file changed, 168 insertions(+), 9 deletions(-) diff --git a/tasks/e2e/cypress/integration/01-tutorial/tutorial.spec.js b/tasks/e2e/cypress/integration/01-tutorial/tutorial.spec.js index 8dd08ef02574..e8f93f7cb295 100644 --- a/tasks/e2e/cypress/integration/01-tutorial/tutorial.spec.js +++ b/tasks/e2e/cypress/integration/01-tutorial/tutorial.spec.js @@ -41,14 +41,21 @@ describe('The Redwood Tutorial - Golden path edition', () => { it('1. Our First Page', () => { //redwoodjs.com/tutorial/our-first-page + cy.task('execa', { + cmd: 'yarn redwood generate page home / --force', + cwd: BASE_DIR, + }) cy.visit('http://localhost:8910') - cy.exec(`cd ${BASE_DIR}; yarn redwood generate page home / --force`) cy.get('h1').should('contain', 'HomePage') }) it('2. A Second Page and a Link', () => { // https://redwoodjs.com/tutorial/a-second-page-and-a-link - cy.exec(`cd ${BASE_DIR}; yarn redwood generate page about --force`) + cy.task('execa', { + cmd: 'yarn redwood generate page about --force', + cwd: BASE_DIR, + }) + cy.wait(15000) cy.writeFile( path.join(BASE_DIR, 'web/src/pages/HomePage/HomePage.js'), Step2_1_PagesHome @@ -64,7 +71,11 @@ describe('The Redwood Tutorial - Golden path edition', () => { }) it('3. Layouts', () => { - cy.exec(`cd ${BASE_DIR}; yarn redwood generate layout blog --force`) + cy.task('execa', { + cmd: 'yarn redwood generate layout blog --force', + cwd: BASE_DIR, + }) + cy.wait(5000) cy.writeFile( path.join(BASE_DIR, 'web/src/layouts/BlogLayout/BlogLayout.js'), Step3_1_LayoutsBlog @@ -91,14 +102,31 @@ describe('The Redwood Tutorial - Golden path edition', () => { it('4. Getting Dynamic', () => { // https://redwoodjs.com/tutorial/getting-dynamic cy.writeFile(path.join(BASE_DIR, 'api/db/schema.prisma'), Step4_1_DbSchema) - cy.exec(`rm ${BASE_DIR}/api/db/dev.db`, { failOnNonZeroExit: false }) + cy.task('execa', { + cmd: `yarn rimraf ${BASE_DIR}/api/db/dev.db`, + cwd: BASE_DIR, + }) // need to also handle case where Prisma Client be out of sync - cy.exec( - `cd ${BASE_DIR}; yarn rimraf ./api/db/migrations && yarn rw prisma migrate reset --skip-seed --force` - ) - cy.exec(`cd ${BASE_DIR}; yarn rw prisma migrate dev`) + cy.task('execa', { + cmd: 'yarn rimraf ./api/db/migrations', + cwd: BASE_DIR, + }) + cy.task('execa', { + cmd: 'yarn rw prisma migrate reset --skip-seed --force', + cwd: BASE_DIR, + }) + cy.wait(5000) + cy.task('execa', { + cmd: 'yarn rw prisma migrate dev', + cwd: BASE_DIR, + }) + cy.wait(5000) - cy.exec(`cd ${BASE_DIR}; yarn rw g scaffold post --force`) + cy.task('execa', { + cmd: 'yarn rw g scaffold post --force', + cwd: BASE_DIR, + }) + cy.wait(5000) cy.visit('http://localhost:8910/posts') @@ -150,6 +178,137 @@ describe('The Redwood Tutorial - Golden path edition', () => { cy.get('input#title').type('Second post') cy.get('input#body').type('Hello world!') cy.get('button').contains('Save').click() + }) + + it('5. Cells', () => { + // https://redwoodjs.com/tutorial/cells + cy.visit('http://localhost:8910/') + + cy.task('execa', { + cmd: 'yarn rw g cell BlogPosts --force', + cwd: BASE_DIR, + }) + cy.wait(15000) + cy.writeFile( + path.join(BASE_DIR, 'web/src/components/BlogPostsCell/BlogPostsCell.js'), + Step5_1_ComponentsCellBlogPost + ) + cy.writeFile( + path.join( + BASE_DIR, + 'web/src/components/BlogPostsCell/BlogPostsCell.test.js' + ), + Step5_2_ComponentsCellBlogPostTest + ) + cy.writeFile( + path.join(BASE_DIR, 'web/src/pages/HomePage/HomePage.js'), + Step5_3_PagesHome + ) + cy.get('main').should( + 'contain', + // [{"title":"Second post","body":"Hello world!","__typename":"Post"}] + '"body":"Hello world!"' + ) + }) + + it('6. Routing Params', () => { + // https://redwoodjs.com/tutorial/routing-params + cy.task('execa', { + cmd: 'yarn rw g page BlogPost --force', + cwd: BASE_DIR, + }) + cy.task('execa', { + cmd: 'yarn rw g cell BlogPost --force', + cwd: BASE_DIR, + }) + cy.task('execa', { + cmd: 'yarn rw g component BlogPost --force', + cwd: BASE_DIR, + }) + cy.wait(15000) + + cy.writeFile(path.join(BASE_DIR, 'web/src/Routes.js'), Step6_1_Routes) + cy.writeFile( + path.join(BASE_DIR, 'web/src/pages/BlogPostPage/BlogPostPage.js'), + Step6_2_BlogPostPage + ) + cy.writeFile( + path.join(BASE_DIR, 'web/src/components/BlogPostCell/BlogPostCell.js'), + Step6_3_BlogPostCell + ) + cy.writeFile( + path.join( + BASE_DIR, + 'web/src/components/BlogPostCell/BlogPostCell.test.js' + ), + Step6_3_BlogPostCellTest + ) + cy.writeFile( + path.join(BASE_DIR, 'web/src/components/BlogPost/BlogPost.js'), + Step6_4_BlogPost + ) + cy.writeFile( + path.join(BASE_DIR, 'web/src/components/BlogPost/BlogPost.test.js'), + Step6_4_BlogPostTest + ) + cy.writeFile( + path.join(BASE_DIR, 'web/src/components/BlogPostsCell/BlogPostsCell.js'), + Step6_5_BlogPostsCell + ) + cy.writeFile( + path.join( + BASE_DIR, + 'web/src/components/BlogPostsCell/BlogPostsCell.mock.js' + ), + Step6_5_BlogPostsCellMock + ) + + // New entry + cy.visit('http://localhost:8910/posts') + cy.contains(' New Post').click() + cy.get('input#title').type('Third post') + cy.get('input#body').type('foo bar') + cy.get('button').contains('Save').click() + + cy.visit('http://localhost:8910/') + + // Detail Page + cy.contains('Second post').click() + cy.get('main').should('contain', 'Hello world!') + + cy.visit('http://localhost:8910/') + + cy.contains('Third post').click() + cy.get('main').should('contain', 'foo bar') + }) + + it("7. Everyone's Favorite Thing to Build: Forms", () => { + // https://redwoodjs.com/tutorial/everyone-s-favorite-thing-to-build-forms + cy.task('execa', { + cmd: 'yarn rw g page contact --force', + cwd: BASE_DIR, + }) + cy.wait(15000) + cy.writeFile( + path.join(BASE_DIR, 'web/src/layouts/BlogLayout/BlogLayout.js'), + Step7_1_BlogLayout + ) + cy.writeFile( + path.join(BASE_DIR, 'web/src/pages/ContactPage/ContactPage.js'), + Step7_2_ContactPage + ) + cy.writeFile(path.join(BASE_DIR, 'web/src/index.css'), Step7_3_Css) + cy.writeFile(path.join(BASE_DIR, 'web/src/Routes.js'), Step7_4_Routes) + + cy.contains('Contact').click() + cy.contains('Save').click() + cy.get('main').should('contain', 'name is required') + cy.get('main').should('contain', 'email is required') + cy.get('main').should('contain', 'message is required') + + cy.get('input#email').type('foo bar') + cy.contains('Save').click() + cy.get('main').should('contain', 'Please enter a valid email address') cy.visit('http://localhost:8910/') }) From 6d25ff8f94e53bf393e3c0932db69a85708663e3 Mon Sep 17 00:00:00 2001 From: David S Price Date: Thu, 8 Apr 2021 16:46:12 -0700 Subject: [PATCH 8/8] add cy.task plugin --- tasks/e2e/cypress/plugins/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tasks/e2e/cypress/plugins/index.js b/tasks/e2e/cypress/plugins/index.js index aa9918d21530..cf2aee1333f4 100644 --- a/tasks/e2e/cypress/plugins/index.js +++ b/tasks/e2e/cypress/plugins/index.js @@ -11,6 +11,7 @@ // This function is called when a project is opened or re-opened (e.g. due to // the project's config changing) +const execa = require('execa') /** * @type {Cypress.PluginConfig} @@ -18,4 +19,15 @@ module.exports = (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config + on('task', { + execa: async (args) => { + await execa(args.cmd, [], { + shell: true, + cleanup: true, + cwd: args.cwd, + }) + + return 0 + }, + }) }