Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add e2e tests #982

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
packages/*/docs
node_modules
dist
**/__tests__/*.node.test.ts
**/__tests__/*.node.test.ts
playwright
coverage
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ module.exports = {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'tsdoc/syntax': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
},
overrides: [
// Disable all tsdoc checking in test files
{
files: ['*.test.*[t|j]s*', '*.fixtures.*[t|j]s*'],
files: ['*.test.*[t|j]s*', '*.fixtures.*[t|j]s*', 'tests/e2e/**/*.*'],
rules: {
'tsdoc/syntax': 'off',
// We use const xxx = () => {} many times in tests.
Expand Down
123 changes: 101 additions & 22 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main and next branches
# events but only for the main, next and v1 branches
on:
push:
branches:
Expand All @@ -17,34 +17,122 @@ on:
- '**/docs/**'
- '**.md'

# Setup concurrency to the ref (branch / tag) that triggered the workflow
concurrency: ci-${{ github.ref }}

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "CI"
CI:
# The type of runner that the job will run on
# This job will run the minimal checks: linting, unit tests and type checking.
BasicChecks:
name: Basic Checks

runs-on: ubuntu-latest
# Do not run if the pull request is a draft
if: ${{ !github.event.pull_request.draft && !contains(github.event.commits[0].message, '[skip build]') }}

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v4
with:
node-version: '20'
scope: '@farfetch'
cache: 'yarn'
always-auth: true

- name: Install dependencies
run: yarn install --ignore-engines --frozen-lockfile

- name: Lint
run: yarn lint

- name: Unit Tests
run: yarn test --ci

- name: Type checking
run: yarn ci:types

# This job will run integration tests, possibly only the critical ones if the branch is master or next
IntegrationTests:
name: Integration Tests

runs-on: ubuntu-latest

env:
PROXY_TARGET: ${{ secrets.E2E_TESTS_PROXY_TARGET }}
TEST_ACCOUNT_USERNAME: ${{ secrets.E2E_TESTS_ACCOUNT_USERNAME }}
TEST_ACCOUNT_PASSWORD: ${{ secrets.E2E_TESTS_ACCOUNT_PASSWORD }}

# Do not run if the pull request is a draft
if: ${{ !github.event.pull_request.draft && !contains(github.event.commits[0].message, '[skip build]') }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- uses: actions/setup-node@v4
with:
node-version: '20'
scope: '@farfetch'
cache: 'yarn'
always-auth: true

- name: Install dependencies
run: yarn install --ignore-engines --frozen-lockfile

- name: Install Playwright Browsers
run: npx playwright install chromium --with-deps

- name: Update version and build packages
run: yarn ci:release:no-publish && yarn build && yarn build:copy-package-json

- name: Build test application
run: yarn test:e2e:build

- name: Setup host alias
run: |
sudo echo "127.0.0.1 development.blackandwhite-ff.com" | sudo tee -a /etc/hosts

- name: Start server
run: yarn test:e2e:server &

- name: Sleep to wait for server to start
run: sleep 5

- name: Run critical tests
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/next' }}
run: yarn test:e2e:run:critical

- name: Run all tests
if: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/next' }}
run: yarn test:e2e:run

- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: tests/e2e/report
retention-days: 30

# This will make a release after the dependant checks are finished and
# it is in a branch that allows publishing (master and next).
Release:
runs-on: ubuntu-latest

# Do not run if the pull request is a draft
if: ${{ !github.event.pull_request.draft && !contains(github.event.commits[0].message, '[skip build]') }}

needs: [BasicChecks, IntegrationTests]
steps:
# Use fetch-depth: 0 so that all tags and branches are fetched
# Use persist-credentials: false so that the make release step uses another personal access
# token which has admin access and can push the version commit without the restriction
# of creating a pull-request.
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: false

- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
node-version: '20'
scope: '@farfetch'
cache: 'yarn'
always-auth: true
Expand Down Expand Up @@ -77,15 +165,6 @@ jobs:
- name: Install dependencies
run: yarn install --ignore-engines --frozen-lockfile

- name: Lint
run: yarn lint

- name: Test
run: yarn test --ci

- name: Type checking
run: yarn ci:types

# Only make a release if it is a run of the 'main' or 'next' branches
# or a pull request that contains a 'chore: make release' message
- name: Make release
Expand All @@ -102,4 +181,4 @@ jobs:
GIT_AUTHOR_EMAIL: ${{ secrets.RELEASE_BOT_GIT_EMAIL }}
GIT_COMMITTER_NAME: ${{ secrets.RELEASE_BOT_GIT_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.RELEASE_BOT_GIT_EMAIL }}
run: yarn ci:release
run: yarn ci:release
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ junit.xml
coverage/
node_modules/

**/package-lock.json
**/dist
**/docs
**/.cache
!/docs/contributing

**/types/**/build
package-lock.json
dist/
.cache/

.eslintcache

*.tsbuildinfo

build/
playwright/
report/
27 changes: 27 additions & 0 deletions cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN CERTIFICATE-----
MIIEnTCCAwWgAwIBAgIRANsUm+o6x+zXg4Y2aq0D1bgwDQYJKoZIhvcNAQELBQAw
ga8xHjAcBgNVBAoTFW1rY2V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a2LmZpnd6ofGH/X
eCUo0cz04fygKSnhPJ/qG7qgh+rZuA9Nv7bkw0gFBiqGFAOm9e2P7p1RCU77tFPh
mBNGRheiShtxdu47B9F39WwmOxNqPataM6XfGGhkJCI7qxF8VLngaLfyyi8zVd/u
gAqw/6suXKY86kbcqOFJxQ+Z3IKMwvaetU83tRhYzn8bbO7ZyT0lEJ8OBStXY8sP
Lxqa9c+BPBTd3TvjVyMo4OWGGkKi6kEswAKUnc8ebYDmj2YfQtesyD47q3uZ1fdU
LaZETXaoqnuncKEPwez+jNDcU/qutrsXLxqcpzcZuMG5sKKb+qADkrqjwdA9QBG1
rWadjJySkkRdiB+hvRxrT65aJ/QnHiesdGv2fXxW2Bk0PhW1MEUx5FBdxAx6q51o
ZrYr3hbldC0IF0EsekX4H2e+Ul26p/1yBnp096rYd1Ia
-----END CERTIFICATE-----
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ module.exports = {
snapshotSerializers: ['./tests/axiosErrorSerializer.mts'],
// The test environment that will be used for testing
testEnvironment: 'jsdom',
// Patterns to ignore
testPathIgnorePatterns: ['/node_modules/', 'dist', 'e2e'],
// The regexp pattern or array of patterns that Jest uses to detect test files
testRegex: ['.+\\.test.[jt]s(x?)$', '!dist'],
testRegex: ['.+\\.test.[jt]s(x?)$'],
// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
// An array of glob patterns indicating a set of files for which coverage information should be collected
Expand All @@ -48,6 +50,7 @@ module.exports = {
'packages/react/src/analytics/integrations/Forter/loadForterScriptForSiteId.ts',
'packages/redux/src/entities/schemas',
'__fixtures__',
'e2e',
],
// A map from regular expressions to module names that allow to stub out resources with a single module
moduleNameMapper: {
Expand Down
28 changes: 28 additions & 0 deletions key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDWR/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Nenn7Ec3loKs/ocwi5uo57JX6GauZ3q8DZLvEeCwn
aUahktbk8lobbFiL3mAjP5gNisNAqG36EcCd16IL5EfXJpiuUyfueF1pjsd4PkWP
bWkH4EmlnruQB38PnBF04Rm7ELy0TdJgMJSBnEfesVEB7vALoII8JYsKMQKBgCB9
DEqLpIvYc5oIGB9W+b1s66pPxMOfl7cL4RNV3rvn9qhb63GGQl1H7982eSBfZemR
BHAjgdqLLi7zBop5PL0WxaMMl/6d2gmMqyDHxP4XEWWnaWmjYovEZ6PVkIsGHoLD
A/D7Y3pXvn8OmnotOVgJWS4zHucre5TCZy01D3MXAoGBAKuf56LxUjgyGK5LnXvN
4aC50epwdHPwR6iCAA87p/NCrzTlN2gu/f4+OurFytkVmmAfgFYGZCkd0mSuu8rh
8KT0A+VkDL/xUyAJ+0zwhddtf3vTdRKtbcMXXUfjlTrCmc+3vj952DLrkD5aCzFD
nbCyQ8YrEUI9nU+JmrQWwsHR
-----END PRIVATE KEY-----
28 changes: 21 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,32 @@
],
"license": "MIT",
"engines": {
"node": ">=14",
"node": ">=16",
"npm": ">=6.4.1"
},
"scripts": {
"build": "lerna run --concurrency 1 --stream --scope \"@farfetch/*\" build",
"build:watch": "lerna run --parallel --concurrency=9999 --scope \"@farfetch/*\" build:watch",
"build:copy-package-json": "lerna run --parallel --concurrency=9999 --scope \"@farfetch/*\" build:copy-package-json",
"clean": "scripts/clean.sh && yarn clean:build",
"clean:build": "lerna run --concurrency 4 --no-bail --parallel --scope \"@farfetch/*\" clean",
"lint": "npx eslint . --ext .js,.ts,.jsx,.tsx,.mts,.mjs,.cjs",
"postinstall": "patch-package",
"format": "prettier --write '**/*.{js,ts,jsx,tsx,mts,mjs,cjs,json,md}'",
"test": "rimraf coverage && yarn clean:build && jest",
"test:e2e:build": "cross-env TS_NODE_PROJECT=\"tests/e2e/tsconfig.json\" node --loader ts-node/esm node_modules/webpack-cli/bin/cli.js --config tests/e2e/webpack.config.ts",
"test:e2e:server": "tests/e2e/scripts/start-local-server.sh",
"test:e2e:run": "playwright test --config=tests/e2e/playwright.config.ts",
"test:e2e:run:critical": "playwright test --config=tests/e2e/playwright.config.ts --project=critical-tests",
"test:e2e:run:non-critical": "playwright test --config=tests/e2e/playwright.config.ts --project=non-critical-tests",
"prepare": "husky install",
"yalc:publish": "scripts/yalc-publish.sh",
"yalc:push": "scripts/yalc-push.sh",
"ci:types": "yarn ci:types:runtime && yarn ci:types:tests",
"ci:types:runtime": "lerna run --concurrency 4 --no-bail --parallel --scope \"@farfetch/*\" ci:types",
"ci:types:tests": "tsc -p tsconfig.ci.tests.json",
"ci:release": "scripts/release.sh",
"ci:release:no-publish": "yarn ci:release --no-publish",
"dev:link": "lerna run --concurrency 1 --stream --scope \"@farfetch/*\" dev:link",
"dev:unlink": "lerna exec --concurrency 1 --stream --scope \"@farfetch/*\" 'cd dist && yarn unlink'",
"release:git": "scripts/release-git.sh"
Expand All @@ -50,22 +57,24 @@
"@babel/preset-typescript": "^7.13.0",
"@commitlint/cli": "^17.0.1",
"@commitlint/config-conventional": "^17.0.0",
"@playwright/test": "^1.40.1",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^13.3.0",
"@types/invariant": "^2.2.34",
"@types/jest": "^27.5.1",
"@types/jquery": "^3.5.16",
"@types/lodash-es": "^4.17.6",
"@types/node": "18.14.2",
"@types/react": "^18.0.10",
"@types/react": "^18.2.10",
"@types/redux-mock-store": "^1.0.3",
"@types/url-parse": "^1.4.3",
"@types/uuid": "3.4.0",
"@typescript-eslint/eslint-plugin": "5.54.0",
"@typescript-eslint/parser": "5.53.0",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"babel-eslint": "^10.1.0",
"browserslist-config-google": "^2.0.0",
"core-js": "^3.6.5",
"cross-env": "^7.0.3",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-react-app": "^7.0.1",
Expand All @@ -88,19 +97,23 @@
"jest-watch-typeahead": "^1.1.0",
"lerna": "^5.0.0",
"lint-staged": "^12.4.2",
"local-web-server": "^5.3.0",
"lodash-es": "^4.17.21",
"msw": "^1.1.0",
"patch-package": "^6.5.1",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.6.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^3.0.2",
"typescript": "5.0.2"
"ts-node": "^10.9.2",
"typescript": "5.3.3",
"webpack-cli": "^5.1.4"
},
"resolutions": {
"@babel/core": "7.16.0",
"@babel/preset-env": "7.16.4",
"@typescript-eslint/eslint-plugin": "5.54.0",
"@typescript-eslint/eslint-plugin": "6.21.0",
"color-string": "^1.6.0",
"css-what": "^5.0.1",
"dot-prop": "^6.0.1",
Expand All @@ -126,6 +139,7 @@
"*.{js,ts}": "eslint --fix"
},
"workspaces": [
"packages/*"
"packages/*",
"tests/e2e"
]
}
Loading
Loading