diff --git a/.github/actions/integration/action.yml b/.github/actions/integration/action.yml deleted file mode 100644 index 3a31759c..00000000 --- a/.github/actions/integration/action.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: Run integration test -description: Prepares the environment and runs an integration test using Cypress - -inputs: - integration: - description: The integration test to run - required: true - node: - description: The Node version to use - required: false - default: 18 - dotenv: - description: The path to the .env file - required: false - default: .env.sample - -runs: - using: composite - - steps: - - uses: pnpm/action-setup@v2 - with: - version: 8 - - - name: Prepare dependencies - shell: bash - run: | - pnpm import - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: ${{ inputs.node }} - cache: 'pnpm' - - - name: Update /etc/hosts - shell: bash - run: | - sudo echo "127.0.0.1 localhost" | sudo tee -a /etc/hosts - - - name: Move dotenv file - shell: bash - run: | - mv examples/${{ inputs.integration }}/${{ inputs.dotenv }} examples/${{ inputs.integration }}/.env - - - name: Install dependencies - shell: bash - run: | - pnpm i - - - name: Start mock API server - shell: bash - run: | - cd examples/users-api - pnpm i - pnpm run start & - env: - DOMAIN: your-tenant.auth0.com - AUDIENCE: https://api.example.com/users - PORT: 3001 - - - name: Start application - shell: bash - run: | - cd examples/${{ inputs.integration }} - pnpm i - pnpm run start & - env: - PORT: 3000 - - - name: Run Cypress test - uses: cypress-io/github-action@v6 - with: - spec: cypress/e2e/smoke.cy.ts - install: false - wait-on: 'http://localhost:3001/, http://localhost:3000' diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 3e240cad..562d5b3d 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -1,14 +1,13 @@ name: Integration Tests on: - # merge_group: workflow_dispatch: - # pull_request: - # branches: - # - main - # push: - # branches: - # - main + pull_request: + branches: + - main + push: + branches: + - main permissions: contents: read @@ -19,69 +18,46 @@ concurrency: env: NODE_VERSION: 18 - # Mock user credentials for Cypress tests - CYPRESS_USER_EMAIL: testing@example.com - CYPRESS_USER_PASSWORD: mockpassword jobs: - test-react-router: - name: Run react-router tests + test-examples: + name: Run example tests runs-on: ubuntu-latest env: SKIP_PREFLIGHT_CHECK: true - REACT_APP_DOMAIN: your-tenant.auth0.com - REACT_APP_CLIENT_ID: yourclientid - REACT_APP_AUDIENCE: https://api.example.com/users - REACT_APP_API_PORT: 3001 + CYPRESS_USER_EMAIL: ${{secrets.CYPRESS_USER_EMAIL}} + CYPRESS_USER_PASSWORD: ${{secrets.CYPRESS_USER_PASSWORD}} + REACT_APP_DOMAIN: ${{secrets.TEST_DOMAIN}} + REACT_APP_CLIENT_ID: ${{secrets.TEST_CLIENT_ID}} + REACT_APP_AUDIENCE: ${{secrets.TEST_AUDIENCE}} + GATSBY_DOMAIN: ${{secrets.TEST_DOMAIN}} + GATSBY_CLIENT_ID: ${{secrets.TEST_CLIENT_ID}} + GATSBY_AUDIENCE: ${{secrets.TEST_AUDIENCE}} + NEXT_PUBLIC_DOMAIN: ${{secrets.TEST_DOMAIN}} + NEXT_PUBLIC_CLIENT_ID: ${{secrets.TEST_CLIENT_ID}} + NEXT_PUBLIC_AUDIENCE: ${{secrets.TEST_AUDIENCE}} + DOMAIN: ${{secrets.TEST_DOMAIN}} + AUDIENCE: ${{secrets.TEST_AUDIENCE}} steps: - name: Checkout code uses: actions/checkout@v4 - - name: Run integration test - uses: ./.github/actions/integration - with: - integration: 'cra-react-router' - node: ${{ env.NODE_VERSION }} + - name: Install dependencies + run: npm ci - test-gatsby: - name: Run Gatsby tests - runs-on: ubuntu-latest + - name: Build SDK + run: npm run build - env: - GATSBY_DOMAIN: your-tenant.auth0.com - GATSBY_CLIENT_ID: yourclientid - GATSBY_AUDIENCE: https://api.example.com/users - GATSBY_API_PORT: 3001 + - name: Install examples + run: npm run install:examples - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Run integration test - uses: ./.github/actions/integration - with: - integration: 'gatsby-app' - node: ${{ env.NODE_VERSION }} - dotenv: '.env.development.sample' + - name: Run integration test (CRA) + run: npm run test:cra - test-nextjs: - name: Run NextJS tests - runs-on: ubuntu-latest - - env: - NEXT_PUBLIC_DOMAIN: your-tenant.auth0.com - NEXT_PUBLIC_CLIENT_ID: yourclientid - NEXT_PUBLIC_AUDIENCE: https://api.example.com/users - NEXT_PUBLIC_API_PORT: 3001 - - steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Run integration test (NextJS) + run: npm run test:nextjs - - name: Run integration test - uses: ./.github/actions/integration - with: - integration: 'nextjs-app' - node: ${{ env.NODE_VERSION }} + - name: Run integration test (Gatsby) + run: npm run test:gatsby diff --git a/browserstack.json b/browserstack.json index e22e768f..15bf62be 100644 --- a/browserstack.json +++ b/browserstack.json @@ -17,7 +17,7 @@ } ], "run_settings": { - "cypress_config_file": "./cypress.config.js", + "cypress_config_file": "./cypress-bs.config.js", "cypress-version": "13.1", "project_name": "Auth0 React SDK", "exclude": [], diff --git a/cypress-bs.config.js b/cypress-bs.config.js new file mode 100644 index 00000000..a92c1b0f --- /dev/null +++ b/cypress-bs.config.js @@ -0,0 +1,18 @@ +const { defineConfig } = require('cypress'); + +module.exports = defineConfig({ + defaultCommandTimeout: 7500, + chromeWebSecurity: false, + viewportWidth: 1000, + viewportHeight: 1000, + fixturesFolder: false, + reporter: 'junit', + reporterOptions: { + mochaFile: 'test-results/cypress/junit-[hash].xml', + }, + e2e: { + setupNodeEvents(on, config) {}, + baseUrl: 'http://127.0.0.1:3000', + supportFile: false, + }, +}); diff --git a/cypress-bs.json b/cypress-bs.json deleted file mode 100644 index f3f69da5..00000000 --- a/cypress-bs.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "baseUrl": "http://127.0.0.1:3000", - "chromeWebSecurity": false, - "viewportWidth": 1000, - "viewportHeight": 1000, - "fixturesFolder": false, - "pluginsFile": false, - "supportFile": false, - "reporter": "junit", - "reporterOptions": { - "mochaFile": "test-results/cypress/junit-[hash].xml" - } -} diff --git a/cypress.config.js b/cypress.config.js index eda489a4..0aa2749d 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,6 +1,7 @@ const { defineConfig } = require('cypress'); module.exports = defineConfig({ + defaultCommandTimeout: 7500, chromeWebSecurity: false, viewportWidth: 1000, viewportHeight: 1000, @@ -14,4 +15,4 @@ module.exports = defineConfig({ baseUrl: 'http://localhost:3000', supportFile: false, }, -}); \ No newline at end of file +}); diff --git a/examples/gatsby-app/src/components/Users.js b/examples/gatsby-app/src/components/Users.js index f8a8fb6e..6bc53114 100644 --- a/examples/gatsby-app/src/components/Users.js +++ b/examples/gatsby-app/src/components/Users.js @@ -10,7 +10,7 @@ export function Users() { loading, error, data: users = [], - } = useApi(`http://localhost:${PORT}/users`, { + } = useApi(`http://127.0.0.1:${PORT}/users`, { audience: process.env.GATSBY_AUDIENCE, scope: 'profile email read:users', }); diff --git a/package-lock.json b/package-lock.json index a3143259..4a1da3a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@testing-library/react": "^14.0.0", "@testing-library/react-hooks": "^7.0.2", "@types/jest": "^29.2.3", - "@types/react": "^17.0.52", + "@types/react": "^18.2.22", "@types/react-dom": "^18.2.7", "@typescript-eslint/eslint-plugin": "^5.45.0", "@typescript-eslint/parser": "^5.45.0", @@ -2036,9 +2036,9 @@ "dev": true }, "node_modules/@types/react": { - "version": "17.0.65", - "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.65.tgz", - "integrity": "sha512-oxur785xZYHvnI7TRS61dXbkIhDPnGfsXKv0cNXR/0ml4SipRIFpSMzA7HMEfOywFwJ5AOnPrXYTEiTRUQeGlQ==", + "version": "18.2.22", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.22.tgz", + "integrity": "sha512-60fLTOLqzarLED2O3UQImc/lsNRgG0jE/a1mPW9KjMemY0LMITWEsbS4VvZ4p6rorEHd5YKxxmMKSDK505GHpA==", "dev": true, "dependencies": { "@types/prop-types": "*", diff --git a/package.json b/package.json index b90a5e0f..913e7539 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "start:api": "npm start --prefix=examples/users-api", "test:cra": "start-server-and-test start:api 3001 start:cra http-get://127.0.0.1:3000 cypress:run", "test:cra:watch": "start-server-and-test start:api 3001 start:cra 3000 cypress:open", - "test:gatsby": "start-server-and-test start:api 3001 start:gatsby 3000 cypress:run", + "test:gatsby": "start-server-and-test start:api 3001 start:gatsby http-get://localhost:3000 cypress:run", "test:gatsby:watch": "start-server-and-test start:api 3001 start:gatsby 3000 cypress:open", "test:nextjs": "start-server-and-test start:api 3001 start:nextjs 3000 cypress:run", "test:nextjs:watch": "start-server-and-test start:api 3001 start:nextjs 3000 cypress:open", @@ -58,7 +58,7 @@ "@testing-library/react": "^14.0.0", "@testing-library/react-hooks": "^7.0.2", "@types/jest": "^29.2.3", - "@types/react": "^17.0.52", + "@types/react": "^18.2.22", "@types/react-dom": "^18.2.7", "@typescript-eslint/eslint-plugin": "^5.45.0", "@typescript-eslint/parser": "^5.45.0",