Skip to content

Commit

Permalink
Started integration test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsharman committed May 20, 2024
1 parent 38c9bc2 commit 961ed2d
Show file tree
Hide file tree
Showing 10 changed files with 11,015 additions and 2,745 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
9 changes: 9 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"checkJs": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
13,390 changes: 10,661 additions & 2,729 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@caspingus/lt",
"version": "2.8.3",
"version": "2.9.0",
"description": "A utility library of helpers and tools for working with Learnosity APIs.",
"main": "src/index.js",
"author": "michael@learnosity.com",
Expand All @@ -19,23 +19,33 @@
},
"homepage": "https://michaelsharman.github.io/LT/",
"devDependencies": {
"@babel/preset-env": "^7.24.5",
"@types/jest": "^29.5.12",
"babel-jest": "^29.7.0",
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^6.10.0",
"docdash": "^2.0.2",
"ejs": "^3.1.10",
"express": "^4.19.2",
"jest": "^29.6.4",
"learnosity-sdk-nodejs": "github:Learnosity/learnosity-sdk-nodejs",
"nodemon": "^3.1.0",
"npm": "^10.7.0",
"puppeteer": "^22.8.1",
"style-loader": "^3.3.4",
"svg-inline-loader": "^0.8.2",
"webpack": "^5.59.1",
"webpack-cli": "^4.9.1"
"webpack-cli": "^4.9.1",
"webpack-version-file": "^0.1.7"
},
"scripts": {
"dev": "npm install && webpack watch --mode development --devtool eval-source-map",
"prod": "npm install && webpack --mode production",
"docs": "jsdoc -c jsdoc.json -R README.md --verbose",
"test": "jest --verbose"
},
"jest": {
"collectCoverage": true
"test": "jest --verbose",
"start:server": "nodemon ./tests/api-server/src/server.js",
"start:server:background": "nodemon ./tests/api-server/src/server.js &"
},
"dependencies": {
"entities": "^4.5.0",
Expand Down
10 changes: 0 additions & 10 deletions test/logger.test.js

This file was deleted.

6 changes: 6 additions & 0 deletions tests/api-server/public/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LT } from './src/assessment/core.js';

window.launch = function (app) {
LT.init(app);
window.LT = LT;
};
60 changes: 60 additions & 0 deletions tests/api-server/src/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const express = require('express');
const net = require('net');
const path = require('path');
const signature = require('./signature');

const app = express();
const PORT = process.env.PORT || 5150;
let server;

app.set('view engine', 'ejs');
app.set('views', './tests/api-server/src/views');
app.use(express.static('./tests/api-server/public'));
app.use('/src', express.static(path.join(__dirname, '../../../src')));
app.use('/dist', express.static(path.join(__dirname, '../../../dist')));
app.use('/src', (req, res, next) => {
if (req.path.indexOf('.js', req.path.length - 3) === -1) {
// If the request does not end in '.js', append '.js' and try to resolve the file
const jsPath = path.join(__dirname, '../../../src', `${req.path}.js`);
res.sendFile(jsPath);
} else {
next();
}
});

// Route for testing LT modules (initalises Items API)
app.get('/itemsapi', (req, res) => {
const signatureData = signature.itemsApi();
res.render('itemsapi', { signature: JSON.stringify(signatureData) });
});

function startServer() {
checkServer(PORT, isRunning => {
if (!isRunning) {
console.log('Starting the server...');
server = app.listen(PORT);
}
});
}

function checkServer(port, callback) {
const server = net.createServer();
server.once('error', function (err) {
if (err.code === 'EADDRINUSE') {
callback(true);
}
});

server.once('listening', function () {
server.close();
callback(false);
});

server.listen(port);
}

function stopServer() {
server.close();
}

module.exports = { startServer, stopServer };
31 changes: 31 additions & 0 deletions tests/api-server/src/signature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const LearnositySDK = require('learnosity-sdk-nodejs/index');

function itemsApi() {
const signature = new LearnositySDK().init(
'items',
{
consumer_key: 'yis0TYCu7U9V4o7M',
domain: 'localhost',
},
'74c5fd430cf1242a527f6223aebd42d30464be22',
{
user_id: 'lt-user',
session_id: '4ca30e35-d73a-4135-af33-f9cad7d01652',
activity_id: 'lt_integration_testing',
rendering_type: 'assess',
type: 'local_practice',
name: 'LT integration testing',
items: ['itembranching-demo-open1', 'itembranching-demo-open2', 'itembranching-demo-open3'],
config: {
regions: 'main',
navigation: {
show_intro: false,
},
},
}
);

return signature;
}

module.exports = { itemsApi };
26 changes: 26 additions & 0 deletions tests/api-server/src/views/itemsapi.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<body>
<div id="flag"></div>
<div id="learnosity_assess"></div>
<script src="https://items.learnosity.com?developer"></script>
<script src="./index.mjs" type="module"></script>
<script>
const signature = <%- locals.signature || {} %>;
const itemsApp = LearnosityItems.init(signature, {
readyListener: init,
errorListener: error
});
function init() {
// A DOM element that we can set so the test script knows the API has rendered
document.getElementById('flag').classList.add('has-loaded');
console.log('Items API ready!');
window.launch(itemsApp);
}
function error(e) {
console.log('Items API error', e);
}
</script>
</body>
</html>
Loading

0 comments on commit 961ed2d

Please sign in to comment.