Skip to content

Commit b86fbc8

Browse files
author
Bruno Oliveira
committed
chore: add integration tests
// TODO
1 parent cb117d0 commit b86fbc8

34 files changed

Lines changed: 3835 additions & 111 deletions

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ module.exports = {
127127
overrides: [
128128
// Disable all tsdoc checking in test files
129129
{
130-
files: ['*.test.*[t|j]s*', '*.fixtures.*[t|j]s*'],
130+
files: ['*.test.*[t|j]s*', '*.fixtures.*[t|j]s*', 'tests/e2e/**/*.*'],
131131
rules: {
132132
'tsdoc/syntax': 'off',
133133
// We use const xxx = () => {} many times in tests.

.github/workflows/CI.yml

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: CI
22

33
# Controls when the action will run. Triggers the workflow on push or pull request
4-
# events but only for the main and next branches
4+
# events but only for the main, next and v1 branches
55
on:
66
push:
77
branches:
@@ -17,33 +17,113 @@ on:
1717
- '**/docs/**'
1818
- '**.md'
1919

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

23-
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
2422
jobs:
25-
# This workflow contains a single job called "CI"
26-
CI:
27-
# The type of runner that the job will run on
23+
# This job will run the minimal checks: linting, unit tests and type checking.
24+
SimpleChecks:
2825
runs-on: ubuntu-latest
2926
# Do not run if the pull request is a draft
3027
if: ${{ !github.event.pull_request.draft && !contains(github.event.commits[0].message, '[skip build]') }}
3128

32-
# Steps represent a sequence of tasks that will be executed as part of the job
3329
steps:
34-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
30+
- uses: actions/checkout@v3
31+
32+
- uses: actions/setup-node@v4
33+
with:
34+
node-version: '16'
35+
registry-url: 'https://registry.npmjs.org'
36+
scope: '@farfetch'
37+
cache: 'yarn'
38+
always-auth: true
39+
40+
- name: Install dependencies
41+
run: yarn install --ignore-engines --frozen-lockfile
42+
43+
- name: Lint
44+
run: yarn lint
45+
46+
- name: Unit Tests
47+
run: yarn test --ci
48+
49+
- name: Type checking
50+
run: yarn ci:types
51+
52+
# This job will run integration tests, possibly only the critical ones if the branch is master or next
53+
IntegrationTests:
54+
runs-on: ubuntu-latest
55+
# Do not run if the pull request is a draft
56+
if: ${{ !github.event.pull_request.draft && !contains(github.event.commits[0].message, '[skip build]') }}
57+
58+
steps:
59+
- uses: actions/checkout@v3
60+
61+
- uses: actions/setup-node@v4
62+
with:
63+
node-version: '16'
64+
registry-url: 'https://registry.npmjs.org'
65+
scope: '@farfetch'
66+
cache: 'yarn'
67+
always-auth: true
68+
69+
- name: Install dependencies
70+
run: yarn install --ignore-engines --frozen-lockfile
71+
72+
- name: Install Playwright Browsers
73+
run: npx playwright install --with-deps
74+
75+
- name: Update version and build packages
76+
run: yarn ci:release --dry-run && yarn build && yarn build:copy-package-json
77+
78+
- name: Build test application
79+
run: yarn test:e2e:build
80+
81+
- name: Setup host alias
82+
run: |
83+
sudo echo "127.0.0.1 development.blackandwhite-ff.com" | sudo tee -a /etc/hosts
84+
85+
- name: Start server
86+
run: yarn test:e2e:server &
87+
88+
- name: Sleep to wait for server to start
89+
run: sleep 5
90+
91+
- name: Run critical tests
92+
run: yarn test:e2e:run:critical
93+
94+
- name: Run all tests
95+
if: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/next' }}
96+
run: yarn test:e2e:run
97+
98+
- uses: actions/upload-artifact@v3
99+
if: always()
100+
with:
101+
name: playwright-report
102+
path: playwright-report/
103+
retention-days: 30
104+
105+
# This will make a release after the dependant checks are finished and
106+
# it is in a branch that allows publishing (master and next).
107+
Release:
108+
runs-on: ubuntu-latest
109+
110+
# Do not run if the pull request is a draft
111+
if: ${{ !github.event.pull_request.draft && !contains(github.event.commits[0].message, '[skip build]') }}
112+
113+
needs: [SimpleChecks, IntegrationTests]
114+
steps:
35115
# Use fetch-depth: 0 so that all tags and branches are fetched
36116
# Use persist-credentials: false so that the make release step uses another personal access
37117
# token which has admin access and can push the version commit without the restriction
38118
# of creating a pull-request.
39-
- uses: actions/checkout@v2
119+
- uses: actions/checkout@v3
40120
with:
41121
fetch-depth: 0
42122
persist-credentials: false
43123

44-
- uses: actions/setup-node@v2
124+
- uses: actions/setup-node@v4
45125
with:
46-
node-version: '14'
126+
node-version: '16'
47127
registry-url: 'https://registry.npmjs.org'
48128
scope: '@farfetch'
49129
cache: 'yarn'
@@ -77,15 +157,6 @@ jobs:
77157
- name: Install dependencies
78158
run: yarn install --ignore-engines --frozen-lockfile
79159

80-
- name: Lint
81-
run: yarn lint
82-
83-
- name: Test
84-
run: yarn test --ci
85-
86-
- name: Type checking
87-
run: yarn ci:types
88-
89160
# Only make a release if it is a run of the 'main' or 'next' branches
90161
# or a pull request that contains a 'chore: make release' message
91162
- name: Make release
@@ -102,4 +173,4 @@ jobs:
102173
GIT_AUTHOR_EMAIL: ${{ secrets.RELEASE_BOT_GIT_EMAIL }}
103174
GIT_COMMITTER_NAME: ${{ secrets.RELEASE_BOT_GIT_NAME }}
104175
GIT_COMMITTER_EMAIL: ${{ secrets.RELEASE_BOT_GIT_EMAIL }}
105-
run: yarn ci:release
176+
run: yarn ci:release

.gitignore

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ junit.xml
1010
coverage/
1111
node_modules/
1212

13-
**/package-lock.json
14-
**/dist
15-
**/docs
16-
**/.cache
17-
!/docs/contributing
18-
19-
**/types/**/build
13+
package-lock.json
14+
dist/
15+
.cache/
2016

2117
.eslintcache
2218

2319
*.tsbuildinfo
20+
21+
build/
22+
playwright/
23+
report/

cert.pem

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIEnTCCAwWgAwIBAgIRANsUm+o6x+zXg4Y2aq0D1bgwDQYJKoZIhvcNAQELBQAw
3+
ga8xHjAcBgNVBAoTFW1rY2VydC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BVLwBfcnkkSI1tF3IIFw0Lbjju6pDpi6RjQL1Q6TxjCS0a2LmZpnd6ofGH/X
20+
eCUo0cz04fygKSnhPJ/qG7qgh+rZuA9Nv7bkw0gFBiqGFAOm9e2P7p1RCU77tFPh
21+
mBNGRheiShtxdu47B9F39WwmOxNqPataM6XfGGhkJCI7qxF8VLngaLfyyi8zVd/u
22+
gAqw/6suXKY86kbcqOFJxQ+Z3IKMwvaetU83tRhYzn8bbO7ZyT0lEJ8OBStXY8sP
23+
Lxqa9c+BPBTd3TvjVyMo4OWGGkKi6kEswAKUnc8ebYDmj2YfQtesyD47q3uZ1fdU
24+
LaZETXaoqnuncKEPwez+jNDcU/qutrsXLxqcpzcZuMG5sKKb+qADkrqjwdA9QBG1
25+
rWadjJySkkRdiB+hvRxrT65aJ/QnHiesdGv2fXxW2Bk0PhW1MEUx5FBdxAx6q51o
26+
ZrYr3hbldC0IF0EsekX4H2e+Ul26p/1yBnp096rYd1Ia
27+
-----END CERTIFICATE-----

key.pem

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDWR/Yv5TyrHS4I
3+
QJzOSu21HpVYzZ+eClF5VOeyAwm+MVvKjgApoG9AOMqJAMF9qlWsAOGqRPiXRXE4
4+
Q2txXt125f+cwLK+K72QrGzgnNuNUYOU0nU42VWvrEf/1r7HT+qDgU/G0gS5ehFh
5+
SudGlzkWMEGnCeSjVci3QhZ6cqP318ezPYiWGVm/L8QUM878Gh8hNGV05W/djp8F
6+
JuMT69AL7MZj5FHIy9+aDWeXl7M8M2kwNCwKqXwOeXfA6gsfz6YkMg/d8599GB9+
7+
yJNQAC9EbfqW76TezD7AJUWJ8qdwliXBMVx1qNTvs5F5I592b37e1NWwhbU/Pd4a
8+
goGuBnXfAgMBAAECggEBAL3vfXXI4TTfoYzpENT+r6N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TCZy01D3MXAoGBAKuf56LxUjgyGK5LnXvN
25+
4aC50epwdHPwR6iCAA87p/NCrzTlN2gu/f4+OurFytkVmmAfgFYGZCkd0mSuu8rh
26+
8KT0A+VkDL/xUyAJ+0zwhddtf3vTdRKtbcMXXUfjlTrCmc+3vj952DLrkD5aCzFD
27+
nbCyQ8YrEUI9nU+JmrQWwsHR
28+
-----END PRIVATE KEY-----

package.json

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"license": "MIT",
2222
"engines": {
23-
"node": ">=14",
23+
"node": ">=16",
2424
"npm": ">=6.4.1"
2525
},
2626
"scripts": {
@@ -32,13 +32,18 @@
3232
"postinstall": "patch-package",
3333
"format": "prettier --write '**/*.{js,ts,jsx,tsx,mts,mjs,cjs,json,md}'",
3434
"test": "rimraf coverage && yarn clean:build && jest",
35+
"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",
36+
"test:e2e:server": "tests/e2e/scripts/start-local-server.sh",
37+
"test:e2e:run": "playwright test --config=tests/e2e/playwright.config.ts",
38+
"test:e2e:run:critical": "playwright test --config=tests/e2e/playwright.config.ts --project=critical",
3539
"prepare": "husky install",
3640
"yalc:publish": "scripts/yalc-publish.sh",
3741
"yalc:push": "scripts/yalc-push.sh",
3842
"ci:types": "yarn ci:types:runtime && yarn ci:types:tests",
3943
"ci:types:runtime": "lerna run --concurrency 4 --no-bail --parallel --scope \"@farfetch/*\" ci:types",
4044
"ci:types:tests": "tsc -p tsconfig.ci.tests.json",
4145
"ci:release": "scripts/release.sh",
46+
"ci:release:dry-run": "yarn ci:release --dry-run",
4247
"dev:link": "lerna run --concurrency 1 --stream --scope \"@farfetch/*\" dev:link",
4348
"dev:unlink": "lerna exec --concurrency 1 --stream --scope \"@farfetch/*\" 'cd dist && yarn unlink'",
4449
"release:git": "scripts/release-git.sh"
@@ -50,6 +55,7 @@
5055
"@babel/preset-typescript": "^7.13.0",
5156
"@commitlint/cli": "^17.0.1",
5257
"@commitlint/config-conventional": "^17.0.0",
58+
"@playwright/test": "^1.40.1",
5359
"@testing-library/jest-dom": "^5.11.4",
5460
"@testing-library/react": "^13.3.0",
5561
"@types/invariant": "^2.2.34",
@@ -61,11 +67,15 @@
6167
"@types/redux-mock-store": "^1.0.3",
6268
"@types/url-parse": "^1.4.3",
6369
"@types/uuid": "3.4.0",
70+
"@types/webpack-env": "^1.18.4",
6471
"@typescript-eslint/eslint-plugin": "5.54.0",
6572
"@typescript-eslint/parser": "5.53.0",
6673
"babel-eslint": "^10.1.0",
74+
"babel-loader": "^9.1.3",
6775
"browserslist-config-google": "^2.0.0",
6876
"core-js": "^3.6.5",
77+
"cross-env": "^7.0.3",
78+
"css-loader": "^6.9.1",
6979
"eslint": "^8.16.0",
7080
"eslint-config-prettier": "^8.5.0",
7181
"eslint-config-react-app": "^7.0.1",
@@ -81,21 +91,34 @@
8191
"faker": "^5.5.3",
8292
"fs-extra": "^10.1.0",
8393
"gitpkg": "^1.0.0-beta.4",
94+
"html-webpack-plugin": "^5.6.0",
8495
"husky": "^7.0.4",
8596
"jest": "^28.1.0",
8697
"jest-environment-jsdom": "^28.1.0",
8798
"jest-localstorage-mock": "^2.4.0",
8899
"jest-watch-typeahead": "^1.1.0",
89100
"lerna": "^5.0.0",
90101
"lint-staged": "^12.4.2",
102+
"local-web-server": "^5.3.0",
103+
"lodash-es": "^4.17.21",
91104
"msw": "^1.1.0",
92105
"patch-package": "^6.5.1",
106+
"postcss": "^8.4.33",
107+
"postcss-loader": "^8.0.0",
108+
"postcss-preset-env": "^9.3.0",
93109
"postinstall-postinstall": "^2.1.0",
94110
"prettier": "^2.6.2",
95111
"react": "^18.2.0",
96112
"react-dom": "^18.2.0",
113+
"react-router-dom": "^6.21.1",
114+
"redux-thunk": "2.4.2",
97115
"rimraf": "^3.0.2",
98-
"typescript": "5.0.2"
116+
"style-loader": "^3.3.4",
117+
"tailwindcss": "^3.4.1",
118+
"ts-node": "^10.9.2",
119+
"typescript": "5.0.2",
120+
"webpack": "^5.89.0",
121+
"webpack-cli": "^5.1.4"
99122
},
100123
"resolutions": {
101124
"@babel/core": "7.16.0",

packages/react/src/users/hooks/useUser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ function useUser(options: UseUserOptions = {}) {
136136
useEffect(() => {
137137
const updatedState = store.getState() as StoreState;
138138

139+
const updatedUser = getUser(updatedState);
140+
const updatedError = getUserError(updatedState);
141+
const updatedIsFetched =
142+
(!!updatedUser && !!updatedUser.id) || updatedError;
139143
const updatedIsLoading = isUserLoadingSelector(updatedState);
140144

141-
if (enableAutoFetch && !updatedIsLoading && !userError) {
145+
if (enableAutoFetch && !updatedIsFetched && !updatedIsLoading) {
142146
fetch(fetchConfig);
143147
}
144148
}, [

scripts/git-diff-ex.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Present git diff output not paginated and limited to the files
4+
# names and lines changed. Used with release script with the --dry-run
5+
# option.
6+
7+
git diff --color=always "$@" | awk '
8+
# 1. Match and print "--- a/" lines
9+
/^(\033\[(([0-9]{1,2};?){1,10})m)?(--- a\/)/ {
10+
print $0
11+
}
12+
13+
# 2. Match and then skip "--- a/" and "+++ b/" lines to avoid being printed again
14+
# in the next step.
15+
/^(\033\[(([0-9]{1,2};?){1,10})m)?(--- a\/|\+\+\+ b\/)/ {
16+
next
17+
}
18+
# 3. Now print the remaining "+" and "-" lines ONLY! Note: doing step 2 above first was required or
19+
# else those lines would have been matched by this matcher below too since they also begin with
20+
# the "+" and "-" symbols.
21+
/^(\033\[(([0-9]{1,2};?){1,10})m)?[-+]/ {
22+
print $0
23+
}
24+
'

0 commit comments

Comments
 (0)