diff --git a/.circleci/config.yml b/.circleci/config.yml index dd0d77bc6..1c16fe79b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,6 +8,10 @@ deploy_defaults: &deploy_defaults docker: - image: cimg/python:3.10.2 +test_defaults: &test_defaults + docker: + - image: cypress/browsers:node16.14.2-slim-chrome100-ff99-edge + install_build_dependency: &install_build_dependency name: Installation of build and deployment dependencies. command: | @@ -50,6 +54,14 @@ running_yarn_build: &running_yarn_build yarn install yarn build +running_yarn_test: &running_yarn_test + name: Running Yarn Test Build + command: | + yarn install + yarn cypress install + yarn build + yarn cy:ci + workspace_persist: &workspace_persist root: . paths: @@ -81,6 +93,27 @@ build_steps: &build_steps - run: *running_yarn_build - persist_to_workspace: *workspace_persist +test_steps: &test_steps + # Initialization. + - checkout + - setup_remote_docker + - restore_cache: + key: test-node-modules-{{ checksum "yarn.lock" }} + - run: *running_yarn_test + - save_cache: + key: test-node-modules-{{ checksum "yarn.lock" }} + paths: + - node_modules + - /root/.cache/Cypress + - store_test_results: + path: cypress/test-report + - store_artifacts: + path: cypress/test-report + - store_artifacts: + path: cypress/videos + - store_artifacts: + path: cypress/screenshots + deploy_steps: &deploy_steps - checkout - attach_workspace: *workspace_attach @@ -127,6 +160,14 @@ jobs: LOGICAL_ENV: "prod" APPNAME: "platform-ui-mvp" steps: *build_steps + + test-dev: + <<: *test_defaults + environment: + DEPLOY_ENV: "DEV" + LOGICAL_ENV: "dev" + APPNAME: "platform-ui-mvp" + steps: *test_steps # Just tests commited code. deployDev: @@ -147,35 +188,6 @@ jobs: APPNAME: "platform-ui-mvp" steps: *deploy_steps - # Test job for the cases when we don not need deployment. - e2e-test: - docker: - - image: cypress/browsers:node16.14.2-slim-chrome100-ff99-edge - steps: - - checkout - - restore_cache: - key: test-node-modules-{{ checksum "yarn.lock" }} - - run: - name: Config Git - command: git config --global url."https://git@".insteadOf git:// - - run: - name: Install Dependencies - command: yarn install - no_output_timeout: 20m - - run: - name: Install Cypress Binary - command: yarn cypress install - - run: - name: Build the application - command: yarn build - no_output_timeout: 20m - - save_cache: - key: test-node-modules-{{ checksum "yarn.lock" }} - paths: - - node_modules - - /root/.cache/Cypress - - run: yarn cy:ci - workflows: version: 2 build: @@ -201,9 +213,6 @@ workflows: ignore: - master - - e2e-test: - context : org-global - - build-prod: context : org-global filters: @@ -215,7 +224,6 @@ workflows: context : org-global requires: - build-dev - - e2e-test filters: branches: only: @@ -229,3 +237,6 @@ workflows: branches: only: - master + + - test-dev: + context : org-global \ No newline at end of file diff --git a/.gitignore b/.gitignore index 63c983693..6d23f4087 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ # testing /coverage .nyc_output +/cypress/screenshots +/cypress/videos +/cypress/test-report # production /build diff --git a/README.md b/README.md index 8e34fdd33..f3d7134a8 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,11 @@ See the [Dev Center README](/src-ts/tools/dev-center/README.md) for further inst | `yarn eslint` | Run eslint against js/x files and outputs report | | `yarn eslint:fix` | Run eslint against js/x files, fixes auto-fixable issues, and outputs report | | `yarn test` | Run unit tests, watching for changes and re-running per your specifications | -| `yarn test:no-watch` | Run unit tests once, without watching for changes or re-running | +| `yarn test:no-watch` | Run unit tests once, without watching for changes or re-running | +| `yarn cy:run` | Run e2e tests once in local command with the site is running | +| `yarn cy:ci` | Run e2e tests once by circle ci | +| `yarn report:coverage`| Generate e2e coverage report in html format | +| `yarn report:coverage:text` | Generate e2e coverage report in text format | ## Folder Structure diff --git a/cypress.config.ts b/cypress.config.ts index e622ea360..fc55f43d8 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,19 +1,33 @@ +// tslint:disable-next-line: no-submodule-imports This is the way cypress does it +import task from '@cypress/code-coverage/task' import { defineConfig } from 'cypress' export default defineConfig({ - fixturesFolder: false, - video: false, - screenshotOnRunFailure: false, - defaultCommandTimeout: 10000, - e2e: { - baseUrl: 'http://localhost:3000', - specPattern: "cypress/e2e/**/*.spec.{js,jsx,ts,tsx}", - supportFile: "cypress/support/e2e.ts", - viewportHeight: 1000, - viewportWidth: 1280, - setupNodeEvents(on, config) { - require('@cypress/code-coverage/task')(on, config) - return config; + defaultCommandTimeout: 10000, + e2e: { + // baseUrl: 'https://local.topcoder-dev.com', + baseUrl: 'http://localhost:3000', + setupNodeEvents: setUpNodeEvents, + specPattern: 'cypress/e2e/**/*.spec.{js,jsx,ts,tsx}', + supportFile: 'cypress/support/e2e.ts', + viewportHeight: 1000, + viewportWidth: 1280, }, - }, + fixturesFolder: false, + reporter: 'junit', + reporterOptions: { + mochaFile: 'cypress/test-report/test-result-[hash].xml', + toConsole: false, + }, + screenshotOnRunFailure: true, + video: true, }) + +// adds the config to node setup events +function setUpNodeEvents( + on: Cypress.PluginEvents, + config: Cypress.PluginConfigOptions +): Cypress.PluginConfigOptions { + task(on, config) + return config +} diff --git a/cypress/e2e/home/home.spec.ts b/cypress/e2e/home/home.spec.ts index 72bc22b1b..43c584180 100644 --- a/cypress/e2e/home/home.spec.ts +++ b/cypress/e2e/home/home.spec.ts @@ -1,6 +1,12 @@ describe('Landing Page', () => { - beforeEach(() => cy.visit('/')) - it('loads landing page should be successfully', () => { - cy.get('[data-cy="root"]').should('be.visible') - }) + + beforeEach(() => cy.visit('/')) + + it('loads landing page should be successfully', () => { + cy.get('[data-id="root"]').should('be.visible') + }) + + it.skip('loads landing page should fail', () => { + cy.get('[data-id="root"]').should('not.be.visible') + }) }) diff --git a/package.json b/package.json index bf9628928..d17a1b4b5 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "eslint:fix": "eslint 'src/**/*.{js,jsx}' --fix", "test": "react-scripts test --watchAll", "test:no-watch": "react-scripts test --watchAll=false --passWithNoTests", - "cy:run": "cypress run", + "cy:run": "cypress run --reporter junit", "cy:ci": "start-server-and-test 'serve -s build -n -p 3000' http://localhost:3000 'cy:run'", "report:coverage": "nyc report --reporter=html", "report:coverage:text": "nyc report --reporter=text" @@ -23,9 +23,6 @@ "dependencies": { "@datadog/browser-logs": "^4.7.1", "@heroicons/react": "^1.0.6", - "@types/dompurify": "^2.3.3", - "@types/highlightjs": "^9.12.2", - "@types/marked": "4.0.3", "apexcharts": "^3.35.3", "axios": "^0.26.1", "browser-cookies": "^1.2.0", @@ -82,8 +79,12 @@ "@testing-library/react": "^12.0.0", "@testing-library/user-event": "^13.2.1", "@types/axios": "^0.14.0", + "@types/cypress": "^1.1.3", + "@types/dompurify": "^2.3.3", + "@types/highlightjs": "^9.12.2", "@types/jest": "^27.0.1", "@types/lodash": "^4.14.182", + "@types/marked": "4.0.3", "@types/node": "^18.7.13", "@types/reach__router": "^1.3.10", "@types/react": "^18.0.5", @@ -94,6 +95,7 @@ "@types/segment-analytics": "^0.0.34", "@types/systemjs": "^6.1.0", "@types/uuid": "^8.3.4", + "@wdio/junit-reporter": "^7.24.0", "autoprefixer": "^9.8.6", "babel-eslint": "^11.0.0-beta.2", "babel-jest": "^24.9.0", diff --git a/public/index.html b/public/index.html index 35c55bd1e..da3a59318 100644 --- a/public/index.html +++ b/public/index.html @@ -32,7 +32,7 @@
- + -