Skip to content

Commit

Permalink
Trying to use swc for e2e tests to see what's the performance speedup
Browse files Browse the repository at this point in the history
nb: swc can't tell that an enum imported from another module is an enum so the type would be undefined
Typeorm can't tell what type to assign and assigns undefined
you must specify the type manually, explore the api to find the valid values

nb2: swc doesn't like
import * as request from "supertest"

import request from "supertest" works just as well
does it work for all this kind of modules? idk
  • Loading branch information
friedbyalice committed Nov 23, 2023
1 parent 4dc60a1 commit 3724d21
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
7 changes: 4 additions & 3 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@casl/ability": "^6.3.3",
"@fastify/static": "^6.6.0",
"@hkrecruitment/shared": "workspace:*",
"@joi/date": "^2.1.0",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.0",
Expand All @@ -34,9 +35,9 @@
"@types/js-yaml": "^4.0.5",
"@types/passport-jwt": "^3.0.7",
"class-transformer": "^0.5.1",
"dotenv": "^16.0.3",
"google-auth-library": "^8.7.0",
"googleapis": "^118.0.0",
"dotenv": "^16.0.3",
"joi": "^17.7.0",
"js-yaml": "^4.1.0",
"jwks-rsa": "^3.0.0",
Expand All @@ -49,7 +50,6 @@
"webpack": "^5.75.0"
},
"devDependencies": {
"@types/multer": "^1.4.7",
"@automock/jest": "^1.0.1",
"@golevelup/ts-jest": "^0.3.6",
"@nestjs/cli": "^9.0.0",
Expand All @@ -59,6 +59,7 @@
"@swc/jest": "^0.2.26",
"@types/express": "^4.17.14",
"@types/jest": "28.1.8",
"@types/multer": "^1.4.7",
"@types/node": "^16.11.10",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
Expand Down Expand Up @@ -99,7 +100,7 @@
],
"moduleNameMapper": {
"^@mocks/(.*)$": "<rootDir>/src/mocks/$1"
},
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
Expand Down
6 changes: 3 additions & 3 deletions api/src/application/application.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Application implements ApplicationInterface {
@PrimaryGeneratedColumn('increment')
id: number;

@Column()
@Column({ type: 'simple-enum' })
type: ApplicationType;

@Column('varchar', { length: 64, name: 'applicant_id' })
Expand All @@ -28,7 +28,7 @@ export class Application implements ApplicationInterface {
@Column()
submission: Date;

@Column()
@Column({ type: 'simple-enum' })
state: ApplicationState;

@Column({ name: 'last_modified', nullable: true })
Expand All @@ -46,7 +46,7 @@ export class Application implements ApplicationInterface {
// @Column({ "name": "interview_id" })
// interviewId: number;

@Column({ name: 'ita_level' })
@Column({ type: 'simple-enum', name: 'ita_level' })
itaLevel: LangLevel;
}

Expand Down
4 changes: 2 additions & 2 deletions api/src/users/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, PrimaryColumn } from 'typeorm';
import { Column, Entity, PrimaryColumn, } from 'typeorm';
import { Person, Role } from '@hkrecruitment/shared';

@Entity()
Expand All @@ -24,6 +24,6 @@ export class User implements Person {
@Column({ nullable: true })
telegramId?: string;

@Column()
@Column({ type: "simple-enum", enum: Role })
role: Role;
}
14 changes: 9 additions & 5 deletions api/src/users/users.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import request from 'supertest';
import { createApp, getAccessToken, getSub } from 'test/app.e2e-spec';
import { CreateUserDto } from './create-user.dto';
import { UsersService } from './users.service';
Expand Down Expand Up @@ -56,9 +56,13 @@ describe('UsersController (e2e)', () => {
await app.close();
});

const insertMockUsers = async () => {
await Promise.all(mockUsers.map(async (u) => await usersService.create(u)));
};

describe('GET /users', () => {
beforeEach(async () => {
await mockUsers.forEach(async (u) => await usersService.create(u));
await insertMockUsers();
});

it('should return all users for admin', async () => {
Expand All @@ -84,7 +88,7 @@ describe('UsersController (e2e)', () => {

describe('GET /users/:oauthId', () => {
beforeEach(async () => {
await mockUsers.forEach(async (u) => await usersService.create(u));
await insertMockUsers();
});

it('should allow reading any user for admin', async () => {
Expand Down Expand Up @@ -182,7 +186,7 @@ describe('UsersController (e2e)', () => {

describe('PATCH /users/:oauthId', () => {
beforeEach(async () => {
await mockUsers.forEach(async (u) => await usersService.create(u));
await insertMockUsers();
});

it('should allow updating themselves for applicants', async () => {
Expand Down Expand Up @@ -267,7 +271,7 @@ describe('UsersController (e2e)', () => {

describe('DELETE /users/:oauthId', () => {
beforeEach(async () => {
await mockUsers.forEach(async (u) => await usersService.create(u));
await insertMockUsers();
});

it('should allow deleting themselves for applicants', async () => {
Expand Down
2 changes: 1 addition & 1 deletion api/test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
"^.+\\.(t|j)s$": "@swc/jest"
}
}
6 changes: 1 addition & 5 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "./App.css";
import "bootstrap/dist/css/bootstrap.min.css";
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import MyNavbar from "./MyNavbar";
import SignupForm from "./SignupForm";
import { Route } from "react-router-dom";
Expand Down Expand Up @@ -37,10 +37,6 @@ function App() {
}
}, [isAuthenticated]);

if (accessToken === "") {
return <div>Loading...</div>;
}

return (
<Routes>
<Route
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3724d21

Please sign in to comment.