Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: ProjMatch Node.js CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
38 changes: 38 additions & 0 deletions .github/workflows/test-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test Deployment

on:
push:
branches: [ main ]

jobs:

deploy:

name: Testing
runs-on: ubuntu-latest
env:
IMAGE_NAME: gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_APP_NAME }}
steps:

- name: Login
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_EMAIL }}
service_account_key: ${{ secrets.GCP_CREDENTIALS }}

- name: Configure Project
run: gcloud config set project ${{ secrets.GCP_PROJECT_ID }}

- name: Configure Docker
run: gcloud auth configure-docker --quiet

- name: Checkout repository
uses: actions/checkout@v2

- name: Inject .env File
run: |
echo "${{ secrets.BACKEND_ENV }}" >> .env

- name: Build Docker image
run: docker build . -t ${{ secrets.GCR_REPO }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# dependencies
/node_modules
package-lock.json
./package-lock.json
/.pnp
.pnp.js

Expand Down
15 changes: 15 additions & 0 deletions __tests__/fixtures.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { UserProvider } from '@auth0/nextjs-auth0/client';

export const mockUser = {
email: 'foo@example.com',
email_verified: true,
name: 'foo',
nickname: 'foo',
picture: 'foo.jpg',
sub: '1',
updated_at: null
};

export const withUserProvider = ({ user, profileUrl } = {}) => {
return props => <UserProvider {...props} user={user} profileUrl={profileUrl} />;
};
12 changes: 12 additions & 0 deletions __tests__/pages/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Home from "@/pages/Home";
import "@testing-library/jest-dom"
import { fireEvent, render, screen } from "@testing-library/react"

describe("Home Page", () => {
it("checks for Side Nav Bar", async () => {
render(<Home />);

expect(screen.getByTestId('navbar')).toBeInTheDocument()
// expect(screen.getAllByTestId('project')).toBeInTheDocument()
})
})
19 changes: 19 additions & 0 deletions __tests__/pages/landing.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Landing from "@/pages/Landing/Landing";

import "@testing-library/jest-dom"
import { fireEvent, render, screen } from "@testing-library/react";
import { useRouter } from "next/router";

describe("Landing Page", () => {
it("checks if login works", () => {
useRouter.mockReturnValue({ query: {} })
render(<Landing />)
expect(useRouter).toHaveBeenCalled()

const loginElement = screen.getByText("Log In")
expect(loginElement).toBeInTheDocument()

expect(screen.getByTestId("landing-anim")).toBeInTheDocument()
expect(screen.getByTestId("landing-titlebar")).toBeInTheDocument()
})
})
19 changes: 19 additions & 0 deletions __tests__/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '@testing-library/jest-dom/extend-expect';

afterEach(() => {
jest.clearAllMocks();
jest.restoreAllMocks();
jest.resetModules();
});

jest.mock('next/router', () => ({
userRouter: jest.fn()
}));

jest.mock('@auth0/nextjs-auth0', () => {
return {
getAccessToken: () => 'access_token',
withApiAuthRequired: handler => handler,
withPageAuthRequired: page => () => page()
};
});
21 changes: 21 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const nextJest = require('next/jest')

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})

// Add any custom config to be passed to Jest
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
'^@/components/(.*)$': '<rootDir>/src/components/$1',

'^@/pages/(.*)$': '<rootDir>/src/pages/$1',
},
testEnvironment: 'jest-environment-jsdom',
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
9 changes: 9 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js`

// Used for __tests__/testing-library.js
// Learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect'

module.exports = {
setupTestFrameworkScriptFile: '/__tests_/setup.js'
};
Loading