Skip to content

Commit

Permalink
Merge pull request #17 from Will-create/main
Browse files Browse the repository at this point in the history
Updated Html Parser and fix other unit tests
  • Loading branch information
petersirka authored Feb 19, 2025
2 parents a9eda2a + d754c7d commit b46c69b
Show file tree
Hide file tree
Showing 88 changed files with 3,828 additions and 817 deletions.
1 change: 1 addition & 0 deletions helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const options = {};
// options.livereload = 'https://yourhostname';
// options.watcher = false; // disables watcher
// options.edit = 'wss://www.yourcodeinstance.com/?id=projectname'

options.release = process.argv.includes('--release');

// Service mode:
Expand Down
1 change: 1 addition & 0 deletions tests/bundles/.bundleignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run.js
3 changes: 3 additions & 0 deletions tests/bundles/app/.bundleignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./run.js/
./app/
./app/*
6 changes: 6 additions & 0 deletions tests/bundles/app/app.bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/controllers/ : #
/public/ : #
/.bundleignore : H4sIAAAAAAAAE9PTLyrN08sq1ufS008sKIBRWgCG50NNGAAAAA==
/app.bundle : H4sIAAAAAAAAE9NPzs8rKcrPyUktKtZXoA2wUlDm0i8oTcrJTKaVFQh79JJK81JyUjPT8/KLUmllj4dJsacjFLhaBoT4VBb5GVgUFxqWpgUbGFgUe3s6BYWnO7ubGvj5uYNV2dpy6ScWFEBdRxt3gZ0GAEXOJ6DRAQAA
/controllers/default.js : H4sIAAAAAAAAE4VRTU/jMBA9O79iVqoUV6rSOxUHDnxcVqDdoD2sOLjJFAaccRjbhQry31HcNv2AZeXLjEfz3rz38LV1EnxB7IOxFk5hEbkK5FiP4S1Tv65vy3OdX56XMM0nu+EoTdWoaK0h1vkVWuvgjxNb5+NZprrxLBu2b65/lzCdR64t+mmDco9fgS2NQGtW1pkaTmFUzF29mmVK0QL0j82gqBwH5ADv7zD8LcgimwbXMGpUEC+NpVrnP8l74nugppdpOEAPCq0R02BA8bDdBcM1bMCTAqUEQxTuyy5T/VM3Z+VV0TzVJDqV4lzQeRvnlqrpo8/HabF0wdjiwhcvQgEvyKI+vnQCR3r23ECRjZBeeN/1tQoP4l4ARWZrjY/esX4DH6sKvT+BIBEnsDQ24gkc80GXLuu20ajDZLfRCDZu+c9sniPKKiWTqiGa1H0Twt/t6A7Ig+BzJMEaiDeIuzS+Nn5te2RL/KQPyQ5tc0fGDf3eNevvRLPHMyT8P2MP6T/b2n0Aqn2R41EDAAA=
/public/ui.js : H4sIAAAAAAAAE0vOzyvOz0nVy8lP11APyS9JzNHLKlYI9VTXtAYA+drsIhsAAAA=
40 changes: 40 additions & 0 deletions tests/bundles/app/controllers/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
exports.install = function() {
ROUTE('GET /', function($) {
$.plain('Hello World');
});

ROUTE('POST /bundles/merge/', function($) {
var payload = $.body;
if (!payload.content || !payload.filename) {
$.invalid('Missing important body parameters filename and content');
return;
}


PATH.mkdir(PATH.root('public/js'));
Total.Fs.writeFile(payload.filename, payload.content, function(err) {
if (err)
throw err;
$.json({ success: true, value: payload.filename });
});
});

ROUTE('GET /bundles/remove/', function($) {
var query = $.query;
if (!query.filename) {
$.invalid('[filename] is required in query parameters');
return;
}

PATH.unlink(query.filename, function(error) {
if (error) {
$.invalid(error);
return;
}


$.json({ success: true, value: query.filename });
});
});

}
1 change: 1 addition & 0 deletions tests/bundles/app/public/ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Total.js UI');
45 changes: 10 additions & 35 deletions tests/bundles/index.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,23 @@
/* eslint-disable */
require('../../index');
require('../../test');
var worker = NEWTHREAD();

// Unpack bundle in bundles directory + download bundles from URL (we can add a test bundle to our CDN)
// Merging files
// Removing files

// load web server and test app
CONF.$imprint = false;
F.http();

var url = 'http://localhost:8000/';
var filename = 'openreports.bundle';
var bundle_link = 'https://raw.githubusercontent.com/totaljs/flow/master/--bundles--/app.bundle';

CONF.$imprint = true;
F.http({ release: true, port: 3000 });
ON('ready', function() {
//console.log('READY');
DEBUG = true;
setTimeout( function() {
worker.postMessage(JSON.stringify({ ready: true }));
setTimeout(process.exit, 1000);
}, 3000);
});

Test.push('Bundles', function(next) {
// Test.print('String.slug()', [error]);
var arr = [];

arr.push(function(resume) {
RESTBuilder.GET(url).exec(function(err, response) {
console.log(err, response);
Test.print('From local', err === null ? null : 'App is not successfully started ');
PATH.unlink(PATH.root('bundles/' + filename), function() {
F.restart();
resume()
});
});
});

arr.push(function(resume) {
resume();
});

arr.push(function(resume) {
resume();
});

arr.async(function() {
next();
});
});

setTimeout(() => Test.run(), 600);
});
101 changes: 101 additions & 0 deletions tests/bundles/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* eslint-disable */
require('../../index');
require('../../test');

// Unpack bundle in bundles directory + download bundles from URL (we can add a test bundle to our CDN)
// Merging files
// Removing files

// load web server and test app
CONF.$imprint = true;

var url = 'http://localhost:3000/';
var filename = 'app.bundle';
var bundle_link = 'https://raw.githubusercontent.com/totaljs/flow/master/--bundles--/app.bundle';
var trash = ['index.js.map', 'bundles/' + filename];
Test.push('Bundles', function(next) {
var arr = [];

arr.push(function(resume) {
var app = PATH.root('app');
SHELL('cd ' + app + ' && ' + ' total5 bundle app && cp app.bundle ' + PATH.root('bundles/app.bundle'), function(err) {
resume();
});
});

arr.push(async function(resume) {
var child = NEWTHREAD('~./index.js');
child.on('message', function(msg) {
RESTBuilder.GET(url).exec(function(err, response) {
Test.print('From local', err === null ? null : 'App is not successfully started');
resume()
});
});
});

arr.push(function(resume) {
var file = 'console.log(window);';
var filename = PATH.root('/.src/public/js/--ui.js');
RESTBuilder.POST(url + 'bundles/merge', { filename: filename, content: file }).exec(function(err, res, out) {
resume();
});
});

arr.push(function(resume) {
RESTBuilder.GET(url + 'ui.js').callback(function(err, res, output) {
Test.print('Test endpoint', err == null ? null : 'Failed to write merge file');
resume();
});
});

arr.push(function(resume) {
PATH.unlink(PATH.root('bundles/' + filename), function() {
PATH.exists(PATH.root('bundles/' + filename), function(exists) {
Test.print('Remove bundle', !exists ? null : 'Failed to remove the bundle');
resume();
});
});
});

arr.push(function(resume) {
RESTBuilder.GET(bundle_link).callback(function(err, response, output) {
Test.print('Download bundle', err === null ? null : 'Failed to download bundle from CDN' + err);
Total.Fs.writeFile(PATH.root('bundles/' + filename), output.response, function(error) {
Test.print('Save bundle', err === null ? null : 'Failed to save the bundle file' + error);
resume();
});
});
});

arr.push(async function(resume) {
var child = NEWTHREAD('~./index.js');
child.on('message', function(msg) {
// check if at least a known expected file like modules/cdn.js exists in the unpacked bundle
PATH.exists(PATH.root('.src/modules/cdn.js'), function(exists) {
Test.print('Successfully run downloaded bundle', exists ? null : 'Failed to run the downloaded bundle');
resume();
});
});
});

arr.push(function(resume) {
trash.wait(function(item, next) {
var path = PATH.root(item);
PATH.unlink(path, NOOP);
next();
}, function(err) {
PATH.rmdir(PATH.root('.src'), function() {
Test.print('Clean up', !err ? null : 'Failed to Clean up the trash');
resume();
});
});
});

arr.async(function() {
next();
});
});
setTimeout(() => {
Test.run(process.exit);
}, 1000);

88 changes: 82 additions & 6 deletions tests/common/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
require('../../index');
require('../../test');

// @TODO: incomplete test

F.http();

ON('ready', function () {
Test.push('CRON', function (next) {
// 08:10 ---> 27 8 * * *

CRON('{0} * * *'.format(NOW.add('1 minute').format('mm HH')), function () {
Test.print('In 1 minute - success');
Expand All @@ -26,15 +23,94 @@ ON('ready', function () {
Test.print('In 1 minute - Full date 2 - success');
});


CRON('*/1 * * * *'.format(NOW.add('1 minute').format('mm HH dd MM')), function () {
CRON('*/1 * * * *', function () {
Test.print('Every 1 minute - success');
});

CRON('*/2 * * * *'.format(NOW.add('1 minute').format('mm HH dd MM')), function () {
CRON('*/2 * * * *', function () {
Test.print('Every 2 minutes - success');
});

CRON('0 12 * * *', function () {
Test.print('At 12:00 PM daily - success');
});

CRON('0 12 * * 1-5', function () {
Test.print('At 12:00 PM Monday to Friday - success');
});

CRON('0 0 * * 1', function () {
Test.print('At 12:00 AM every Monday - success');
});

CRON('0 */2 * * *', function () {
Test.print('Every 2 hours - success');
});

CRON('0 0 */3 * *', function () {
Test.print('At midnight every 3 days - success');
});

CRON('0 0 1 */2 *', function () {
Test.print('At midnight on the 1st day of every other month - success');
});

CRON('0 0 1 1 *', function () {
Test.print('At midnight on January 1st - success');
});

CRON('0 0 1 1,4,7,10 *', function () {
Test.print('At midnight on January, April, July, and October 1st - success');
});

CRON('0 0 1 1-5 *', function () {
Test.print('At midnight on the 1st to 5th day of every month - success');
});

CRON('0 0 1 * *', function () {
Test.print('At midnight on the 1st day of every month - success');
});

CRON('0 0 1 * *', function () {
Test.print('At midnight on the 1st day of every month - success');
});

CRON('0 0 * * *', function () {
Test.print('At the start of every hour - success');
});

CRON('0 8-17 * * *', function () {
Test.print('Every hour from 8 AM to 5 PM - success');
});

CRON('0 12 * * 1-5', function () {
Test.print('At 12:00 PM from Monday to Friday - success');
});

CRON('0 0 1 */3 *', function () {
Test.print('At midnight on the 1st of every third month - success');
});

CRON('0 0 * * *', function () {
Test.print('At midnight every day - success');
});

CRON('0 0 1 1 *', function () {
Test.print('At midnight on January 1st - success');
});

CRON('0 0 1 * *', function () {
Test.print('At midnight on the 1st day of every month - success');
});

CRON('0 0 * * *', function () {
Test.print('At the start of every hour - success');
});

CRON('0 8-17 * * *', function () {
Test.print('Every hour from 8 AM to 5 PM - success');
});

});

setTimeout(function () {
Expand Down
Loading

0 comments on commit b46c69b

Please sign in to comment.