Skip to content

Commit

Permalink
Merge pull request #695 from freeCodeCamp/main
Browse files Browse the repository at this point in the history
Create a new pull request by comparing changes across two branches
  • Loading branch information
GulajavaMinistudio authored Jul 18, 2024
2 parents f20be74 + 375333e commit c20ed82
Show file tree
Hide file tree
Showing 1,132 changed files with 95,359 additions and 1,528 deletions.
74 changes: 0 additions & 74 deletions .github/workflows/e2e-mobile.yml

This file was deleted.

191 changes: 191 additions & 0 deletions .github/workflows/e2e-with-new-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
name: CI - E2E - Containers
on:
workflow_dispatch:
workflow_run:
workflows: ['CI - Node.js']
types:
- completed
pull_request:
paths-ignore:
- 'docs/**'
branches:
- 'main'
- 'next-**'
- 'e2e-**'

jobs:
build-client:
name: Build Client
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout Source Files
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Checkout client-config
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: freeCodeCamp/client-config
path: client-config

- name: Setup pnpm
uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d #v3.0.0
with:
version: 9

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: ${{ matrix.node-version }}
cache: pnpm

- name: Set freeCodeCamp Environment Variables
run: cp sample.env .env

- name: Install and Build
run: |
pnpm install
pnpm run build
- name: Move serve.json to Public Folder
run: cp client-config/serve.json client/public/serve.json

# We tar them for performance reasons - uploading a lot of files is slow.
- name: Tar Files
run: tar -cf client-artifact.tar client/public

- name: Upload Client Artifact
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: client-artifact
path: client-artifact.tar

- name: Upload Webpack Stats
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: webpack-stats
path: client/public/stats.json

build-api:
name: Build Api (Container)
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout Source Files
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Create Image
run: |
docker build \
-t fcc-api \
-f docker/api/Dockerfile .
build-new-api:
name: Build New Api (Container)
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout Source Files
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Create Image
run: |
docker build \
-t fcc-new-api \
-f docker/new-api/Dockerfile .
- name: Save Image
run: docker save fcc-new-api > api-artifact.tar

- name: Upload Api Artifact
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: api-artifact
path: api-artifact.tar

playwright-run:
name: Run Playwright Tests (with new Api)
runs-on: ubuntu-22.04
needs: [build-client, build-new-api]
strategy:
fail-fast: false
matrix:
# Extend this to include firefox and webkit once chromium is working.
browsers: [chromium]
node-version: [20.x]

steps:
- name: Set Action Environment Variables
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Checkout Source Files
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4

- name: Unpack Client Artifact
run: |
tar -xf client-artifact/client-artifact.tar
rm client-artifact/client-artifact.tar
- name: Load Api Image
run: |
docker load < api-artifact/api-artifact.tar
rm api-artifact/api-artifact.tar
# Cypress calls some pnpm scripts, so we need to install pnpm.
- name: Setup pnpm
uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d #v3.0.0
with:
version: 9

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: pnpm install

- name: Set freeCodeCamp Environment Variables (needed by api)
run: |
cp sample.env .env
echo 'HOST=0.0.0.0' >> .env
- name: Install playwright dependencies
run: npx playwright install --with-deps

- name: Install and Build
run: |
pnpm install
pnpm run create:shared
pnpm run build:curriculum
- name: Start apps
run: |
docker compose up -d
pnpm run serve:client-ci &
sleep 10
- name: Seed Database with Certified User
run: pnpm run seed:certified-user

- name: Run playwright tests
run: npx playwright test --project=${{ matrix.browsers }} --grep-invert 'third-party-donation.spec.ts'

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report-${{ matrix.browsers }}
path: playwright/reporter
retention-days: 30
6 changes: 3 additions & 3 deletions .github/workflows/node.js-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
pnpm install
- name: Install Chrome for Puppeteer
run: pnpm dlx puppeteer browsers install chrome
run: pnpm -F=curriculum install-puppeteer

- name: Run Tests
run: pnpm test
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:
pnpm install
- name: Install Chrome for Puppeteer
run: pnpm dlx puppeteer browsers install chrome
run: pnpm -F=curriculum install-puppeteer

- name: Run Tests
run: pnpm test
Expand Down Expand Up @@ -259,7 +259,7 @@ jobs:
pnpm run build
- name: Install Chrome for Puppeteer
run: pnpm dlx puppeteer browsers install chrome
run: pnpm -F=curriculum install-puppeteer

- name: Run Tests
env:
Expand Down
30 changes: 23 additions & 7 deletions api/jest.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare global {

type Options = {
sendCSRFToken?: boolean;
} & Record<string, unknown>;
};

const requests = {
GET: (resource: string) => request(fastifyTestInstance?.server).get(resource),
Expand Down Expand Up @@ -41,16 +41,27 @@ export const getCookies = (setCookies: string[]): string => {
return setCookies.map(cookie => cookie.split(';')[0]).join('; ');
};

/**
* A wrapper around supertest that handles common setup for requests. Namely
* setting the Origin header, cookies and CSRF token.
*
* @param resource - The URL of the resource to be requested
* @param config - The configuration for the request
* @param config.method - The HTTP method to be used
* @param config.setCookies - The cookies to be set in the request
* @param options - Additional options for the request
* @param options.sendCSRFToken - Whether to send the CSRF token in the request (default: true)
* @returns The request object
*/
export function superRequest(
resource: string,
config: {
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
setCookies?: string[];
headers?: { referer: string };
},
options?: Options
): request.Test {
const { method, setCookies, headers } = config;
const { method, setCookies } = config;
const { sendCSRFToken = true } = options ?? {};

const req = requests[method](resource).set('Origin', ORIGIN);
Expand All @@ -59,17 +70,22 @@ export function superRequest(
void req.set('Cookie', getCookies(setCookies));
}

if (headers) {
void req.set('Referer', headers.referer);
}

const csrfToken = (setCookies && getCsrfToken(setCookies)) ?? '';
if (sendCSRFToken) {
void req.set('CSRF-Token', csrfToken);
}
return req;
}

/**
* Factory function for 'superRequest' allows for the creation of a concise
* request function with the desired method and setCookies baked in.
*
* @param config
* @param config.method - HTTP method
* @param config.setCookies - Cookies to be set in the request
* @returns A superRequest function with the desired method and setCookies
*/
export function createSuperRequest(config: {
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
setCookies?: string[];
Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"pino-pretty": "10.2.3",
"query-string": "7.1.3",
"rate-limit-mongo": "^2.3.2",
"stripe": "8.222.0",
"stripe": "16.0.0",
"validator": "13.11.0"
},
"description": "The freeCodeCamp.org open-source codebase and curriculum",
Expand Down
Loading

0 comments on commit c20ed82

Please sign in to comment.