express-generator-typescript 2.6.3 → 2.7.1

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
  }
@@ -43,6 +43,13 @@ function saveDb(db: IDb): Promise<void> {
43
43
  return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), db);
44
44
  }
45
45
 
46
+ /**
47
+ * Empty the database
48
+ */
49
+ function cleanDb(): Promise<void> {
50
+ return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), {});
51
+ }
52
+
46
53
 
47
54
  /******************************************************************************
48
55
  Export default
@@ -51,4 +58,5 @@ function saveDb(db: IDb): Promise<void> {
51
58
  export default {
52
59
  openDb,
53
60
  saveDb,
61
+ cleanDb,
54
62
  } as const;
@@ -1 +1,22 @@
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
+ {
2
+ "users": [
3
+ {
4
+ "id": 752712205078,
5
+ "name": "Bill",
6
+ "created": "2025-04-30T18:42:44.406Z",
7
+ "email": "sean.maxwell@gmail.com"
8
+ },
9
+ {
10
+ "id": 874707860804,
11
+ "name": "John Smith",
12
+ "created": "2025-04-30T18:42:44.406Z",
13
+ "email": "john.smith@gmail.com"
14
+ },
15
+ {
16
+ "id": 299903074095,
17
+ "name": "Gordan Freeman",
18
+ "created": "2025-04-30T18:42:44.406Z",
19
+ "email": "gordan.freeman@gmail.com"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,16 @@
1
+ import { Response } from 'supertest';
2
+
3
+
4
+ /******************************************************************************
5
+ Types
6
+ ******************************************************************************/
7
+
8
+ // Use generics to add properties to 'body'
9
+ export type TRes<T = object> = Omit<Response, 'body'> & {
10
+ body: T & { error?: string | IErrObj },
11
+ };
12
+
13
+ interface IErrObj {
14
+ message: string;
15
+ [key: string]: unknown;
16
+ }
@@ -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,26 @@
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 MockOrm from '@src/repos/MockOrm';
8
+
9
+
10
+ /******************************************************************************
11
+ Run
12
+ ******************************************************************************/
13
+
14
+ let agent: TestAgent<Test>;
15
+
16
+ beforeAll(async () => {
17
+ agent = supertest.agent(app);
18
+ await MockOrm.cleanDb();
19
+ });
20
+
21
+
22
+ /******************************************************************************
23
+ Export
24
+ ******************************************************************************/
25
+
26
+ 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,11 @@ 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();
47
+ await UserRepo.deleteAllUsers();
51
48
  dbUsers = await UserRepo.insertMult(DB_USERS);
52
49
  });
53
50
 
@@ -56,14 +53,10 @@ describe('UserRouter', () => {
56
53
 
57
54
  // Success
58
55
  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
- });
56
+ `of "${HttpStatusCodes.OK}" if the request was successful.`, async () => {
57
+ const res: TRes<{ users: IUser[]}> = await agent.get(Paths.Users.Get);
58
+ expect(res.status).toBe(HttpStatusCodes.OK);
59
+ expect(compareUserArrays(res.body.users, DB_USERS)).toBeTruthy();
67
60
  });
68
61
  });
69
62
 
@@ -72,31 +65,21 @@ describe('UserRouter', () => {
72
65
 
73
66
  // Test add user success
74
67
  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
- });
68
+ 'request was successful.', async () => {
69
+ const user = User.new({ name: 'a', email: 'a@a.com' }),
70
+ res = await agent.post(Paths.Users.Add).send({ user });
71
+ expect(res.status).toBe(HttpStatusCodes.CREATED);
84
72
  });
85
73
 
86
74
  // Missing param
87
75
  it('should return a JSON object with an error message of and a status ' +
88
76
  `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
- });
77
+ 'missing.', async () => {
78
+ const res: TRes = await agent.post(Paths.Users.Add).send({ user: null });
79
+ expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
80
+ const errorObj = parseValidationErr(res.body.error);
81
+ expect(errorObj.message).toBe(ValidationError.MESSAGE);
82
+ expect(errorObj.errors[0].prop).toBe('user');
100
83
  });
101
84
  });
102
85
 
@@ -105,81 +88,59 @@ describe('UserRouter', () => {
105
88
 
106
89
  // Success
107
90
  it(`should return a status code of "${HttpStatusCodes.OK}" if the ` +
108
- 'request was successful.', done => {
91
+ 'request was successful.', async () => {
109
92
  const user = DB_USERS[0];
110
93
  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
- });
94
+ const res = await agent.put(Paths.Users.Update).send({ user });
95
+ expect(res.status).toBe(HttpStatusCodes.OK);
118
96
  });
119
97
 
120
98
  // Id is the wrong data type
121
99
  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 => {
100
+ `of "${HttpStatusCodes.BAD_REQUEST}" if the user param was missing`,
101
+ async () => {
124
102
  const user = User.new();
125
103
  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
- });
104
+ const res: TRes = await agent.put(Paths.Users.Update).send({ user });
105
+ expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
106
+ const errorObj = parseValidationErr(res.body.error);
107
+ expect(errorObj.message).toBe(ValidationError.MESSAGE);
108
+ expect(errorObj.errors[0].prop).toBe('user');
109
+ expect(errorObj.errors[0].children?.[0].prop).toBe('id');
137
110
  });
138
111
 
139
112
  // User not found
140
113
  it('should return a JSON object with the error message of ' +
141
114
  `"${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
- });
115
+ `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, async () => {
116
+ const user = User.new({ id: 4, name: 'a', email: 'a@a.com' }),
117
+ res: TRes = await agent.put(Paths.Users.Update).send({ user });
118
+ expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
119
+ expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
152
120
  });
153
121
  });
154
122
 
155
123
  // Delete User
156
124
  describe(`"DELETE:${Paths.Users.Delete}"`, () => {
157
125
 
158
- const getPath = (id: number) => insertUrlParams(Paths.Users.Delete, { id });
126
+ const getPath = (id: number) => insertUrlParams(Paths.Users.Delete,
127
+ { id });
159
128
 
160
129
  // Success
161
130
  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
- });
131
+ 'request was successful.', async () => {
132
+ const id = dbUsers[0].id,
133
+ res = await agent.delete(getPath(id));
134
+ expect(res.status).toBe(HttpStatusCodes.OK);
170
135
  });
171
136
 
172
137
  // User not found
173
138
  it('should return a JSON object with the error message of ' +
174
139
  `"${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
- });
140
+ `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, async () => {
141
+ const res: TRes = await agent.delete(getPath(-1));
142
+ expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
143
+ expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
183
144
  });
184
145
  });
185
146
  });
@@ -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.1",
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
- }