Browse Source

Adding a basic test init

Herton 4 years ago
parent
commit
0b3d4bb8b6
5 changed files with 27 additions and 4 deletions
  1. 1 1
      README.md
  2. 2 2
      package.json
  3. 1 1
      public/index.html
  4. 0 0
      server.js
  5. 23 0
      test.js

+ 1 - 1
README.md

@@ -1,4 +1,4 @@
-# Simple Node Server for a Single Page App
+# Simple Node Server For A Single Page App
 
 This is a very simple node web server with 0 dependencies but a clean structure ready to be built upon.
 

+ 2 - 2
package.json

@@ -4,8 +4,8 @@
   "description": "Single page node server with no dependencies",
   "main": "htmlServer.js",
   "scripts": {
-    "start": "node htmlServer.js",
-    "test": "echo \"Error: no test specified\" && exit 1"
+    "start": "node server.js",
+    "test": "node test.js"
   },
   "keywords": [
     "server",

+ 1 - 1
public/index.html

@@ -16,7 +16,7 @@
 <body>
     <div class="wrapper">
         <img src="favicon-32x32.png" width="16" height="16" alt="icon"/>
-        <p>Basic Node Single file Server Setup</p>
+        <h2>Simple Node Server For A Single Page App</h2>
     </div>
 </body>
 </html>

htmlServer.js → server.js


+ 23 - 0
test.js

@@ -0,0 +1,23 @@
+// Add your own test cases here
+let testNumber = 1;
+const rightTick = "\u2713";
+const wrongTick = "\u2717";
+function test(params, expected, method) {
+    try {
+        var output = method(params);
+    } catch(error) {
+        console.error(error.toString());
+    }
+    let out = '';
+    if (output == expected) {
+        out = `${rightTick} Test #${testNumber}`;
+    } else {
+        out = `${wrongTick} Test #${testNumber}`
+        + ` Expected [${expected.toString()}]`
+        + ` Your output: [${output}]`;
+    }
+    console.log(out);
+    testNumber++;
+}
+
+test('param', true, param => Boolean(param));