From 70e18c763fbfd9bdc2f6d4b9c17dad54634e0ec2 Mon Sep 17 00:00:00 2001 From: mfilipiec Date: Fri, 29 Jul 2022 11:41:04 +0200 Subject: [PATCH] Added node server to listing avilivle tests in browser --- .gitignore | 3 + package.json | 2 + server.js | 30 +++++ tests/initial-test/demo.html | 24 +++- tests/not-working-test/demo.html | 24 +++- views/index.ejs | 220 +++++++++++++++++++++++++++++++ 6 files changed, 291 insertions(+), 12 deletions(-) create mode 100644 server.js create mode 100644 views/index.ejs diff --git a/.gitignore b/.gitignore index e43b0f9..ff714ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .DS_Store +.package-lock.json + +/node_modules \ No newline at end of file diff --git a/package.json b/package.json index 3f9e192..ce24acc 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "classroom for understanding tests", "main": "app.js", "scripts": { + "start": "node ./server", "test": "./node_modules/karma/bin/karma start" }, "repository": { @@ -21,6 +22,7 @@ }, "homepage": "https://github.com/blacklabel/highcharts-tests#readme", "dependencies": { + "ejs": "^3.1.8", "express": "^4.18.1", "highcharts": "^10.1.0", "qunit": "^2.19.1" diff --git a/server.js b/server.js new file mode 100644 index 0000000..174aa7f --- /dev/null +++ b/server.js @@ -0,0 +1,30 @@ +// Server to listing tests + +const path = require('path'), + fs = require('fs'), + express = require('express'), + app = express(), + testsPath = path.join(__dirname, './tests'), + getListOfTests = (urlPath) => fs.readdirSync(urlPath).filter(file => { + return fs.statSync(path.join(urlPath, file)).isDirectory(); + }); + +app.use(express.static(testsPath)); +app.set('view engine', 'ejs'); + +app.get('/', async (req, res) => { + const tests = getListOfTests(testsPath), + currentTest = tests[0]; + + res.render("index", { tests, currentTest }) +}); + +app.get('/tests', async (req, res) => { + const tests = getListOfTests(testsPath); + + res.send(tests) +}); + +app.listen(process.env.PORT || 3000, () => { + console.log('Classroom server available at: http://localhost:3000'); +}); \ No newline at end of file diff --git a/tests/initial-test/demo.html b/tests/initial-test/demo.html index e73f457..ec9f8c7 100644 --- a/tests/initial-test/demo.html +++ b/tests/initial-test/demo.html @@ -1,13 +1,25 @@ - - + + + + + + Initial test + + + + + + + + - - -
+
-
+
+ + \ No newline at end of file diff --git a/tests/not-working-test/demo.html b/tests/not-working-test/demo.html index e73f457..234625a 100644 --- a/tests/not-working-test/demo.html +++ b/tests/not-working-test/demo.html @@ -1,13 +1,25 @@ - - + + + + + + Not working test + + + + + + + + - - -
+
-
+
+ + \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs new file mode 100644 index 0000000..9c14ca8 --- /dev/null +++ b/views/index.ejs @@ -0,0 +1,220 @@ + + + + + + + + + + + QUnit tests + + + + +
+ +
+ + + \ No newline at end of file