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

chore: Introduced react and nestjs test applications #18

Merged
merged 21 commits into from
Aug 10, 2024
Merged
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
5 changes: 5 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['prettier', '@typescript-eslint'],
rules: {
// Miscellanous
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ jobs:
run_checks:
name: Run code checks
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_checks.yml@v4.0.0
with:
PNPM_BUILD: true

run_unit_tests:
name: Run unit tests
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_unit_tests.yml@v4.0.0
name: Run tests (vitest)
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_tests_vitest.yml@v4.0.0
with:
PNPM_BUILD: true
COVERAGE_FILENAME: reports/vitest/coverage/cobertura-coverage.xml
COVERAGE_FAIL_BELOW_MIN: 100

Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ jobs:
run_checks:
name: Run code checks
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_checks.yml@v4.0.0
with:
PNPM_BUILD: true

run_unit_tests:
name: Run unit tests
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_unit_tests.yml@v4.0.0
name: Run tests (vitest)
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_tests_vitest.yml@v4.0.0
with:
PNPM_BUILD: true
COVERAGE_FILENAME: reports/vitest/coverage/cobertura-coverage.xml
COVERAGE_FAIL_BELOW_MIN: 100

Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ jobs:
run_checks:
name: Run code checks
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_checks.yml@v4.0.0
with:
PNPM_BUILD: true

run_unit_tests:
name: Run unit tests
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_unit_tests.yml@v4.0.0
name: Run tests (vitest)
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_tests_vitest.yml@v4.0.0
with:
PNPM_BUILD: true
COVERAGE_FILENAME: reports/vitest/coverage/cobertura-coverage.xml
COVERAGE_FAIL_BELOW_MIN: 100
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_checks.yml@v4.0.0

run_unit_tests:
name: Run unit tests
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_unit_tests.yml@v4.0.0
name: Run tests (vitest)
uses: spuxx1701/ci-cd/.github/workflows/pnpm_run_tests_vitest.yml@v4.0.0
with:
COVERAGE_FILENAME: reports/vitest/coverage/cobertura-coverage.xml
COVERAGE_FAIL_BELOW_MIN: 100
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pnpm-lock.yaml
pnpm-workspace.yaml
reports/
dist/
.github/
Expand Down
2 changes: 1 addition & 1 deletion .release-please/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{ "type": "style", "section": "Styles", "hidden": true },
{ "type": "chore", "section": "Miscellaneous Chores", "hidden": true },
{ "type": "refactor", "section": "Code Refactoring" },
{ "type": "test", "section": "Tests" },
{ "type": "test", "section": "Tests", "hidden": true },
{ "type": "build", "section": "Build System" },
{ "type": "ci", "section": "Continuous Integration", "hidden": true }
]
Expand Down
9 changes: 9 additions & 0 deletions apps/nest/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"builder": "swc",
"deleteOutDir": true
}
}
25 changes: 25 additions & 0 deletions apps/nest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "nest",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite dev",
"debug": "nest start --debug --watch",
"preview": "node dist/main.mjs",
"build": "vite build",
"types": "tsc --noEmit"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"@spuxx/nest-utils": "workspace:@spuxx/nest-utils@*"
},
"devDependencies": {
"source-map-support": "^0.5.21",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1"
}
}
24 changes: 24 additions & 0 deletions apps/nest/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { NestUtilsModule } from '@spuxx/nest-utils';

describe('AppController', () => {
let controller: AppController;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
imports: [NestUtilsModule],
controllers: [AppController],
providers: [AppService],
}).compile();

controller = app.get<AppController>(AppController);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(controller.getHello()).toBe('Hello World!');
});
});
});
12 changes: 12 additions & 0 deletions apps/nest/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly service: AppService) {}

@Get()
getHello(): string {
return this.service.getHello();
}
}
11 changes: 11 additions & 0 deletions apps/nest/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { NestUtilsModule } from '@spuxx/nest-utils';

@Module({
imports: [NestUtilsModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
11 changes: 11 additions & 0 deletions apps/nest/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@nestjs/common';
import { NestUtilsService } from '@spuxx/nest-utils';

@Injectable()
export class AppService {
constructor(private readonly utils: NestUtilsService) {}

getHello(): string {
return this.utils.getHello();
}
}
Empty file.
15 changes: 15 additions & 0 deletions apps/nest/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Logger } from '@nestjs/common';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Logger.log(`Application is running on: http://localhost:3000`, 'Bootstrap');
// Required, see: https://www.npmjs.com/package/vite-plugin-node#get-started
if (import.meta.env.PROD) {
await app.listen(3000);
}
return app;
}

export const app = bootstrap();
7 changes: 7 additions & 0 deletions apps/nest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.nest.json",
"include": ["./src/**/*"],
"compilerOptions": {
"outDir": "./dist"
}
}
24 changes: 24 additions & 0 deletions apps/nest/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference types="vitest" />
import baseConfig from '../../vite.config';
import { mergeConfig, defineConfig } from 'vite';
import { VitePluginNode } from 'vite-plugin-node';

export default mergeConfig(
baseConfig,
defineConfig({
server: {
port: 3000,
},
plugins: [
...baseConfig.plugins!,
// https://www.npmjs.com/package/vite-plugin-node#get-started
VitePluginNode({
adapter: 'nest',
tsCompiler: 'swc',
appPath: 'src/main.ts',
exportName: 'app',
initAppOnBoot: true,
}),
],
}),
);
3 changes: 1 addition & 2 deletions test-apps/react/index.html → apps/react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@spuxx/browser-utils</title>
<title>@spuxx/jslibs</title>
</head>
<body>
<div id="root"></div>
Expand Down
1 change: 1 addition & 0 deletions test-apps/react/main.tsx → apps/react/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './src/App.tsx';
// @ts-expect-error TypeScript config is f***ed in this app for some reason
import de from './translations/de.yaml';
import { Intl, Logger } from '@spuxx/js-utils';

Expand Down
21 changes: 21 additions & 0 deletions apps/react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "react-test-app",
"version": "0.0.0",
"type": "module",
"private": true,
"scripts": {
"dev": "vite dev",
"types": "tsc --noEmit"
},
"dependencies": {
"@spuxx/browser-utils": "workspace:@spuxx/browser-utils@*",
"@spuxx/js-utils": "workspace:@spuxx/js-utils@*",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@vitejs/plugin-react": "^4.3.1"
}
}
5 changes: 2 additions & 3 deletions test-apps/react/src/App.tsx → apps/react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react';
import { intl } from '@spuxx/js-utils';

function App() {
export default function App(): React.ReactElement {
return (
<>
<h1>{intl('app.title')}</h1>
</>
);
}

export default App;
2 changes: 2 additions & 0 deletions apps/react/translations/de.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app:
title: 'spuxx/jslibs'
7 changes: 7 additions & 0 deletions apps/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.bundler.json",
"include": ["./src"],
"compilerOptions": {
"jsx": "react-jsx"
}
}
11 changes: 11 additions & 0 deletions apps/react/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import baseConfig from '../../vite.config';
import { mergeConfig, defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import ViteYaml from '@modyfi/vite-plugin-yaml';

export default mergeConfig(
baseConfig,
defineConfig({
plugins: [...baseConfig.plugins!, ViteYaml(), react()],
}),
);
30 changes: 30 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"monorepo": true,
"sourceRoot": "apps/nest/src",
"compilerOptions": {
"builder": "swc",
"typeCheck": true,
"deleteOutDir": true
},
"projects": {
"test-app": {
"type": "application",
"root": "apps/nest",
"sourceRoot": "apps/nest/src",
"compilerOptions": {
"tsConfigPath": "apps/nest/tsconfig.json"
}
},
"nest-utils": {
"type": "library",
"root": "packages/nest-utils",
"entryFile": "index",
"sourceRoot": "packages/nest-utils/src",
"compilerOptions": {
"tsConfigPath": "packages/nest-utils/tsconfig.json"
}
}
}
}
25 changes: 19 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,44 @@
"packageManager": "pnpm@9.6.0",
"private": "true",
"scripts": {
"dev": "concurrently \"pnpm dev:js-utils\" \"pnpm dev:browser-utils\" \"pnpm dev:nest-utils\" \"pnpm dev:app:react\" \"pnpm dev:app:nest\"",
"dev:js-utils": "cd packages/js-utils && pnpm dev",
"dev:browser-utils": "cd packages/browser-utils && pnpm dev",
"dev:nest-utils": "cd packages/nest-utils && pnpm dev",
"dev:app:react": "cd apps/react && pnpm dev",
"dev:app:nest": "cd apps/nest && pnpm dev",
"publish:test": "pnpm -r publish --dry-run --no-git-checks",
"test": "pnpm run test:unit",
"test:unit": "vitest run --coverage",
"test": "pnpm test:vitest",
"test:vitest": "vitest run --coverage",
"check": "pnpm types && pnpm run lint && pnpm run prettier-check",
"types": "tsc --noEmit",
"types": "pnpm -r types",
"lint": "eslint . --ext ts,tsx",
"prettier-check": "prettier --check .",
"format": "prettier --write ."
},
"devDependencies": {
"@modyfi/vite-plugin-yaml": "1.1.0",
"@nestjs/cli": "10.4.2",
"@nestjs/testing": "10.3.10",
"@swc/cli": "^0.4.0",
"@swc/core": "^1.7.6",
"@types/express": "^4.17.21",
"@types/node": "22.1.0",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"@vitest/coverage-v8": "2.0.5",
"concurrently": "^8.2.2",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
"prettier": "3.3.3",
"release-please": "^16.12.0",
"release-please": "16.12.0",
"typescript": "5.5.4",
"unplugin-swc": "^1.5.1",
"vite": "5.3.5",
"vite-plugin-dts": "3.9.1",
"vite-plugin-node": "^3.1.0",
"vite-tsconfig-paths": "4.3.2",
"vitest": "2.0.5"
},
"dependencies": {}
}
}
Loading