Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve vitest config and add GitHub action for lint + testing #22

Closed
wants to merge 20 commits into from
Closed
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
61 changes: 61 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests.
# For now we only run against node 22.x, but can easily add more node versions should we decide to support them.
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

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

jobs:
frontend:
runs-on: ubuntu-latest

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

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install frontend dependencies
run: npm ci
- name: Lint frontend
run: npm run lint
- name: Check code format (also checks backend code)
run: npm run check:format
- name: Check that the frontend can successfully build (runs type checking)
run: npm run build

backend:
runs-on: ubuntu-latest

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

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install server dependencies
working-directory: ./server
run: npm ci
- name: Lint backend
working-directory: ./server
run: npm run check
- name: Run backend tests
working-directory: ./server
run: npm run ci:test
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"format": "prettier --write .",
"preview": "vite preview",
"test-server": "node --experimental-vm-modules node_modules/jest/bin/jest.js server/test/ --config server/jest.config.cjs",
"test-client": "jest src/test/",
"test": "npm run test-server && npm run test-client"
"check:format": "prettier --check .",
"preview": "vite preview"
},
"dependencies": {
"@codemirror/lang-javascript": "^6.2.2",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion server/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path';

export const SRCBOOK_DIR = path.join(os.homedir(), '.srcbook');

const userDir = import.meta.env.VITE_NOTEBOOKS_DIR || os.homedir();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should re-add this. Idk that it should affect anything here

Copy link
Contributor

@benjreinhart benjreinhart May 25, 2024

Choose a reason for hiding this comment

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

we should readd this as process.env.MY_ENV_VAR.

I don't know why the vite stuff and vite namespace is used for regular operating system environment variables. The vite specific stuff is for building frontend apps that are compiled for the browser.

const userDir = os.homedir();
const configPath = path.join(SRCBOOK_DIR, 'config.json');
const secretsPath = path.join(SRCBOOK_DIR, 'secrets.json');

Expand Down
3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"check": "tsc --noEmit",
"dev": "vite-node index.mts",
"test": "vitest"
"test": "vitest",
"ci:test": "vitest run ./"
},
"dependencies": {
"@scure/base": "^1.1.6",
Expand Down
2 changes: 2 additions & 0 deletions server/test/srcmd.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('encoding and decoding srcmd files', () => {
type: 'package.json',
source: `{\n "dependencies": {}\n}`,
filename: 'package.json',
output: [],
},
{
id: expect.any(String),
Expand Down Expand Up @@ -98,6 +99,7 @@ describe('it can decode from directories', () => {
type: 'package.json',
source: `{\n "dependencies": {}\n}\n`,
filename: 'package.json',
output: [],
},
{
id: expect.any(String),
Expand Down
4 changes: 3 additions & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
// Test
"types": ["vitest/globals"]
},
"include": ["./**/*.mts"],
"exclude": ["node_modules"]
Expand Down
10 changes: 0 additions & 10 deletions server/vite-env.d.mts

This file was deleted.

2 changes: 1 addition & 1 deletion server/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from 'vite';

export default defineConfig({
test: {
include: ['test/**/*.test.mts'],
include: ['**/*.test.mts'],
globals: true,
},
server: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
);
Button.displayName = 'Button';

export { Button, buttonVariants };
export { Button };
Loading