Skip to content

Commit d4f2539

Browse files
authored
chore: migrate to vite
2 parents 5c48789 + 6c360e5 commit d4f2539

28 files changed

+2330
-7097
lines changed

.github/workflows/cypress.yml

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,54 @@
1-
name: Cypress
1+
name: Cypress UI tests
22

33
on:
4-
merge_group:
54
push:
6-
branches-ignore:
7-
- 'release-please-**'
85

96
jobs:
107
cypress-run:
11-
concurrency:
12-
group: cypress-${{ github.head_ref || github.ref }}
8+
concurrency: cypress-${{ github.head_ref || github.ref }}
139
runs-on: ubuntu-latest
1410
steps:
15-
- name: checkout
16-
uses: actions/checkout@v3
17-
18-
- name: set up node
19-
uses: actions/setup-node@v3
20-
with:
21-
node-version: '18'
11+
- name: Checkout
12+
uses: actions/checkout@v4
2213

2314
- name: Yarn Install and Cache
2415
uses: graasp/graasp-deploy/.github/actions/yarn-install-and-cache@v1
2516
with:
2617
cypress: true
2718

28-
- name: cypress run
29-
uses: cypress-io/github-action@v4
19+
- name: Build App
20+
run: yarn build:test
21+
shell: bash
22+
env:
23+
VITE_PORT: 3000
24+
VITE_API_HOST: http://localhost:3636
25+
VITE_GRAASP_APP_KEY: id-1234567890
26+
VITE_ENABLE_MOCK_API: true
27+
VITE_VERSION: cypress-tests
28+
29+
- name: Cypress Run
30+
uses: cypress-io/github-action@v5
3031
env:
31-
PORT: 3000
32-
REACT_APP_API_HOST: http://localhost:3636
33-
REACT_APP_GRAASP_APP_KEY: id-1234567890
34-
REACT_APP_ENABLE_MOCK_API: true
32+
VITE_PORT: 3000
33+
VITE_API_HOST: http://localhost:3636
34+
VITE_GRAASP_APP_KEY: id-1234567890
35+
VITE_ENABLE_MOCK_API: true
36+
VITE_VERSION: cypress-tests
3537
with:
36-
wait-on: http://localhost:3000
37-
wait-on-timeout: 180
3838
install: false
39-
build: yarn build
4039
config: baseUrl=http://localhost:3000
41-
start: yarn start:ci
40+
start: yarn preview:test
4241
browser: chrome
4342
quiet: true
4443
# point to new cypress@10 config file
4544
config-file: cypress.config.ts
4645

47-
# component tests are not running ok in the CI
48-
# - name: Run Component tests 🧪
49-
# uses: cypress-io/github-action@v4
50-
# with:
51-
# # we have already installed everything
52-
# install: false
53-
# # to run component tests we need to use "component: true"
54-
# component: true
55-
56-
# after the test run completes
57-
# store videos and any screenshots
58-
# NOTE: screenshots will be generated only if E2E test failed
59-
# thus we store screenshots only on failures
60-
# Alternative: create and commit an empty cypress/screenshots folder
61-
# to always have something to upload
62-
- uses: actions/upload-artifact@v3
46+
- uses: actions/upload-artifact@v4
6347
if: failure()
6448
with:
6549
name: cypress-screenshots
6650
path: cypress/screenshots
6751

68-
- uses: actions/upload-artifact@v3
69-
if: failure()
70-
with:
71-
name: cypress-videos
72-
path: cypress/videos
73-
7452
- name: coverage report
7553
run: npx nyc report --reporter=text-summary
7654

@@ -88,4 +66,4 @@ jobs:
8866
GITHUB_TOKEN: ${{ github.token }}
8967
REPO_PATH: ${{ github.repository }}
9068
COMMIT_SHA: ${{ github.sha }}
91-
RUN_ID: ${{ github.run_id }}
69+
RUN_ID: ${{ github.run_id }}

.github/workflows/deploy-dev.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ jobs:
2525
- name: Yarn build
2626
# Set environment variables required to perform the build. These are only available to this step
2727
env:
28-
REACT_APP_API_HOST: ${{ secrets.REACT_APP_API_HOST_DEV }}
29-
REACT_APP_GRAASP_APP_KEY: ${{ secrets.APP_KEY }}
30-
REACT_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
28+
VITE_API_HOST: ${{ vars.VITE_API_HOST }}
29+
VITE_GRAASP_APP_KEY: ${{ secrets.VITE_GRAASP_APP_KEY }}
30+
VITE_SENTRY_ENV: development
31+
VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
32+
VITE_VERSION: ${{ github.sha }}
3133
run: yarn build
3234
shell: bash
3335

.github/workflows/deploy-prod.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ jobs:
2424
- name: Yarn build
2525
# Set environment variables required to perform the build. These are only available to this step
2626
env:
27-
REACT_APP_API_HOST: ${{ secrets.REACT_APP_API_HOST_PROD }}
28-
REACT_APP_GRAASP_APP_KEY: ${{ secrets.APP_KEY }}
29-
REACT_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
27+
VITE_API_HOST: ${{ vars.VITE_API_HOST }}
28+
VITE_GRAASP_APP_KEY: ${{ secrets.VITE_GRAASP_APP_KEY }}
29+
VITE_SENTRY_ENV: production
30+
VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
31+
VITE_VERSION: ${{ github.event.client_payload.tag }}
3032
run: yarn build
3133
shell: bash
3234

.github/workflows/deploy-stage.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ jobs:
2424
- name: Yarn build
2525
# Set environment variables required to perform the build. These are only available to this step
2626
env:
27-
REACT_APP_API_HOST: ${{ secrets.REACT_APP_API_HOST_STAGE }}
28-
REACT_APP_GRAASP_APP_KEY: ${{ secrets.APP_KEY }}
29-
REACT_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
27+
VITE_API_HOST: ${{ vars.VITE_API_HOST }}
28+
VITE_GRAASP_APP_KEY: ${{ secrets.VITE_GRAASP_APP_KEY }}
29+
VITE_SENTRY_ENV: staging
30+
VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
31+
VITE_VERSION: ${{ github.event.client_payload.tag }}
3032
run: yarn build
3133
shell: bash
3234

.husky/pre-commit

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55

66
. "$(dirname "$0")/_/husky.sh"
77

8-
yarn pretty-quick --staged && yarn lint
8+
yarn type-check
9+
yarn prettier:check
10+
yarn lint

.husky/pre-push

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55

66
. "$(dirname "$0")/_/husky.sh"
77

8-
yarn lint && yarn build
8+
yarn type-check
9+
yarn lint
10+
yarn build

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
Create a env.development file with:
55
66
PORT=3005
7-
REACT_APP_GRAASP_APP_KEY=<app KEY>
8-
REACT_APP_ENABLE_MOCK_API=true
9-
REACT_APP_GRAASP_DOMAIN=localhost
10-
REACT_APP_API_HOST=<request address for the backend>
7+
VITE_GRAASP_APP_KEY=<app KEY>
8+
VITE_ENABLE_MOCK_API=true
9+
VITE_API_HOST=<request address for the backend>
1110
```
1211

1312
![GitHub package.json version](https://img.shields.io/github/package-json/v/graasp/graasp-app-text-analysis?color=green&style=flat-square)

cypress.config.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { defineConfig } from 'cypress';
2+
import vitePreprocessor from 'cypress-vite';
3+
4+
import setupCoverage from '@cypress/code-coverage/task';
25

36
export default defineConfig({
47
video: false,
8+
retries: {
9+
runMode: 2,
10+
},
11+
chromeWebSecurity: false,
512
e2e: {
613
setupNodeEvents(on, config) {
7-
return require('./cypress/plugins/index')(on, config);
14+
// cypress-vite allow to using vite specific features
15+
// like plugins and virtual imports, import.meta, etc. in e2e tests
16+
on('file:preprocessor', vitePreprocessor());
17+
setupCoverage(on, config);
18+
return config;
819
},
9-
baseUrl: `http://localhost:${process.env.PORT || 3000}`,
20+
baseUrl: `http://localhost:${process.env.VITE_PORT || 3335}`,
1021
},
1122
});

cypress/plugins/index.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

cypress/support/commands.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/// <reference types="../../src/interfaces/window" />
2+
import { PermissionLevel } from '@graasp/sdk';
3+
24
import '@testing-library/cypress/add-commands';
35

46
import { CURRENT_MEMBER, MEMBERS, MOCK_SERVER_ITEM } from '../../src/data/db';
@@ -48,7 +50,9 @@ Cypress.Commands.add(
4850
win.appContext = {
4951
memberId: currentMember.id,
5052
itemId: MOCK_SERVER_ITEM.id,
51-
apiHost: Cypress.env('REACT_APP_API_HOST') || MOCK_SERVER_API_HOST,
53+
apiHost: Cypress.env('VITE_API_HOST') || MOCK_SERVER_API_HOST,
54+
context: 'standalone',
55+
permission: PermissionLevel.Read,
5256
...appContext,
5357
};
5458
});

cypress/tsconfig.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
2+
"extends": "../tsconfig.json",
23
"compilerOptions": {
34
"target": "es5",
4-
"lib": ["es5", "dom"],
5-
"types": ["cypress", "node"],
6-
"esModuleInterop": true
5+
"lib": ["es5", "dom", "ES2021.String"],
6+
"types": ["cypress", "node", "vite/client"],
7+
"esModuleInterop": true,
8+
"strictNullChecks": false,
9+
"strict": true,
10+
"sourceMap": false
711
},
8-
"include": ["**/*.ts", "../src/data/members.ts"]
12+
"include": ["**/*.ts", "../src/data/members.ts", "cypress.d.ts"],
13+
"exclude": ["coverage", ".nyc_output"]
914
}

docs/Setup_Intructions.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,9 @@ jobs:
359359
- name: cypress run
360360
uses: cypress-io/github-action@v2
361361
env:
362-
REACT_APP_API_HOST: http://localhost:3636
363-
REACT_APP_GRAASP_DOMAIN: localhost
364-
REACT_APP_GRAASP_APP_KEY: id-1234567890
365-
REACT_APP_ENABLE_MOCK_API: true
362+
VITE_API_HOST: http://localhost:3636
363+
VITE_GRAASP_APP_KEY: id-1234567890
364+
VITE_ENABLE_MOCK_API: true
366365
NODE_ENV: test
367366
with:
368367
install: false

public/index.html renamed to index.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
5+
<link rel="icon" href="/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="theme-color" content="#000000" />
88
<!-- todo: change this to appropriate values -->
99
<meta
1010
name="Text Analysis"
1111
content="A Graasp App created using a template."
1212
/>
13-
<meta name="version-info" content="%REACT_APP_VERSION%" />
13+
<meta name="version-info" content="%VITE_VERSION%" />
1414
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
1515
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
1616
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
@@ -22,13 +22,13 @@
2222
manifest.json provides metadata used when your web app is installed on a
2323
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
2424
-->
25-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
25+
<link rel="manifest" href="/manifest.json" />
2626
<!--
27-
Notice the use of %PUBLIC_URL% in the tags above.
27+
Notice the use of in the tags above.
2828
It will be replaced with the URL of the `public` folder during the build.
2929
Only files inside the `public` folder can be referenced from the HTML.
3030
31-
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
31+
Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
3232
work correctly both with client-side routing and a non-root public URL.
3333
Learn how to configure a non-root public URL by running `npm run build`.
3434
-->
@@ -48,5 +48,6 @@
4848
To begin the development, run `npm start` or `yarn start`.
4949
To create a production bundle, use `npm run build` or `yarn build`.
5050
-->
51+
<script type="module" src="src/index.tsx"></script>
5152
</body>
5253
</html>

0 commit comments

Comments
 (0)