Skip to content

Commit 0f1d6c8

Browse files
Merge pull request #215 from microsoft/dev
fix: merging dev changes to main branch
2 parents 5e7bd4f + a0b79cd commit 0f1d6c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+9486
-1614
lines changed
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
name: Build and Push Docker Image
22

33
on:
4+
push:
5+
branches: [main, dev, demo]
46
pull_request:
5-
types: [closed]
6-
branches:
7-
- main
8-
- dev
9-
- demo
10-
workflow_dispatch: # Add this line to enable manual triggering
7+
branches: [main, dev, demo]
8+
types:
9+
- opened
10+
- ready_for_review
11+
- reopened
12+
- synchronize
13+
merge_group:
1114

1215
jobs:
1316
build-and-push:
14-
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
1517
runs-on: ubuntu-latest
1618

1719
steps:
@@ -37,26 +39,24 @@ jobs:
3739
username: ${{ secrets.ACR_DEV_USERNAME }}
3840
password: ${{ secrets.ACR_DEV_PASSWORD }}
3941

40-
- name: Set Docker image tag
41-
id: docker_tag
42-
run: |
43-
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
44-
echo "TAG=latest" >> $GITHUB_ENV
45-
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
46-
echo "TAG=dev" >> $GITHUB_ENV
47-
elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then
48-
echo "TAG=demo" >> $GITHUB_ENV
49-
fi
50-
51-
- name: Build and push Docker image
52-
if: ${{ github.ref_name == 'main' }}
53-
run: |
54-
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/webapp:${{ env.TAG }} -f WebApp.Dockerfile .
55-
docker push ${{ secrets.ACR_LOGIN_SERVER }}/webapp:${{ env.TAG }}
42+
- name: Get current date
43+
id: date
44+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
5645

57-
- name: Build and push Docker image (Dev/Demo)
58-
if: ${{ github.ref_name == 'dev' || github.ref_name == 'demo' }}
59-
run: |
60-
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/webapp:latest -f WebApp.Dockerfile .
61-
docker push ${{ secrets.ACR_LOGIN_SERVER }}/webapp:latest
62-
46+
- name: Get registry
47+
id: registry
48+
run: echo "registry=${{ github.ref_name == 'main' && secrets.ACR_LOGIN_SERVER || secrets.ACR_DEV_LOGIN_SERVER }}" >> $GITHUB_OUTPUT
49+
50+
- name: Determine Tag Name Based on Branch
51+
id: determine_tag
52+
run: echo "tagname=${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || github.head_ref || 'default' }}" >> $GITHUB_OUTPUT
53+
54+
- name: Build Docker Image and optionally push
55+
uses: docker/build-push-action@v6
56+
with:
57+
context: .
58+
file: WebApp.Dockerfile
59+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' }}
60+
tags: |
61+
${{ steps.registry.outputs.registry }}/webapp:${{ steps.determine_tag.outputs.tagname }}
62+
${{ steps.registry.outputs.registry }}/webapp:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ __pycache__/
77
static
88
scripts/config.json
99
venv
10-
myenv
10+
myenv
11+
frontend/coverage

WebApp.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ USER node
77
RUN npm ci
88
COPY --chown=node:node ./frontend/ ./frontend
99
WORKDIR /home/node/app/frontend
10+
RUN npm install --save-dev @types/node @types/jest
1011
RUN NODE_OPTIONS=--max_old_space_size=8192 npm run build
1112

1213
FROM python:3.11-alpine
@@ -27,4 +28,4 @@ COPY --from=frontend /home/node/app/static /usr/src/app/static/
2728
WORKDIR /usr/src/app
2829
EXPOSE 80
2930

30-
CMD ["gunicorn" , "-b", "0.0.0.0:80", "app:app"]
31+
CMD ["gunicorn" , "-b", "0.0.0.0:80", "app:app"]

frontend/__mocks__/dompurify.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const DOMPurify = {
2+
sanitize: jest.fn((input: string) => input), // Mock implementation that returns the input
3+
};
4+
5+
export default DOMPurify; // Use default export

frontend/__mocks__/fileMock.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// __mocks__/fileMock.ts
2+
const fileMock = 'test-file-stub';
3+
4+
export default fileMock;

frontend/__mocks__/mockAPIData.ts

Lines changed: 164 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// __mocks__/react-markdown.tsx
2+
3+
import React from 'react';
4+
5+
// Mock implementation of react-markdown
6+
const mockNode = {
7+
children: [{ value: 'console.log("Test Code");' }]
8+
};
9+
const mockProps = { className: 'language-javascript' };
10+
11+
const ReactMarkdown: React.FC<{ children: React.ReactNode , components: any }> = ({ children,components }) => {
12+
return <div data-testid="reactMockDown">
13+
{/* {components && components.code({ node: mockNode, ...mockProps })} */}
14+
{children}</div>; // Simply render the children
15+
};
16+
17+
export default ReactMarkdown;

frontend/jest.config.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,55 @@ import type { Config } from '@jest/types'
22

33
const config: Config.InitialOptions = {
44
verbose: true,
5+
6+
preset: 'ts-jest',
7+
//testEnvironment: 'jsdom', // For React DOM testing
8+
testEnvironment: 'jest-environment-jsdom',
9+
testEnvironmentOptions: {
10+
customExportConditions: ['']
11+
},
12+
moduleNameMapper: {
13+
'\\.(css|less|scss)$': 'identity-obj-proxy', // For mocking static file imports
14+
'^react-markdown$': '<rootDir>/__mocks__/react-markdown.tsx',
15+
'^dompurify$': '<rootDir>/__mocks__/dompurify.js', // Point to the mock
16+
'\\.(jpg|jpeg|png|gif|svg)$': '<rootDir>/__mocks__/fileMock.ts',
17+
18+
},
19+
setupFilesAfterEnv: ['<rootDir>/src/test/setupTests.ts'], // For setting up testing environment like jest-dom
520
transform: {
6-
'^.+\\.tsx?$': 'ts-jest'
21+
'^.+\\.ts(x)?$': 'ts-jest', // For TypeScript files
22+
'^.+\\.js$': 'babel-jest', // For JavaScript files if you have Babel
723
},
8-
setupFilesAfterEnv: ['<rootDir>/polyfills.js']
24+
25+
setupFiles: ['<rootDir>/jest.polyfills.js'],
26+
collectCoverage: true,
27+
//collectCoverageFrom: ['src/**/*.{ts,tsx}'], // Adjust the path as needed
28+
//coverageReporters: ['json', 'lcov', 'text', 'clover'],
29+
30+
collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}'],
31+
coverageThreshold: {
32+
global: {
33+
branches: 80,
34+
functions: 80,
35+
lines: 80,
36+
statements: 80,
37+
},
38+
},
39+
40+
coveragePathIgnorePatterns: [
41+
'<rootDir>/node_modules/', // Ignore node_modules
42+
'<rootDir>/__mocks__/', // Ignore mocks
43+
'<rootDir>/src/state/',
44+
'<rootDir>/src/api/',
45+
'<rootDir>/src/mocks/',
46+
//'<rootDir>/src/test/',
47+
'<rootDir>/src/components/QuestionInput/index.ts',
48+
'<rootDir>/src/components/Answer/index.ts',
49+
'<rootDir>/src/pages/NoPage.tsx',
50+
'<rootDir>/src/index.tsx',
51+
'<rootDir>/src/vite-env.d.ts',
52+
'<rootDir>/src/helpers/'
53+
],
954
}
1055

1156
export default config

frontend/jest.polyfills.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @note The block below contains polyfills for Node.js globals
3+
* required for Jest to function when running JSDOM tests.
4+
* These HAVE to be require's and HAVE to be in this exact
5+
* order, since "undici" depends on the "TextEncoder" global API.
6+
*
7+
* Consider migrating to a more modern test runner if
8+
* you don't want to deal with this.
9+
*/
10+
11+
const { TextDecoder, TextEncoder } = require('node:util')
12+
13+
Object.defineProperties(globalThis, {
14+
TextDecoder: { value: TextDecoder },
15+
TextEncoder: { value: TextEncoder },
16+
})
17+
18+
const { Blob } = require('node:buffer')
19+
const { fetch, Headers, FormData, Request, Response } = require('undici')
20+
21+
Object.defineProperties(globalThis, {
22+
fetch: { value: fetch, writable: true },
23+
Blob: { value: Blob },
24+
Headers: { value: Headers },
25+
FormData: { value: FormData },
26+
Request: { value: Request },
27+
Response: { value: Response },
28+
})

0 commit comments

Comments
 (0)