Skip to content

Commit

Permalink
Switch to vitest and other latest libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjsr committed May 15, 2024
1 parent 2bf5721 commit ef072fe
Show file tree
Hide file tree
Showing 21 changed files with 929 additions and 150 deletions.
10 changes: 10 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MYSQL_DATABASE=testdb
MYSQL_USER=testuser
MYSQL_PASSWORD=testpassword
MYSQL_ROOT_PASSWORD=rootcipassword
# MYSQL_HOST_PORT=23306
MYSQL_PORT=23407
MYSQL_HOST=localhost
PRISMA_DATABASE_URL=mysql://testuser:testpassword@tagtool_mysqldb:3306/testdb

MYSQL_CI_VERSION=8.0
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["github.vscode-github-actions"]
"recommendations": ["github.vscode-github-actions", "vitest.explorer", "hbenl.vscode-test-explorer"]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"jest.enable": false,
"jest.rootPath": "${workspaceFolder}"
}
5 changes: 3 additions & 2 deletions Dockerfile.dbmigrate
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ FROM ghcr.io/tjsr/node_patched_npm:${NODE_VERSION}-alpine${ALPINE_VERSION}-npm${

RUN --mount=type=cache,target=/root/.npm mkdir /opt/tagtool && npm config set fund false --location=global

COPY [ "package.json", "package-lock.json", "/opt/tagtool/" ]
COPY [ "package.json", "package-lock.json", ".npmrc", "/opt/tagtool/" ]
COPY prisma /opt/tagtool

WORKDIR /opt/tagtool
RUN --mount=type=secret,id=github,target=/root/.npm/github_pat if [ ! -s /root/.npm/github_pat ]; then echo "No github_pat secret found" && cat /root/.npm/github_pat && exit 127; fi

RUN --mount=type=secret,id=github,target=/root/.npm/github_pat --mount=type=cache,target=/root/.npm \
echo "//npm.pkg.github.com/:_authToken=$(cat /root/.npm/github_pat)" >> /root/.npmrc && \
npm install && \
echo "@tjsr:registry=https://npm.pkg.github.com/" >> /root/.npmrc && \
npm ci && \
rm -f /root/.npmrc

CMD ["npm", "run", "db:upgrade:deploy"]
32 changes: 20 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,46 @@ services:
container_name: tagtool_mysqldb
build:
args:
- MYSQL_VERSION=${MYSQL_CI_VERSION:-5.7}
MYSQL_VERSION: ${MYSQL_CI_VERSION:-5.7}
context: .
dockerfile_inline: |
ARG MYSQL_VERSION 5.7
FROM mysql:${MYSQL_VERSION:-5.7} as mysql
#COPY resources/*.sql /docker-entrypoint-initdb.d/
# env_file:
# - ./.env.test
environment:
MYSQL_ROOT_PASSWORD: cirootpassword
MYSQL_DATABASE: tagtool_ci
MYSQL_USER: ciuser
MYSQL_PASSWORD: cipassword
MYSQL_HOST: '127.0.0.1'
env_file:
- ./.env.test
# environment:
# MYSQL_ROOT_PASSWORD: cirootpassword
# MYSQL_DATABASE: tagtool_ci
# MYSQL_USER: ciuser
# MYSQL_PASSWORD: cipassword
# MYSQL_HOST: '127.0.0.1'
ports:
- "${MYSQL_CI_HOST_PORT:-23407}:3306"
command: --default-authentication-plugin=mysql_native_password
healthcheck:
test: ["CMD", "mysql", "-h", "127.0.0.1", "--silent", "-uciuser", "-pcipassword", "-e", "SELECT 1"]
test: ["CMD-SHELL", "mysql -h 127.0.0.1 --silent -u$$MYSQL_USER -p$$MYSQL_PASSWORD", "-e", "SELECT 1"]
interval: 3s
retries: 5
start_period: 30s
cidbmig:
container_name: tagtool_dbmigration
build:
args:
NODE_VERSION: 20.13.1
ALPINE_VERSION: 3.19
NPM_VERSION: 10.7.0
context: .
dockerfile: Dockerfile.dbmigrate
secrets:
- github
environment:
- PRISMA_DATABASE_URL=mysql://ciuser:cipassword@tagtool_mysqldb:3306/tagtool_ci
env_file:
- path: ./.env.test
required: true
# environment:
# - PRISMA_DATABASE_URL=mysql://testuser:testpassword@tagtool_mysqldb:3306/testdb
# - PRISMA_DATABASE_URL="mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@tagtool_mysqldb:${MYSQL_PORT}/${MYSQL_DATABASE}"
depends_on:
- mysqldb

Expand Down
5 changes: 2 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as dotenv from 'dotenv';
import { loadEnv, requireEnv } from '@tjsr/simple-env-utils';

import express from 'express';
import { requireEnv } from '@tjsr/simple-env-utils';
import { startApp } from './src/server.js';

dotenv.config();
loadEnv();

requireEnv('SESSION_SECRET');
requireEnv('USERID_UUID_NAMESPACE');
Expand Down
6 changes: 3 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { JestConfigWithTsJest } from 'ts-jest';
import dotenvFlow from 'dotenv-flow';
import { loadEnv } from '@tjsr/simple-env-utils';

dotenvFlow.config({ silent: true });
loadEnv({ path: process.cwd() });

const config: JestConfigWithTsJest = {
bail: 1,
Expand All @@ -10,7 +10,7 @@ const config: JestConfigWithTsJest = {
preset: 'ts-jest',
setupFiles: ['<rootDir>/src/setup-tests.ts'],
testEnvironment: 'node',
testRunner: 'jest-jasmine2',
testRunner: 'node',
extensionsToTreatAsEsm: ['.ts'],
moduleFileExtensions: ['js', 'mjs', 'json', 'ts'],
moduleNameMapper: {
Expand Down
Loading

0 comments on commit ef072fe

Please sign in to comment.