From bd4e950be5184ebe6bf91227b77612b554b69558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Thu, 12 Jan 2023 15:55:43 +0100 Subject: [PATCH 1/2] preload assets before running test and mock them --- src/87source.js | 2 +- src/88require.js | 26 +++++++++++++++----------- test/test000.js | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/87source.js b/src/87source.js index 2d75b36284..4a02804133 100755 --- a/src/87source.js +++ b/src/87source.js @@ -19,7 +19,7 @@ yy.Source.prototype.toString = function () { yy.Source.prototype.execute = function (databaseid, params, cb) { // console.log(this.url); var res; - loadFile( + alasql.utils.loadFile( this.url, !!cb, function (data) { diff --git a/src/88require.js b/src/88require.js index ecbfc2c7ed..91325b4ecf 100755 --- a/src/88require.js +++ b/src/88require.js @@ -40,7 +40,7 @@ yy.Require.prototype.execute = function (databaseid, params, cb) { // console.log(this.paths); if (this.paths && this.paths.length > 0) { this.paths.forEach(function (path) { - loadFile(path.value, !!cb, function (data) { + alasql.utils.loadFile(path.value, !!cb, function (data) { res++; // console.log(res,self.paths.length); // console.log(data); @@ -56,16 +56,20 @@ yy.Require.prototype.execute = function (databaseid, params, cb) { this.plugins.forEach(function (plugin) { // If plugin is not loaded already if (!alasql.plugins[plugin]) { - loadFile(alasql.path + '/alasql-' + plugin.toLowerCase() + '.js', !!cb, function (data) { - // Execute all plugins at the same time - res++; - ss += data; - if (res < self.plugins.length) return; - // console.log(346346, ss); - new Function('params,alasql', ss)(params, alasql); - alasql.plugins[plugin] = true; // Plugin is loaded - if (cb) res = cb(res); - }); + alasql.utils.loadFile( + alasql.path + '/alasql-' + plugin.toLowerCase() + '.js', + !!cb, + function (data) { + // Execute all plugins at the same time + res++; + ss += data; + if (res < self.plugins.length) return; + // console.log(346346, ss); + new Function('params,alasql', ss)(params, alasql); + alasql.plugins[plugin] = true; // Plugin is loaded + if (cb) res = cb(res); + } + ); } }); } else { diff --git a/test/test000.js b/test/test000.js index 63894b3fc2..dcaf19b73c 100644 --- a/test/test000.js +++ b/test/test000.js @@ -1,8 +1,48 @@ +const assets = [ + 'dist/alasql-echo.js', + 'dist/alasql-prolog.js', + 'test127.sql', + 'test128.sql', + 'test198-1.sql', + 'test198-2.sql', + 'test203myfn.js1', + 'test203myfn2.js1', + 'test305a.gexf', + 'test306.xml', + 'test306a.xml', +]; + +const fixtures = {}; + if (typeof exports === 'object') { - var assert = require('assert'); + var fs = require('fs'); + var path = require('path'); var alasql = require('..'); + globalThis.fixturesAssets = {}; + assets.forEach((asset) => { + fixtures[asset] = fs.readFileSync(path.join(__dirname, asset), 'utf8'); + }); +} else { + before(async () => { + return Promise.all( + assets.map((asset) => + fetch(asset) + .then((res) => res.text()) + .then((text) => { + fixtures[asset] = text; + }) + ) + ); + }); } +const load = alasql.utils.loadFile; +alasql.utils.loadFile = function (path, asy, cb, err) { + if (asy) return load(...arguments); + const file = assets.find(x => path.split('/').pop() === x.split('/').pop()); + return cb(fixtures[file]) +}; + describe('Test 000 - multiple statements', function () { const test = '000'; // insert test file number From a486a893c425f8653dedc8d68d6680b6b5c84cb2 Mon Sep 17 00:00:00 2001 From: Mathias Wulff Date: Sun, 30 Jul 2023 14:15:54 +1000 Subject: [PATCH 2/2] Rename test000.js to test1610.js --- test/{test000.js => test1610.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{test000.js => test1610.js} (100%) diff --git a/test/test000.js b/test/test1610.js similarity index 100% rename from test/test000.js rename to test/test1610.js