redweb 0.0.1 → 0.0.3

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.
Files changed (3) hide show
  1. package/index.js +12 -9
  2. package/index.test.js +14 -0
  3. package/package.json +5 -3
package/index.js CHANGED
@@ -5,19 +5,19 @@ const path = require('path');
5
5
  const DEFAULT_OPTIONS = {
6
6
  port: 80,
7
7
  bind: '0.0.0.0',
8
- public: ['./public'],
8
+ publicPaths: ['./public'],
9
9
  services: [],
10
10
  listenCallback: undefined
11
11
  }
12
12
 
13
13
  /**
14
- * To get started with WebExpress, simply initialize your WebExpress instance:
14
+ * To get started with RedWeb, simply initialize your RedWeb instance:
15
15
  * ```javascript
16
- * const app = new WebExpress();
16
+ * const app = new RedWeb();
17
17
  * ```
18
18
  * You can also configure it according to your needs:
19
19
  * ```javascript
20
- * const app = new WebExpress({
20
+ * const app = new RedWeb({
21
21
  * port: 3000,
22
22
  * public: [
23
23
  * './pages/my_public_html',
@@ -28,12 +28,15 @@ const DEFAULT_OPTIONS = {
28
28
  * ```
29
29
  *
30
30
  * @param {{port: Number, bind: String, public: Array<String>, services: []}} options
31
- * @return WebExpress
31
+ * @return RedWeb
32
32
  */
33
- export function WebExpress(options = DEFAULT_OPTIONS) {
33
+ function RedWeb(options = DEFAULT_OPTIONS) {
34
34
  const app = express();
35
+ const { publicPaths, port, listenCallback, services } = options;
35
36
  app.use(bodyParser.json());
36
- options.public.forEach((public_path) => app.use(express.static(path.join(__dirname, public_path))));
37
- app.listen(options.port, listenCallback ? listenCallback : () => console.log('WebExpress listening on port ' + options.port));
37
+ publicPaths.forEach((public_path) => app.use(express.static(path.join(__dirname, public_path))));
38
+ app.listen(port, listenCallback ? listenCallback : () => console.log('RedWeb listening on port ' + options.port));
38
39
  return this;
39
- }
40
+ }
41
+
42
+ module.exports = { RedWeb }
package/index.test.js ADDED
@@ -0,0 +1,14 @@
1
+ const { RedWeb } = require('.');
2
+
3
+ jest.mock('express', () => {
4
+ const self = () => ({
5
+ use: jest.fn(),
6
+ listen: jest.fn()
7
+ });
8
+ self.static = jest.fn();
9
+ return self;
10
+ })
11
+
12
+ test('it should create a RedWeb instance', () => {
13
+ expect(RedWeb()).toBeDefined();
14
+ })
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "redweb",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "A way to quickly set up an express server",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "test": "jest"
8
8
  },
9
9
  "keywords": [],
10
10
  "author": "",
@@ -13,6 +13,8 @@
13
13
  "express": "^4.19.2"
14
14
  },
15
15
  "devDependencies": {
16
- "@types/express": "^4.17.21"
16
+ "@types/express": "^4.17.21",
17
+ "@types/jest": "^29.5.12",
18
+ "jest": "^29.7.0"
17
19
  }
18
20
  }