@stanlemon/server 0.2.1 → 0.2.5

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/jest.config.js ADDED
@@ -0,0 +1 @@
1
+ export { default } from "@stanlemon/webdev/jest.config.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stanlemon/server",
3
- "version": "0.2.1",
3
+ "version": "0.2.5",
4
4
  "description": "A basic express web server setup.",
5
5
  "author": "Stan Lemon <stanlemon@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -13,21 +13,26 @@
13
13
  "scripts": {
14
14
  "start": "NODE_ENV=development nodemon ./app.js",
15
15
  "lint": "eslint --ext js,jsx,ts,tsx ./",
16
- "lint:format": "eslint --fix --ext js,jsx,ts,tsx ./"
16
+ "lint:format": "eslint --fix --ext js,jsx,ts,tsx ./",
17
+ "test": "jest --detectOpenHandles",
18
+ "test:coverage": "jest --detectOpenHandles --coverage",
19
+ "test:watch": "jest --detectOpenHandles --watch"
17
20
  },
18
21
  "dependencies": {
22
+ "@stanlemon/webdev": "*",
19
23
  "compression": "^1.7.4",
20
24
  "dotenv": "16.0.0",
21
- "express": "^4.17.3",
22
- "express-rate-limit": "^6.3.0",
25
+ "express": "^4.18.1",
26
+ "express-rate-limit": "^6.4.0",
23
27
  "helmet": "^5.0.2",
24
- "http-proxy-middleware": "^2.0.4",
28
+ "http-proxy-middleware": "^2.0.6",
25
29
  "joi": "^17.6.0",
26
- "lodash-es": "^4.17.21",
30
+ "lodash": "^4.17.21",
27
31
  "morgan": "^1.10.0"
28
32
  },
29
33
  "devDependencies": {
30
34
  "@stanlemon/eslint-config": "*",
31
- "nodemon": "^2.0.15"
35
+ "@types/lodash": "^4.14.182",
36
+ "nodemon": "^2.0.16"
32
37
  }
33
38
  }
@@ -37,10 +37,7 @@ export function asyncJsonHandler(fn) {
37
37
  return;
38
38
  }
39
39
 
40
- if (
41
- process.env.NODE_ENV === "development" ||
42
- process.env.NODE_ENV === "test"
43
- ) {
40
+ if (process.env.NODE_ENV !== "production") {
44
41
  // eslint-disable-next-line no-console
45
42
  console.error(ex);
46
43
 
@@ -1,4 +1,4 @@
1
- import { isObject, isArray, isString } from "lodash-es";
1
+ import { isObject, isString } from "lodash-es";
2
2
 
3
3
  export default function convertCase(obj, me, convert) {
4
4
  if (
@@ -8,9 +8,9 @@ export default function convertCase(obj, me, convert) {
8
8
  )
9
9
  ) {
10
10
  return new Date(obj);
11
- } else if (isArray(obj)) {
11
+ } else if (Array.isArray(obj)) {
12
12
  return obj.map((i) => me(i));
13
- } else if (isObject(obj) && !isArray(obj)) {
13
+ } else if (isObject(obj) && !Array.isArray(obj)) {
14
14
  const n = {};
15
15
  Object.keys(obj).forEach((k) => (n[convert(k)] = me(obj[k])));
16
16
  return n;
@@ -0,0 +1,30 @@
1
+ import convertCase from "./convertCase";
2
+ import { snakeCase } from "lodash-es";
3
+
4
+ describe("convertCase()", () => {
5
+ const convert = (obj) => convertCase(obj, convert, snakeCase);
6
+
7
+ it("converts object keys", async () => {
8
+ expect(convert({ fooBar: true }, convertCase, snakeCase)).toEqual({
9
+ foo_bar: true,
10
+ });
11
+ });
12
+
13
+ it("converts an array of object keys", async () => {
14
+ expect(convert([{ fooBar: true }], convertCase, snakeCase)).toEqual([
15
+ {
16
+ foo_bar: true,
17
+ },
18
+ ]);
19
+ });
20
+
21
+ it("does not convert strings", async () => {
22
+ expect(convert("hereIsAString", convertCase, snakeCase)).toEqual(
23
+ "hereIsAString"
24
+ );
25
+ });
26
+
27
+ it("does not convert anything else", async () => {
28
+ expect(convert(true, convertCase, snakeCase)).toEqual(true);
29
+ });
30
+ });
@@ -33,7 +33,11 @@ export default function createAppServer(options) {
33
33
  app.use(helmet());
34
34
  }
35
35
 
36
- if (webpack !== false && process.env.NODE_ENV !== "production") {
36
+ if (
37
+ webpack !== false &&
38
+ process.env.NODE_ENV !== "production" &&
39
+ process.env.NODE_ENV !== "test"
40
+ ) {
37
41
  app.get(
38
42
  "/*.js",
39
43
  createProxyMiddleware({
@@ -68,7 +72,8 @@ export default function createAppServer(options) {
68
72
  });
69
73
  });
70
74
 
71
- if (start) {
75
+ // If we're set to start. Btw we never start in test.
76
+ if (start && process.env.NODE_ENV !== "test") {
72
77
  const server = app.listen(port);
73
78
 
74
79
  /* eslint-disable no-console */
@@ -1,8 +1,8 @@
1
- import { isArray, snakeCase } from "lodash-es";
1
+ import { snakeCase } from "lodash-es";
2
2
  import convertCase from "./convertCase.js";
3
3
 
4
4
  export default function formatInput(obj) {
5
- if (isArray(obj)) {
5
+ if (Array.isArray(obj)) {
6
6
  return obj.map((v) => formatInput(v));
7
7
  }
8
8
  return convertCase(obj, formatInput, snakeCase);
@@ -0,0 +1,31 @@
1
+ import formatInput from "./formatInput";
2
+
3
+ describe("formatInput()", () => {
4
+ it("formats object keys", async () => {
5
+ expect(formatInput({ fooBar: true })).toEqual({
6
+ foo_bar: true,
7
+ });
8
+ });
9
+
10
+ it("formats an array of object keys", async () => {
11
+ expect(formatInput([{ fooBar: true }])).toEqual([
12
+ {
13
+ foo_bar: true,
14
+ },
15
+ ]);
16
+ });
17
+
18
+ it("does not formats strings", async () => {
19
+ expect(formatInput("hereIsAString")).toEqual("hereIsAString");
20
+ });
21
+
22
+ it("does not formats anything else", async () => {
23
+ expect(formatInput(true)).toEqual(true);
24
+ });
25
+
26
+ it("does not change already formatted object keys", async () => {
27
+ expect(formatInput({ foo_bar: true })).toEqual({
28
+ foo_bar: true,
29
+ });
30
+ });
31
+ });
@@ -1,11 +1,4 @@
1
- import {
2
- camelCase,
3
- isPlainObject,
4
- isArray,
5
- isDate,
6
- isEmpty,
7
- omit,
8
- } from "lodash-es";
1
+ import { camelCase, isPlainObject, isDate, isEmpty, omit } from "lodash-es";
9
2
  import convertCase from "./convertCase.js";
10
3
 
11
4
  export default function formatOutput(o, omittedFields = []) {
@@ -14,7 +7,7 @@ export default function formatOutput(o, omittedFields = []) {
14
7
  if (isDate(obj)) {
15
8
  return obj.toISOString();
16
9
  }
17
- if (isArray(obj)) {
10
+ if (Array.isArray(obj)) {
18
11
  return obj.map((v) => formatOutput(v));
19
12
  }
20
13
  return convertCase(obj, formatOutput, camelCase);
@@ -0,0 +1,31 @@
1
+ import formatOutput from "./formatOutput";
2
+
3
+ describe("formatOutput()", () => {
4
+ it("formats object keys", async () => {
5
+ expect(formatOutput({ foo_bar: true })).toEqual({
6
+ fooBar: true,
7
+ });
8
+ });
9
+
10
+ it("formats an array of object keys", async () => {
11
+ expect(formatOutput([{ foo_bar: true }])).toEqual([
12
+ {
13
+ fooBar: true,
14
+ },
15
+ ]);
16
+ });
17
+
18
+ it("does not formats strings", async () => {
19
+ expect(formatOutput("hereIsAString")).toEqual("hereIsAString");
20
+ });
21
+
22
+ it("does not formats anything else", async () => {
23
+ expect(formatOutput(true)).toEqual(true);
24
+ });
25
+
26
+ it("does not change already formatted object keys", async () => {
27
+ expect(formatOutput({ fooBar: true })).toEqual({
28
+ fooBar: true,
29
+ });
30
+ });
31
+ });