express-generator-typescript 2.6.3 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README-git ADDED
@@ -0,0 +1,95 @@
1
+ <img alt='overnightjs' src='https://github.com/seanpmaxwell/express-generator-typescript/raw/master/express-typescript.png' border='0'>
2
+
3
+ [Express](https://www.npmjs.com/package/express) with [TypeScript's](https://www.npmjs.com/package/typescript) application generator.
4
+
5
+ <a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/v/express-generator-typescript.svg" alt="NPM Version" /></a>
6
+ <a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/l/express-generator-typescript.svg" alt="Package License" /></a>
7
+ <a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/dm/express-generator-typescript.svg" alt="NPM Downloads" /></a>
8
+
9
+
10
+ ## What is it?
11
+
12
+ Creates a new express application similar to the _express-generator_ module. Except this new application is configured to use TypeScript instead of plain JavaScript.
13
+
14
+ This project complies with Typescript best practices listed <a href="https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md">here</a>.
15
+
16
+
17
+ ## Why express-generator-typescript?
18
+
19
+ NodeJS is great for the rapid development of web-projects, but is often neglected because of the lack of type safety. TypeScript solves this issue and (along with its linter file) can even make your code more robust than some other static languages like Java.
20
+
21
+ There are some other tools out there to generate express apps with TypeScript such as _express-generator-ts_, but these either haven't been updated in a while or install a lot of junk in your project (such as an ORM).
22
+
23
+ Due to the heavy use of single-page-applications, no view-engine is configured by default. Express is only setup with the minimal settings for calling APIs and serving an index.html file. All the tools you need to run for development (while restarting on changes), building, testing, and running for production are packaged with this library.
24
+
25
+ In addition, relative paths are also setup, so you don't have to go through the trouble of installing and configuring _tsconfig-paths_ and _module-alias_. Just make sure to update `paths` in _tsconfig.json_ and `_moduleAliases` in _preload.js_ if you want to add/edit the relative paths.
26
+
27
+
28
+ ## Sample-project
29
+
30
+ When you run _express-generator-typescript_, it sets up a simple application with routes for adding, updating, deleting, and fetching user objects. This is just to demonstrate how routing is done with express.
31
+
32
+ ### `--with-auth` option no longer available for version 2.5+
33
+
34
+ For the command-line, you used to be able to pass the `--with-auth` option to generate an app which required a login before using the routes; however, maintaining two separate projects became quite cumbersome. If you want an example of how to do authentication in expressjs with json-web-tokens you can refer to this sample project <a href="https://github.com/seanpmaxwell/express-jsonwebtoken-demo">here</a>.
35
+
36
+
37
+ ## Installation
38
+
39
+ ```sh
40
+ $ Just use 'npx'
41
+ Or
42
+ $ npm install -g express-generator-typescript
43
+ ```
44
+
45
+
46
+ ## Quick Start
47
+
48
+ The quickest way to get started is use npx and pass in the name of the project you want to create. If you don't specify a project name, the default _express-gen-ts_ will be used instead. If you want to use `yarn` instead of `npm`, pass the option `--use-yarn`.
49
+
50
+ Create the app:<br/>
51
+ With no options: `$ npx express-generator-typescript`<br/>
52
+ With all options (order doesn't matter): `$ npx express-generator-typescript --use-yarn "project name"`
53
+
54
+
55
+ Start your express-generator-typescript app in development mode at `http://localhost:3000/`:
56
+
57
+ ```bash
58
+ $ cd "project name" && npm run dev
59
+ ```
60
+
61
+
62
+ ## Available commands for the server.
63
+
64
+ - Run the server in development mode: `npm run dev` or `npm run dev:hot`.
65
+ - Run all unit-tests: `npm run test` or `npm run test:hot`.
66
+ - Run a single unit-test: `npm test -- --testFile="name of test file" (i.e. --testFile=Users)`.
67
+ - Check for linting errors: `npm run lint`.
68
+ - Build the project for production: `npm run build`.
69
+ - Run the production build: `npm start`.
70
+ - Check for typescript errors: `npm run type-check`.
71
+
72
+
73
+ ## Debugging
74
+
75
+ During development, _express-generator-typescript_ uses `nodemon` to restart the server when changes are detected. If you want to enable debugging for node, you'll need to modify the nodemon configurations. This is located under `nodemonConfig:` in `package.json` for the server and `./spec/nodemon.json` for unit-testing. For the `exec` property, replace `ts-node` with `node --inspect -r ts-node/register`.
76
+
77
+
78
+ ## Note for VSCode users
79
+
80
+ In order to use eslint as a typescript file with VSCode, you need to add a setting to your eslint options. At the root of your project, add a `.vscode/settings.json` file (if you don't have one already) and add the option `unstable_ts_config`:
81
+
82
+ ```typescript
83
+ "eslint.options": {
84
+ "flags": ["unstable_ts_config"]
85
+ }
86
+ ```
87
+ <br/>
88
+
89
+
90
+ Happy web deving :)
91
+
92
+
93
+ ## License
94
+
95
+ [MIT](LICENSE)
package/README.md CHANGED
@@ -12,84 +12,9 @@
12
12
  Creates a new express application similar to the _express-generator_ module. Except this new application is configured to use TypeScript instead of plain JavaScript.
13
13
 
14
14
  This project complies with Typescript best practices listed <a href="https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md">here</a>.
15
-
16
-
17
- ## Why express-generator-typescript?
18
-
19
- NodeJS is great for the rapid development of web-projects, but is often neglected because of the lack of type safety. TypeScript solves this issue and (along with its linter file) can even make your code more robust than some other static languages like Java.
20
-
21
- There are some other tools out there to generate express apps with TypeScript such as _express-generator-ts_, but these either haven't been updated in a while or install a lot of junk in your project (such as an ORM).
22
-
23
- Due to the heavy use of single-page-applications, no view-engine is configured by default. Express is only setup with the minimal settings for calling APIs and serving an index.html file. All the tools you need to run for development (while restarting on changes), building, testing, and running for production are packaged with this library.
24
-
25
- In addition, relative paths are also setup, so you don't have to go through the trouble of installing and configuring _tsconfig-paths_ and _module-alias_. Just make sure to update `paths` in _tsconfig.json_ and `_moduleAliases` in _preload.js_ if you want to add/edit the relative paths.
26
-
27
-
28
- ## Sample-project
29
-
30
- When you run _express-generator-typescript_, it sets up a simple application with routes for adding, updating, deleting, and fetching user objects. This is just to demonstrate how routing is done with express.
31
-
32
- ### `--with-auth` option no longer available for version 2.5+
33
-
34
- For the command-line, you used to be able to pass the `--with-auth` option to generate an app which required a login before using the routes; however, maintaining two separate projects became quite cumbersome. If you want an example of how to do authentication in expressjs with json-web-tokens you can refer to this sample project <a href="https://github.com/seanpmaxwell/express-jsonwebtoken-demo">here</a>.
35
-
36
-
37
- ## Installation
38
-
39
- ```sh
40
- $ Just use 'npx'
41
- Or
42
- $ npm install -g express-generator-typescript
43
- ```
44
-
45
-
46
- ## Quick Start
47
-
48
- The quickest way to get started is use npx and pass in the name of the project you want to create. If you don't specify a project name, the default _express-gen-ts_ will be used instead. If you want to use `yarn` instead of `npm`, pass the option `--use-yarn`.
49
-
50
- Create the app:<br/>
51
- With no options: `$ npx express-generator-typescript`<br/>
52
- With all options (order doesn't matter): `$ npx express-generator-typescript --use-yarn "project name"`
53
-
54
-
55
- Start your express-generator-typescript app in development mode at `http://localhost:3000/`:
56
-
57
- ```bash
58
- $ cd "project name" && npm run dev
59
- ```
60
-
61
-
62
- ## Available commands for the server.
63
-
64
- - Run the server in development mode: `npm run dev` or `npm run dev:hot`.
65
- - Run all unit-tests: `npm run test` or `npm run test:hot`.
66
- - Run a single unit-test: `npm test -- --testFile="name of test file" (i.e. --testFile=Users)`.
67
- - Check for linting errors: `npm run lint`.
68
- - Build the project for production: `npm run build`.
69
- - Run the production build: `npm start`.
70
- - Check for typescript errors: `npm run type-check`.
71
-
72
-
73
- ## Debugging
74
-
75
- During development, _express-generator-typescript_ uses `nodemon` to restart the server when changes are detected. If you want to enable debugging for node, you'll need to modify the nodemon configurations. This is located under `nodemonConfig:` in `package.json` for the server and `./spec/nodemon.json` for unit-testing. For the `exec` property, replace `ts-node` with `node --inspect -r ts-node/register`.
76
-
77
-
78
- ## Note for VSCode users
79
-
80
- In order to use eslint as a typescript file with VSCode, you need to add a setting to your eslint options. At the root of your project, add a `.vscode/settings.json` file (if you don't have one already) and add the option `unstable_ts_config`:
81
-
82
- ```typescript
83
- "eslint.options": {
84
- "flags": ["unstable_ts_config"]
85
- }
86
- ```
87
15
  <br/>
88
16
 
89
17
 
90
- Happy web deving :)
91
-
92
-
93
- ## License
18
+ ## Documenation
94
19
 
95
- [MIT](LICENSE)
20
+ Please refer to the official <a href="https://github.com/seanpmaxwell/express-generator-typescript">github repo</a> for the most up-to-date documentation.
@@ -16,8 +16,8 @@ const PROJECT_FOLDER_PATH = './project-files';
16
16
  const DEPENDENCIES = 'express dotenv morgan cookie-parser jet-logger ' +
17
17
  'module-alias helmet jsonfile inserturlparams jet-paths dayjs jet-env ' +
18
18
  'jet-validators',
19
- DEV_DEPENDENCIES = 'ts-node typescript nodemon find jasmine supertest ' +
20
- '@types/node @types/jasmine @types/find @types/morgan @types/cookie-parser ' +
19
+ DEV_DEPENDENCIES = 'ts-node typescript nodemon find supertest vitest ' +
20
+ '@types/node @types/find @types/morgan @types/cookie-parser ' +
21
21
  '@types/supertest fs-extra tsconfig-paths jiti @swc/core @types/jsonfile ' +
22
22
  '@types/fs-extra @types/module-alias @stylistic/eslint-plugin-js eslint ' +
23
23
  '@eslint/js typescript-eslint eslint-plugin-n @stylistic/eslint-plugin-ts';
@@ -8,8 +8,7 @@
8
8
  "dev:hot": "nodemon --exec \"npm run dev\" --watch ./src --ext .ts",
9
9
  "lint": "eslint .",
10
10
  "start": "NODE_ENV=production node -r ./config.js ./dist",
11
- "test": "NODE_ENV=test ts-node ./spec",
12
- "test:hot": "nodemon --exec \"npm run test\" --watch ./src --watch ./spec --ext .ts",
11
+ "test": "NODE_ENV=test vitest",
13
12
  "type-check": "tsc --noEmit"
14
13
  },
15
14
  "engines": {
@@ -38,7 +37,6 @@
38
37
  "@types/cookie-parser": "^1.4.8",
39
38
  "@types/find": "^0.2.4",
40
39
  "@types/fs-extra": "^11.0.4",
41
- "@types/jasmine": "^5.1.7",
42
40
  "@types/jsonfile": "^6.1.4",
43
41
  "@types/module-alias": "^2.0.4",
44
42
  "@types/morgan": "^1.9.9",
@@ -48,13 +46,13 @@
48
46
  "eslint-plugin-n": "^17.17.0",
49
47
  "find": "^0.3.0",
50
48
  "fs-extra": "^11.3.0",
51
- "jasmine": "^5.6.0",
52
49
  "jiti": "^2.4.2",
53
50
  "nodemon": "^3.1.10",
54
51
  "supertest": "^7.1.0",
55
52
  "ts-node": "^10.9.2",
56
53
  "tsconfig-paths": "^4.2.0",
57
54
  "typescript": "^5.8.3",
58
- "typescript-eslint": "^8.31.0"
55
+ "typescript-eslint": "^8.31.0",
56
+ "vitest": "^3.1.2"
59
57
  }
60
58
  }
@@ -1 +1 @@
1
- {"users":[{"id":53597750560,"name":"Bill","created":"2025-04-23T22:13:36.714Z","email":"sean.maxwell@gmail.com"},{"id":343509021766,"name":"John Smith","created":"2025-04-23T22:13:36.714Z","email":"john.smith@gmail.com"},{"id":223752183095,"name":"Gordan Freeman","created":"2025-04-23T22:13:36.714Z","email":"gordan.freeman@gmail.com"}]}
1
+ {"users":[{"id":37508014430,"name":"Sean Maxwell","created":"2025-04-30T18:16:40.961Z","email":"sean.maxwell@gmail.com"},{"id":188309817441,"name":"John Smith","created":"2025-04-30T18:16:40.961Z","email":"john.smith@gmail.com"},{"id":787266485461,"name":"Gordan Freeman","created":"2025-04-30T18:16:40.961Z","email":"gordan.freeman@gmail.com"},{"id":448607986518,"name":"Sean Maxwell","created":"2025-04-30T18:16:40.990Z","email":"sean.maxwell@gmail.com"},{"id":517772227440,"name":"John Smith","created":"2025-04-30T18:16:40.990Z","email":"john.smith@gmail.com"},{"id":341201737995,"name":"Gordan Freeman","created":"2025-04-30T18:16:40.990Z","email":"gordan.freeman@gmail.com"},{"id":15893202169,"name":"a","created":"2025-04-30T18:16:40.991Z","email":"a@a.com"},{"id":929445117117,"name":"Sean Maxwell","created":"2025-04-30T18:16:41.008Z","email":"sean.maxwell@gmail.com"},{"id":414870034077,"name":"John Smith","created":"2025-04-30T18:16:41.008Z","email":"john.smith@gmail.com"},{"id":425170167908,"name":"Gordan Freeman","created":"2025-04-30T18:16:41.008Z","email":"gordan.freeman@gmail.com"},{"id":668144426266,"name":"Bill","created":"2025-04-30T18:16:41.029Z","email":"sean.maxwell@gmail.com"},{"id":346599891503,"name":"John Smith","created":"2025-04-30T18:16:41.029Z","email":"john.smith@gmail.com"},{"id":868427536392,"name":"Gordan Freeman","created":"2025-04-30T18:16:41.029Z","email":"gordan.freeman@gmail.com"},{"id":781342423953,"name":"Bill","created":"2025-04-30T18:16:41.038Z","email":"sean.maxwell@gmail.com"},{"id":259532967654,"name":"John Smith","created":"2025-04-30T18:16:41.038Z","email":"john.smith@gmail.com"},{"id":128343184794,"name":"Gordan Freeman","created":"2025-04-30T18:16:41.038Z","email":"gordan.freeman@gmail.com"},{"id":137492210417,"name":"Bill","created":"2025-04-30T18:16:41.045Z","email":"sean.maxwell@gmail.com"},{"id":393535542925,"name":"John Smith","created":"2025-04-30T18:16:41.045Z","email":"john.smith@gmail.com"},{"id":332379349789,"name":"Gordan Freeman","created":"2025-04-30T18:16:41.045Z","email":"gordan.freeman@gmail.com"},{"id":923502375831,"name":"John Smith","created":"2025-04-30T18:16:41.052Z","email":"john.smith@gmail.com"},{"id":119305864617,"name":"Gordan Freeman","created":"2025-04-30T18:16:41.052Z","email":"gordan.freeman@gmail.com"},{"id":269664001282,"name":"Bill","created":"2025-04-30T18:16:41.060Z","email":"sean.maxwell@gmail.com"},{"id":988915527591,"name":"John Smith","created":"2025-04-30T18:16:41.060Z","email":"john.smith@gmail.com"},{"id":851898715932,"name":"Gordan Freeman","created":"2025-04-30T18:16:41.060Z","email":"gordan.freeman@gmail.com"}]}
@@ -0,0 +1,33 @@
1
+ import { Response } from 'supertest';
2
+ import UserRepo from '@src/repos/UserRepo';
3
+
4
+
5
+ /******************************************************************************
6
+ Types
7
+ ******************************************************************************/
8
+
9
+ // Use generics to add properties to 'body'
10
+ export type TRes<T = object> = Omit<Response, 'body'> & {
11
+ body: T & { error?: string | IErrObj },
12
+ };
13
+
14
+ interface IErrObj {
15
+ message: string;
16
+ [key: string]: unknown;
17
+ }
18
+
19
+
20
+ /******************************************************************************
21
+ Functions
22
+ ******************************************************************************/
23
+
24
+ /**
25
+ * Delete all records for unit testing.
26
+ */
27
+ export async function cleanDatabase(): Promise<void> {
28
+ await Promise.all([
29
+ UserRepo.deleteAllUsers(),
30
+ ]);
31
+ }
32
+
33
+
@@ -1,5 +1,4 @@
1
1
  import { Response } from 'supertest';
2
- import UserRepo from '@src/repos/UserRepo';
3
2
  import { IParseObjectError, parseJson } from 'jet-validators/utils';
4
3
  import { isString } from 'jet-validators';
5
4
 
@@ -28,15 +27,6 @@ interface IValidationErr {
28
27
  Functions
29
28
  ******************************************************************************/
30
29
 
31
- /**
32
- * Delete all records for unit testing.
33
- */
34
- export async function cleanDatabase(): Promise<void> {
35
- await Promise.all([
36
- UserRepo.deleteAllUsers(),
37
- ]);
38
- }
39
-
40
30
  /**
41
31
  * JSON parse a validation error.
42
32
  */
@@ -0,0 +1,28 @@
1
+
2
+ import { beforeAll } from 'vitest';
3
+ import supertest, { Test } from 'supertest';
4
+ import TestAgent from 'supertest/lib/agent';
5
+
6
+ import app from '@src/server';
7
+ import UserRepo from '@src/repos/UserRepo';
8
+
9
+
10
+ /******************************************************************************
11
+ Run
12
+ ******************************************************************************/
13
+
14
+ let agent: TestAgent<Test>;
15
+
16
+ beforeAll(async () => {
17
+ agent = supertest.agent(app);
18
+ await Promise.all([
19
+ UserRepo.deleteAllUsers(),
20
+ ]);
21
+ });
22
+
23
+
24
+ /******************************************************************************
25
+ Export
26
+ ******************************************************************************/
27
+
28
+ export { agent };
@@ -1,9 +1,6 @@
1
- import supertest from 'supertest';
2
1
  import insertUrlParams from 'inserturlparams';
3
2
  import { customDeepCompare } from 'jet-validators/utils';
4
3
 
5
- import app from '@src/server';
6
-
7
4
  import UserRepo from '@src/repos/UserRepo';
8
5
  import User, { IUser } from '@src/models/User';
9
6
  import { USER_NOT_FOUND_ERR } from '@src/services/UserService';
@@ -11,8 +8,9 @@ import { USER_NOT_FOUND_ERR } from '@src/services/UserService';
11
8
  import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
12
9
  import { ValidationError } from '@src/common/util/route-errors';
13
10
 
14
- import Paths from 'spec/support/Paths';
15
- import { cleanDatabase, parseValidationErr, TRes } from 'spec/support';
11
+ import Paths from './common/Paths';
12
+ import { parseValidationErr, TRes } from './common/util';
13
+ import { agent } from './support/setup';
16
14
 
17
15
 
18
16
  /******************************************************************************
@@ -42,12 +40,10 @@ const compareUserArrays = customDeepCompare({
42
40
 
43
41
  describe('UserRouter', () => {
44
42
 
45
- const agent = supertest.agent(app);
46
43
  let dbUsers: IUser[] = [];
47
44
 
48
45
  // Run before all tests
49
46
  beforeEach(async () => {
50
- await cleanDatabase();
51
47
  dbUsers = await UserRepo.insertMult(DB_USERS);
52
48
  });
53
49
 
@@ -56,14 +52,10 @@ describe('UserRouter', () => {
56
52
 
57
53
  // Success
58
54
  it('should return a JSON object with all the users and a status code ' +
59
- `of "${HttpStatusCodes.OK}" if the request was successful.`, done => {
60
- agent
61
- .get(Paths.Users.Get)
62
- .end((_, res: TRes<{ users: IUser[]}>) => {
63
- expect(res.status).toBe(HttpStatusCodes.OK);
64
- expect(compareUserArrays(res.body.users, DB_USERS)).toBeTruthy();
65
- done();
66
- });
55
+ `of "${HttpStatusCodes.OK}" if the request was successful.`, async () => {
56
+ const res: TRes<{ users: IUser[]}> = await agent.get(Paths.Users.Get);
57
+ expect(res.status).toBe(HttpStatusCodes.OK);
58
+ expect(compareUserArrays(res.body.users, DB_USERS)).toBeTruthy();
67
59
  });
68
60
  });
69
61
 
@@ -72,31 +64,21 @@ describe('UserRouter', () => {
72
64
 
73
65
  // Test add user success
74
66
  it(`should return a status code of "${HttpStatusCodes.CREATED}" if the ` +
75
- 'request was successful.', done => {
76
- const user = User.new({ name: 'a', email: 'a@a.com' });
77
- agent
78
- .post(Paths.Users.Add)
79
- .send({ user })
80
- .end((_, res) => {
81
- expect(res.status).toBe(HttpStatusCodes.CREATED);
82
- done();
83
- });
67
+ 'request was successful.', async () => {
68
+ const user = User.new({ name: 'a', email: 'a@a.com' }),
69
+ res = await agent.post(Paths.Users.Add).send({ user });
70
+ expect(res.status).toBe(HttpStatusCodes.CREATED);
84
71
  });
85
72
 
86
73
  // Missing param
87
74
  it('should return a JSON object with an error message of and a status ' +
88
75
  `code of "${HttpStatusCodes.BAD_REQUEST}" if the user param was ` +
89
- 'missing.', done => {
90
- agent
91
- .post(Paths.Users.Add)
92
- .send({ user: null })
93
- .end((_, res: TRes) => {
94
- expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
95
- const errorObj = parseValidationErr(res.body.error);
96
- expect(errorObj.message).toBe(ValidationError.MESSAGE);
97
- expect(errorObj.errors[0].prop).toBe('user');
98
- done();
99
- });
76
+ 'missing.', async () => {
77
+ const res: TRes = await agent.post(Paths.Users.Add).send({ user: null });
78
+ expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
79
+ const errorObj = parseValidationErr(res.body.error);
80
+ expect(errorObj.message).toBe(ValidationError.MESSAGE);
81
+ expect(errorObj.errors[0].prop).toBe('user');
100
82
  });
101
83
  });
102
84
 
@@ -105,81 +87,59 @@ describe('UserRouter', () => {
105
87
 
106
88
  // Success
107
89
  it(`should return a status code of "${HttpStatusCodes.OK}" if the ` +
108
- 'request was successful.', done => {
90
+ 'request was successful.', async () => {
109
91
  const user = DB_USERS[0];
110
92
  user.name = 'Bill';
111
- agent
112
- .put(Paths.Users.Update)
113
- .send({ user })
114
- .end((_, res) => {
115
- expect(res.status).toBe(HttpStatusCodes.OK);
116
- done();
117
- });
93
+ const res = await agent.put(Paths.Users.Update).send({ user });
94
+ expect(res.status).toBe(HttpStatusCodes.OK);
118
95
  });
119
96
 
120
97
  // Id is the wrong data type
121
98
  it('should return a JSON object with an error message and a status code ' +
122
- `of "${HttpStatusCodes.BAD_REQUEST}" if the user param was missing`,
123
- done => {
99
+ `of "${HttpStatusCodes.BAD_REQUEST}" if the user param was missing`,
100
+ async () => {
124
101
  const user = User.new();
125
102
  user.id = ('5' as unknown as number);
126
- agent
127
- .put(Paths.Users.Update)
128
- .send({ user })
129
- .end((_, res: TRes) => {
130
- expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
131
- const errorObj = parseValidationErr(res.body.error);
132
- expect(errorObj.message).toBe(ValidationError.MESSAGE);
133
- expect(errorObj.errors[0].prop).toBe('user');
134
- expect(errorObj.errors[0].children?.[0].prop).toBe('id');
135
- done();
136
- });
103
+ const res: TRes = await agent.put(Paths.Users.Update).send({ user });
104
+ expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
105
+ const errorObj = parseValidationErr(res.body.error);
106
+ expect(errorObj.message).toBe(ValidationError.MESSAGE);
107
+ expect(errorObj.errors[0].prop).toBe('user');
108
+ expect(errorObj.errors[0].children?.[0].prop).toBe('id');
137
109
  });
138
110
 
139
111
  // User not found
140
112
  it('should return a JSON object with the error message of ' +
141
113
  `"${USER_NOT_FOUND_ERR}" and a status code of ` +
142
- `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, done => {
143
- const user = User.new({ id: 4, name: 'a', email: 'a@a.com' });
144
- agent
145
- .put(Paths.Users.Update)
146
- .send({ user })
147
- .end((_, res: TRes) => {
148
- expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
149
- expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
150
- done();
151
- });
114
+ `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, async () => {
115
+ const user = User.new({ id: 4, name: 'a', email: 'a@a.com' }),
116
+ res: TRes = await agent.put(Paths.Users.Update).send({ user });
117
+ expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
118
+ expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
152
119
  });
153
120
  });
154
121
 
155
122
  // Delete User
156
123
  describe(`"DELETE:${Paths.Users.Delete}"`, () => {
157
124
 
158
- const getPath = (id: number) => insertUrlParams(Paths.Users.Delete, { id });
125
+ const getPath = (id: number) => insertUrlParams(Paths.Users.Delete,
126
+ { id });
159
127
 
160
128
  // Success
161
129
  it(`should return a status code of "${HttpStatusCodes.OK}" if the ` +
162
- 'request was successful.', done => {
163
- const id = dbUsers[0].id;
164
- agent
165
- .delete(getPath(id))
166
- .end((_, res) => {
167
- expect(res.status).toBe(HttpStatusCodes.OK);
168
- done();
169
- });
130
+ 'request was successful.', async () => {
131
+ const id = dbUsers[0].id,
132
+ res = await agent.delete(getPath(id));
133
+ expect(res.status).toBe(HttpStatusCodes.OK);
170
134
  });
171
135
 
172
136
  // User not found
173
137
  it('should return a JSON object with the error message of ' +
174
138
  `"${USER_NOT_FOUND_ERR}" and a status code of ` +
175
- `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, done => {
176
- agent
177
- .delete(getPath(-1))
178
- .end((_, res: TRes) => {
179
- expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
180
- expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
181
- done();
182
- });
139
+ `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, async () => {
140
+ const res: TRes = await agent.delete(getPath(-1));
141
+ expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
142
+ expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
183
143
  });
184
144
  });
185
145
  });
@@ -11,7 +11,8 @@
11
11
  "paths": {
12
12
  "@src/*": ["src/*"]
13
13
  },
14
- "useUnknownInCatchVariables": false
14
+ "useUnknownInCatchVariables": false,
15
+ "types": ["vitest/globals"],
15
16
  },
16
17
  "ts-node": {
17
18
  "swc": true,
@@ -22,10 +23,11 @@
22
23
  },
23
24
  "include": [
24
25
  "src/**/*.ts",
25
- "spec/**/*.ts",
26
+ "tests/**/*.ts",
26
27
  "config.ts",
27
28
  "scripts",
28
- "eslint.config.ts"
29
+ "eslint.config.ts",
30
+ "vitest.config.ts"
29
31
  ],
30
32
  "exclude": [
31
33
  "src/public/*"
@@ -21,9 +21,10 @@
21
21
  "config.ts"
22
22
  ],
23
23
  "exclude": [
24
- "spec",
24
+ "tests",
25
25
  "src/public/",
26
26
  "scripts",
27
- "eslint.config.ts"
27
+ "eslint.config.ts",
28
+ "vitest.config.js"
28
29
  ]
29
30
  }
@@ -0,0 +1,18 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import path from 'path';
3
+
4
+ const config = defineConfig({
5
+ test: {
6
+ globals: true,
7
+ environment: 'node',
8
+ setupFiles: ['config.ts', './tests/support/setup.ts'],
9
+ isolate: true,
10
+ },
11
+ resolve: {
12
+ alias: {
13
+ '@src': path.resolve(__dirname, './src'),
14
+ },
15
+ },
16
+ });
17
+
18
+ export default config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-generator-typescript",
3
- "version": "2.6.3",
3
+ "version": "2.7.0",
4
4
  "description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
5
5
  "scripts": {
6
6
  "express-generator-typescript": "node bin/cli.js",
package/README-npm DELETED
@@ -1,20 +0,0 @@
1
- <img alt='overnightjs' src='https://github.com/seanpmaxwell/express-generator-typescript/raw/master/express-typescript.png' border='0'>
2
-
3
- [Express](https://www.npmjs.com/package/express) with [TypeScript's](https://www.npmjs.com/package/typescript) application generator.
4
-
5
- <a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/v/express-generator-typescript.svg" alt="NPM Version" /></a>
6
- <a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/l/express-generator-typescript.svg" alt="Package License" /></a>
7
- <a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/dm/express-generator-typescript.svg" alt="NPM Downloads" /></a>
8
-
9
-
10
- ## What is it?
11
-
12
- Creates a new express application similar to the _express-generator_ module. Except this new application is configured to use TypeScript instead of plain JavaScript.
13
-
14
- This project complies with Typescript best practices listed <a href="https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md">here</a>.
15
- <br/>
16
-
17
-
18
- ## Documenation
19
-
20
- Please refer to the official <a href="https://github.com/seanpmaxwell/express-generator-typescript">github repo</a> for the most up-to-date documentation.
@@ -1,70 +0,0 @@
1
- import find from 'find';
2
- import Jasmine from 'jasmine';
3
- import logger from 'jet-logger';
4
- import { argv } from 'process';
5
-
6
-
7
- /******************************************************************************
8
- Run
9
- ******************************************************************************/
10
-
11
- // Start
12
- (async () => {
13
- try {
14
- // Init Jasmine
15
- const jasmine = new Jasmine();
16
- jasmine.exitOnCompletion = false;
17
- // Set location of test files
18
- jasmine.loadConfig({
19
- random: true,
20
- spec_dir: 'spec',
21
- spec_files: [
22
- './tests/**/*.spec.ts',
23
- ],
24
- stopSpecOnExpectationFailure: false,
25
- });
26
- // Run all or a single unit-test
27
- let doneInfo: jasmine.JasmineDoneInfo;
28
- if (!!argv[2]) {
29
- const files = await findFile(argv[2]);
30
- if (files.length === 1) {
31
- doneInfo = await jasmine.execute([files[0]]);
32
- } else {
33
- return logger.err('Test file not found!');
34
- }
35
- } else {
36
- doneInfo = await jasmine.execute();
37
- }
38
- // Wait for tests to finish
39
- if (doneInfo?.overallStatus === 'passed') {
40
- logger.info('All tests have passed :)');
41
- } else if (doneInfo?.overallStatus === 'incomplete') {
42
- logger.warn('Some tests did not complete or were skipped');
43
- } else {
44
- logger.err('At least one test has failed :(');
45
- }
46
- } catch (err: unknown) {
47
- return logger.err(err);
48
- }
49
- })();
50
-
51
-
52
- /******************************************************************************
53
- Functions
54
- ******************************************************************************/
55
-
56
- /**
57
- * Wrap find file in a promise.
58
- */
59
- function findFile(testFile: string): Promise<string[]> {
60
- return new Promise((res, rej) => {
61
- return find.file(testFile + '.spec.ts', './spec', (files: string[]) => {
62
- if (files.length > 0) {
63
- return res(files);
64
- } else {
65
- const err = new Error('Test file not found!');
66
- return rej(err);
67
- }
68
- });
69
- });
70
- }
@@ -1,11 +0,0 @@
1
- {
2
- "spec_dir": "spec",
3
- "spec_files": [
4
- "**/*[sS]pec.ts"
5
- ],
6
- "helpers": [
7
- "helpers/**/*.js"
8
- ],
9
- "stopSpecOnExpectationFailure": false,
10
- "random": true
11
- }