Skip to content

Commit 0d27a2a

Browse files
committed
Playwright tests
1 parent 4ab0acf commit 0d27a2a

18 files changed

+345
-16
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ dist/
1313
.github/
1414
Dockerfile
1515
*.md
16+
azure-deploy/
17+
infra/
18+
playwright-report/
19+
test-results/
20+
test-results-docker/

.github/workflows/playwright.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Install Playwright Browsers
19+
run: npx playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: npm test
22+
- uses: actions/upload-artifact@v4
23+
if: ${{ !cancelled() }}
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ pnpm-debug.log*
2525

2626
api/public
2727
test.http
28+
/test-results/
29+
/test-results-docker/
30+
/playwright-report/
31+
/blob-report/
32+
/playwright/.cache/

api.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ COPY --chown=1000:1000 api/ .
2929
# Copy the built Vue.js app from the previous stage
3030
COPY --chown=1000:1000 --from=build-stage /app/dist /api/public
3131
COPY --chown=1000:1000 --from=build-stage /app/dist/assets/app-config.js /api/app-config.template.js
32+
COPY --chown=1000:1000 --from=build-stage /app/mock-data /mock-data
3233

3334
# Expose the port your API will run on
3435
EXPOSE 3000

api/server.mjs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,47 @@ const authMiddleware = (req, res, next) => {
4545
next();
4646
};
4747

48+
const simpleRequestLogger = (proxyServer, options) => {
49+
proxyServer.on('proxyReq', (proxyReq, req, res) => {
50+
console.log(`[HPM] [${req.method}] ${req.url}`); // outputs: [HPM] GET /users
51+
});
52+
}
53+
54+
const mockResponses = (proxyServer, options) => {
55+
proxyServer.on('proxyReq', (proxyReq, req, res) => {
56+
// Do not send to GitHub when mocked
57+
switch (req.path) {
58+
case "/orgs/octodemo/copilot/usage":
59+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/organization_response_sample.json'), 'utf8')));
60+
break;
61+
case "/orgs/octodemo/copilot/billing/seats":
62+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/organization_response_sample_seats.json'), 'utf8')));
63+
break;
64+
case "/enterprises/octodemo/copilot/usage":
65+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/enterprise_response_sample.json'), 'utf8')));
66+
break;
67+
case "/enterprises/octodemo/copilot/billing/seats":
68+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/enterprise_response_sample_seats.json'), 'utf8')));
69+
break;
70+
default:
71+
res.status(418).send('🫖Request Not Mocked');
72+
}
73+
});
74+
}
75+
76+
const plugins = [simpleRequestLogger];
77+
78+
if (process.env.APP_MOCKED_DATA === 'true') {
79+
plugins.push(mockResponses);
80+
}
81+
4882
const githubProxy = createProxyMiddleware({
4983
target: 'https://api.github.com',
5084
changeOrigin: true,
5185
pathRewrite: {
5286
'^/api/github': '', // Rewrite URL path (remove /api/github)
5387
},
54-
onProxyReq: (proxyReq, req) => {
55-
console.log('Proxying request to GitHub API:', req.url);
56-
// Optional: Modify the proxy request here (e.g., headers)
57-
},
88+
plugins
5889
});
5990

6091
// Apply middlewares to the app

docker-compose.ent.override.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '3.8'
2+
3+
services:
4+
api:
5+
environment:
6+
# Determines the scope of the API calls.
7+
# Can be 'enterprise' or 'organization' to target API calls to an enterprise or an organization respectively.
8+
- VUE_APP_SCOPE=enterprise
9+
# Determines the enterprise or organization name to target API calls.
10+
- VUE_APP_GITHUB_ORG=
11+
- VUE_APP_GITHUB_ENT=octodemo
12+
13+
playwright:
14+
command: npx playwright test --output test-results-docker --grep @ent

docker-compose.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: '3.8'
2+
3+
services:
4+
api:
5+
build:
6+
context: .
7+
dockerfile: api.Dockerfile
8+
ports:
9+
- "3000:3000"
10+
environment:
11+
- NODE_ENV=production
12+
# Determines if mocked data should be used instead of making API calls.
13+
- VUE_APP_MOCKED_DATA=false
14+
# Mock requests in the API not UI
15+
- APP_MOCKED_DATA=true
16+
# Determines the scope of the API calls.
17+
# Can be 'enterprise' or 'organization' to target API calls to an enterprise or an organization respectively.
18+
- VUE_APP_SCOPE=organization
19+
# Determines the enterprise or organization name to target API calls.
20+
- VUE_APP_GITHUB_ORG=octodemo
21+
- VUE_APP_GITHUB_ENT=
22+
- VUE_APP_GITHUB_TOKEN=dummy
23+
# GitHub Api Url
24+
# for proxy api - set to /api/github defaults to https://api.github.com
25+
- VUE_APP_GITHUB_API=/api/github
26+
- SESSION_SECRET=secret
27+
28+
playwright:
29+
image: mcr.microsoft.com/playwright:v1.49.1
30+
environment:
31+
- TEST_URL=http://api:3000
32+
- CI=true
33+
volumes:
34+
- .:/workspace
35+
working_dir: /workspace
36+
command: npx playwright test --output test-results-docker --grep @org
37+
ipc: host
38+
profiles: [tests]
39+
depends_on:
40+
- api

0 commit comments

Comments
 (0)