Skip to content

Commit

Permalink
Use path aliases for the server (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfelixrico authored Apr 5, 2024
1 parent 2325650 commit 2b8735e
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 88 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/verify-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -24,14 +24,14 @@ jobs:
run: yarn install
working-directory: ./server
shell: bash

- name: Cypress run
uses: cypress-io/github-action@v6
with:
install: false
working-directory: ./client
build: yarn build
start: yarn preview, yarn server:dev
start: yarn preview, yarn test:e2e:server
wait-on: http://localhost:4173, http://localhost:3000
config: baseUrl=http://localhost:4173

Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"preview": "vite preview",
"cypress:open": "cypress open",
"test:e2e": "cypress run",
"server:dev": "cd ../server && yarn dev"
"test:e2e:server": "cd ../server && yarn build && yarn start"
},
"dependencies": {
"@reduxjs/toolkit": "^2.2.1",
Expand Down
2 changes: 2 additions & 0 deletions server/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
13 changes: 8 additions & 5 deletions server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const config = {
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",
coverageProvider: 'v8',

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
Expand Down Expand Up @@ -89,7 +89,10 @@ const config = {
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},
moduleNameMapper: {
'@/(.*)': '<rootDir>/src/$1',
'@test/(.*)': '<rootDir>/test/$1',
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
Expand All @@ -101,7 +104,7 @@ const config = {
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
preset: "ts-jest",
preset: 'ts-jest',

// Run tests from one or more projects
// projects: undefined,
Expand Down Expand Up @@ -193,6 +196,6 @@ const config = {

// Whether to use watchman for file crawling
// watchman: true,
};
}

module.exports = config;
module.exports = config
21 changes: 13 additions & 8 deletions server/jest/__tests__/room.service.class.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// TODO support absolute paths. these are a mess.
import { INACTIVITY_THRESHOLD, RoomService } from '../../../server/src/services/room.service/room-service.class'
import { Room } from '../../src/services/room.service/room.class'
import {
INACTIVITY_THRESHOLD,
RoomService,
} from '@/services/room.service/room-service.class'
import { Room } from '@/services/room.service/room.class'

describe('room-service', () => {
it('purges rooms past the inactivity threshold', () => {
const room = new Room('room_id')
// Forces lastActivityTs to be way past the inactivity threshold
jest.spyOn(room, 'lastActivityTs', 'get')
jest
.spyOn(room, 'lastActivityTs', 'get')
.mockReturnValue(Date.now() - INACTIVITY_THRESHOLD * 2)

const service = new RoomService()
Expand All @@ -15,16 +18,18 @@ describe('room-service', () => {
service.rooms['dummy2'] = new Room('dummy2')
service.rooms['dummy3'] = new Room('dummy3')

expect(service.rooms).toEqual(expect.objectContaining({
'room_id': expect.any(Room)
}))
expect(service.rooms).toEqual(
expect.objectContaining({
room_id: expect.any(Room),
})
)
expect(Object.values(service.rooms)).toHaveLength(4)

service.purgeInactiveRooms()

expect(service.rooms).toEqual(
expect.not.objectContaining({
'room_id': expect.any(Room)
room_id: expect.any(Room),
})
)
expect(Object.values(service.rooms)).toHaveLength(3)
Expand Down
25 changes: 25 additions & 0 deletions server/jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2017",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "CommonJS",
"baseUrl": "../",
"resolveJsonModule": true,
"outDir": "./dist",
"removeComments": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./src/*"],
"@test/*": ["./jest/*"]
}
},
"include": ["./**/*.ts"],
"exclude": ["./node_modules"]
}
File renamed without changes.
13 changes: 7 additions & 6 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"private": true,
"license": "MIT",
"scripts": {
"lint": "eslint src/**/*.ts",
"format": "prettier ./**/*.{ts,json} --w",
"build": "tsc",
"start": "node dist/index.js",
"dev": "nodemon src/index.ts",
"lint": "eslint ./**/*.ts",
"format": "prettier ./**/*.{ts,json,js} --w",
"build": "tsc && tsc-alias",
"start": "node dist/src/index.js",
"dev": "tsx src/index.ts",
"test": "jest"
},
"dependencies": {
Expand All @@ -31,10 +31,11 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"nodemon": "^3.1.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.8",
"tsx": "^4.7.2",
"typescript": "^5.4.2"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Socket } from 'socket.io'
// TODO make absolute paths work
import roomService from '../services/room.service'
import roomService from '@/services/room.service'

function saveEvent(roomId: string, event: unknown) {
const room = roomService.getRoom(roomId)
Expand Down
5 changes: 4 additions & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"strict": true,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true
"skipLibCheck": true,
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["./src/**/*.ts", "./*.d.ts"],
"exclude": ["./node_modules", "./test/**/*.ts"]
Expand Down
Loading

0 comments on commit 2b8735e

Please sign in to comment.