express-generator-typescript 2.7.0 → 2.7.2
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 +1 -1
- package/lib/project-files/src/index.ts +17 -4
- package/lib/project-files/src/models/User.ts +4 -4
- package/lib/project-files/src/repos/MockOrm.ts +8 -0
- package/lib/project-files/src/repos/database.test.json +1 -1
- package/lib/project-files/tests/common/types/index.ts +0 -17
- package/lib/project-files/tests/support/setup.ts +2 -4
- package/lib/project-files/tests/users.test.ts +1 -0
- package/lib/project-files/tsconfig.json +1 -1
- package/package.json +1 -1
- /package/lib/project-files/{vitest.config.ts → vitest.config.mts} +0 -0
package/README-git
CHANGED
|
@@ -63,7 +63,7 @@ $ cd "project name" && npm run dev
|
|
|
63
63
|
|
|
64
64
|
- Run the server in development mode: `npm run dev` or `npm run dev:hot`.
|
|
65
65
|
- Run all unit-tests: `npm run test` or `npm run test:hot`.
|
|
66
|
-
- Run a single unit-test: `npm test --
|
|
66
|
+
- Run a single unit-test: `npm run test -- "name of test file" (i.e. users.test.ts)`.
|
|
67
67
|
- Check for linting errors: `npm run lint`.
|
|
68
68
|
- Build the project for production: `npm run build`.
|
|
69
69
|
- Run the production build: `npm start`.
|
|
@@ -5,10 +5,23 @@ import server from './server';
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
/******************************************************************************
|
|
8
|
-
|
|
8
|
+
Constants
|
|
9
9
|
******************************************************************************/
|
|
10
10
|
|
|
11
|
-
const SERVER_START_MSG = (
|
|
12
|
-
ENV.Port.toString()
|
|
11
|
+
const SERVER_START_MSG = (
|
|
12
|
+
'Express server started on port: ' + ENV.Port.toString()
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/******************************************************************************
|
|
17
|
+
Run
|
|
18
|
+
******************************************************************************/
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
// Start the server
|
|
21
|
+
server.listen(ENV.Port, err => {
|
|
22
|
+
if (!!err) {
|
|
23
|
+
logger.err(err.message);
|
|
24
|
+
} else {
|
|
25
|
+
logger.info(SERVER_START_MSG);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -47,7 +47,7 @@ const parseUser = parseObject<IUser>({
|
|
|
47
47
|
/**
|
|
48
48
|
* New user object.
|
|
49
49
|
*/
|
|
50
|
-
function
|
|
50
|
+
function __new__(user?: Partial<IUser>): IUser {
|
|
51
51
|
const retVal = { ...DEFAULT_USER_VALS(), ...user };
|
|
52
52
|
return parseUser(retVal, errors => {
|
|
53
53
|
throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
|
|
@@ -57,7 +57,7 @@ function newUser(user?: Partial<IUser>): IUser {
|
|
|
57
57
|
/**
|
|
58
58
|
* Check is a user object. For the route validation.
|
|
59
59
|
*/
|
|
60
|
-
function
|
|
60
|
+
function test(arg: unknown, errCb?: TParseOnError): arg is IUser {
|
|
61
61
|
return !!parseUser(arg, errCb);
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -67,6 +67,6 @@ function testUser(arg: unknown, errCb?: TParseOnError): arg is IUser {
|
|
|
67
67
|
******************************************************************************/
|
|
68
68
|
|
|
69
69
|
export default {
|
|
70
|
-
new:
|
|
71
|
-
test
|
|
70
|
+
new: __new__,
|
|
71
|
+
test,
|
|
72
72
|
} as const;
|
|
@@ -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 @@
|
|
|
1
|
-
{"users":[{"id":
|
|
1
|
+
{"users":[{"id":701029715561,"name":"Bill","created":"2025-06-03T15:16:08.805Z","email":"sean.maxwell@gmail.com"},{"id":625166376007,"name":"John Smith","created":"2025-06-03T15:16:08.805Z","email":"john.smith@gmail.com"},{"id":595966642687,"name":"Gordan Freeman","created":"2025-06-03T15:16:08.805Z","email":"gordan.freeman@gmail.com"}]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Response } from 'supertest';
|
|
2
|
-
import UserRepo from '@src/repos/UserRepo';
|
|
3
2
|
|
|
4
3
|
|
|
5
4
|
/******************************************************************************
|
|
@@ -15,19 +14,3 @@ interface IErrObj {
|
|
|
15
14
|
message: string;
|
|
16
15
|
[key: string]: unknown;
|
|
17
16
|
}
|
|
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
|
-
|
|
@@ -4,7 +4,7 @@ import supertest, { Test } from 'supertest';
|
|
|
4
4
|
import TestAgent from 'supertest/lib/agent';
|
|
5
5
|
|
|
6
6
|
import app from '@src/server';
|
|
7
|
-
import
|
|
7
|
+
import MockOrm from '@src/repos/MockOrm';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
/******************************************************************************
|
|
@@ -15,9 +15,7 @@ let agent: TestAgent<Test>;
|
|
|
15
15
|
|
|
16
16
|
beforeAll(async () => {
|
|
17
17
|
agent = supertest.agent(app);
|
|
18
|
-
await
|
|
19
|
-
UserRepo.deleteAllUsers(),
|
|
20
|
-
]);
|
|
18
|
+
await MockOrm.cleanDb();
|
|
21
19
|
});
|
|
22
20
|
|
|
23
21
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
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",
|
|
File without changes
|