Skip to content

Commit

Permalink
Add Tests (#252)
Browse files Browse the repository at this point in the history
* Add Testing

* Update CI Names
  • Loading branch information
timoclsn authored Oct 26, 2023
1 parent 137344c commit c9b53f5
Show file tree
Hide file tree
Showing 37 changed files with 2,390 additions and 149 deletions.
43 changes: 39 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [main]
jobs:
lint:
name: ESLint
name: Lint
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18
cache: 'pnpm'

- name: Install dependencies
Expand All @@ -32,7 +32,7 @@ jobs:
run: pnpm lint

typecheck:
name: TypeScript
name: Type check
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
Expand All @@ -49,7 +49,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18
cache: 'pnpm'

- name: Install dependencies
Expand All @@ -65,3 +65,38 @@ jobs:

- name: Type check
run: pnpm typecheck

test:
name: Test
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
with:
version: 8

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Generate prisma type
working-directory: ./packages/database
run: pnpm db:generate

- name: Generate content types
working-directory: ./apps/resources
run: pnpm content

- name: Test
run: pnpm test
2 changes: 1 addition & 1 deletion apps/resources/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Footer } from '../components/Footer/Footer';
import { Header } from '../components/Header/Header';
import { description, title } from '../lib/metadata';
import '../lib/polyfills';
import { getBaseUrl } from '../lib/utils';
import { getBaseUrl } from '../lib/utils/utils';
import '../styles/globals.css';

const sans = DM_Sans({
Expand Down
2 changes: 1 addition & 1 deletion apps/resources/app/resource-og-image/route.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ImageResponse } from 'next/server';
import { ContentType } from '../../lib/resources';
import { formatType, getHostname } from '../../lib/utils';
import { formatType, getHostname } from '../../lib/utils/utils';

export const runtime = 'edge';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/app/resources/Resources/Resources.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Heading, Text } from 'design-system';
import { SearchParams } from 'lib/types';
import { z } from 'zod';
import { formateDate } from '../../../lib/utils';
import { formateDate } from '../../../lib/utils/utils';
import { ResourcesTable } from './ResourcesTable/ResourcesTable';

export type ReseourcesFilter = z.infer<typeof reseourcesFilterSchema>;
Expand Down
2 changes: 1 addition & 1 deletion apps/resources/app/resources/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RelatedResources } from '../../../components/RelatedResources/RelatedRe
import { ResourceCard } from '../../../components/ResourceCard/ResourceCard';
import { getResourceCached } from '../../../lib/cache';
import { createGenerateMetadata } from '../../../lib/metadata';
import { getBaseUrl, parseResourceSlug } from '../../../lib/utils';
import { getBaseUrl, parseResourceSlug } from '../../../lib/utils/utils';

export const generateMetadata = createGenerateMetadata(async ({ params }) => {
const { slug } = params;
Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Text,
Tooltip,
} from 'design-system';
import { isExternalUrl } from 'lib/utils';
import { isExternalUrl } from 'lib/utils/utils';
import { ExternalLink, LucideIcon, StickyNote, Users2 } from 'lucide-react';
import { ReactNode } from 'react';
import { ContentType } from '../../lib/resources';
Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/Card/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Tag, Tooltip } from 'design-system';
import { Check, Copy } from 'lucide-react';
import { useState } from 'react';
import { wait } from '../../lib/utils';
import { wait } from '../../lib/utils/utils';
import { track } from 'lib/tracking';

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/Card/ShareButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { track } from 'lib/tracking';
import { Check, Share } from 'lucide-react';
import { useState } from 'react';
import { ContentType } from '../../lib/resources';
import { getBaseUrl, wait } from '../../lib/utils';
import { getBaseUrl, wait } from '../../lib/utils/utils';

interface Props {
title: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ErrorBoundary/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { track } from 'lib/tracking';
import { getErrorMessage } from 'lib/utils';
import { getErrorMessage } from 'lib/utils/utils';
import { Component, ErrorInfo, ReactNode } from 'react';

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/Newsletter/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { createAction } from 'lib/serverActions/create';
import { z } from 'zod';
import { getErrorMessage } from '../../lib/utils';
import { getErrorMessage } from '../../lib/utils/utils';
import { newsletterFormSchema } from './schemas';

const envSchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/AgencyCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tag } from 'lucide-react';
import { Agency } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/ArticleCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BookOpen, CalendarDays, Clock3, Tag } from 'lucide-react';
import { Article } from '../../lib/resources';
import { formateDate, getHostname } from '../../lib/utils';
import { formateDate, getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { thoughtleadersList, topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/BookCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Tag,
} from 'lucide-react';
import { Book } from '../../lib/resources';
import { formateDate, getHostname } from '../../lib/utils';
import { formateDate, getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { thoughtleadersList, topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/CommunityCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tag } from 'lucide-react';
import { Community } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/CourseCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tag } from 'lucide-react';
import { Course } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/DirectoryCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tag } from 'lucide-react';
import { Directory } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/ExampleCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tag } from 'lucide-react';
import { Example } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/MagazineCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tag } from 'lucide-react';
import { Magazine } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/NewsletterCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BookOpen, Tag } from 'lucide-react';
import { Newsletter } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { thoughtleadersList, topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/PaperCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BookOpen, CalendarDays, Newspaper, Tag } from 'lucide-react';
import { Paper } from '../../lib/resources';
import { formateDate, getHostname } from '../../lib/utils';
import { formateDate, getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { thoughtleadersList, topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/PodcastCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Smile, Tag } from 'lucide-react';
import { Podcast } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { thoughtleadersList, topicsList } from '../utils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CalendarDays, Clock3, Mic, Smile, Tag } from 'lucide-react';
import { PodcastEpisode } from '../../lib/resources';
import { formateDate, getHostname } from '../../lib/utils';
import { formateDate, getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { thoughtleadersList, topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/ReportCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BookOpen, CalendarDays, Tag } from 'lucide-react';
import { Report } from '../../lib/resources';
import { formateDate, getHostname } from '../../lib/utils';
import { formateDate, getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { thoughtleadersList, topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/SlideCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BookOpen, CalendarDays, Tag } from 'lucide-react';
import { Slide } from '../../lib/resources';
import { formateDate, getHostname } from '../../lib/utils';
import { formateDate, getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { thoughtleadersList, topicsList } from '../utils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AtSign, Tag } from 'lucide-react';
import { SocialMediaProfile } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { topicsList } from '../utils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Briefcase, Tag } from 'lucide-react';
import { Thoughtleader } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/ToolCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tag } from 'lucide-react';
import { Tool } from '../../lib/resources';
import { getHostname } from '../../lib/utils';
import { getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { topicsList } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion apps/resources/components/ResourceCards/VideoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CalendarDays, Clock3, Tag, VideoIcon } from 'lucide-react';
import { Video } from '../../lib/resources';
import { formateDate, getHostname } from '../../lib/utils';
import { formateDate, getHostname } from '../../lib/utils/utils';
import { Card } from '../Card/Card';
import { thoughtleadersList, topicsList } from '../utils';

Expand Down
18 changes: 18 additions & 0 deletions apps/resources/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import nextJest from 'next/jest.js';

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
/** @type {import('jest').Config} */
const config = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],

testEnvironment: 'jest-environment-jsdom',
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config);
2 changes: 1 addition & 1 deletion apps/resources/lib/serverActions/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getErrorMessage,
isNextNotFoundError,
isNextRedirectError,
} from '../utils';
} from '../utils/utils';
import { InferInputType, ServerAction } from './server';

interface State<TResponse extends any> {
Expand Down
2 changes: 1 addition & 1 deletion apps/resources/lib/serverActions/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getErrorMessage,
isNextNotFoundError,
isNextRedirectError,
} from '../utils';
} from '../utils/utils';

type MaybePromise<T> = Promise<T> | T;

Expand Down
Loading

1 comment on commit c9b53f5

@vercel
Copy link

@vercel vercel bot commented on c9b53f5 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.