Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"scripts": {
"test": "sh build.sh && yarn test-only",
"test-ci": "(yarn test-format-all || 1) && yarn test-only && yarn install-g && alasql 'select 1 as Succes'",
"test-only": "node node_modules/mocha/bin/mocha.js ./test --reporter dot --bail",
"#test-only": "(command -v bun && bun node_modules/.bin/mocha ./test --reporter dot) || npx bun node_modules/.bin/mocha ./test --reporter dot",
"test-only": "CLAUDECODE=1 bun test test/*.js --bail",
"test-browser": "node test/browserTestRunner.js 7387",
"test-cover": "# istanbul cover -x 'lib/zt/zt.js' --dir test/coverage _mocha",
"build": "yarn format && yarn build-only",
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

console.log('');
console.log(' Running tests on alasql@' + alasql.version);
Expand Down
26 changes: 13 additions & 13 deletions test/test000.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 000 - multiple statements', function () {
const test = '000'; // insert test file number
const testId = '000'; // insert test file number

before(function () {
alasql('create database test' + test);
alasql('use test' + test);
beforeAll(function () {
alasql('create database test' + testId);
alasql('use test' + testId);
});

after(function () {
alasql('drop database test' + test);
afterAll(function () {
alasql('drop database test' + testId);
});

it('A) From single lines', function () {
test('A) From single lines', function () {
var res = [];
res.push(alasql('create table one (a int)'));
res.push(alasql('insert into one values (1),(2),(3),(4),(5)'));
res.push(alasql('select * from one'));
assert.deepEqual(res, [1, 5, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]]);
});

it('B) Multiple statements in one string', function () {
test('B) Multiple statements in one string', function () {
//
var sql = 'create table two (a int);';
sql += 'insert into two values (1),(2),(3),(4),(5);';
Expand All @@ -32,7 +32,7 @@ describe('Test 000 - multiple statements', function () {
assert.deepEqual(res, [1, 5, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]]);
});

it('C) Multiple statements in one string with callback', function (done) {
test('C) Multiple statements in one string with callback', function (done) {
// Please note that first parameter (here `done`) must be called if defined - and is needed when testing async code
var sql = 'create table three (a int);';
sql += 'insert into three values (1),(2),(3),(4),(5);';
Expand Down
16 changes: 8 additions & 8 deletions test/test001.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

function prepareData(defined) {
// alasql('create database test01');
Expand Down Expand Up @@ -117,7 +117,7 @@ function prepareData(defined) {
}

function doTests() {
it('Select 1.1: COUNT', function (done) {
test('Select 1.1: COUNT', function (done) {
var res = alasql(
'SELECT courses.courseid, COUNT(*) AS cnt ' +
' FROM students RIGHT JOIN courses USING courseid GROUP BY courses.courseid ORDER BY courseid'
Expand All @@ -134,7 +134,7 @@ function doTests() {
);
done();
});
it('Select 1.2: LEFT JOIN ON ', function (done) {
test('Select 1.2: LEFT JOIN ON ', function (done) {
var res = alasql(
'SELECT * ' +
' FROM students ' +
Expand All @@ -146,14 +146,14 @@ function doTests() {
assert.equal(res[4].studentname, 'Astrid Carlson');
done();
});
it('Select 1.3: LEFT JOIN', function (done) {
test('Select 1.3: LEFT JOIN', function (done) {
var res = alasql(
'SELECT COLUMN students.schoolid ' + ' FROM students ' + ' LEFT JOIN courses USING courseid'
);
assert.deepEqual([1, 1, 1, 2, 1], res);
done();
});
it('Select 1.4: queryValue', function (done) {
test('Select 1.4: queryValue', function (done) {
var res = alasql('SELECT VALUE COUNT(*) FROM courses, students');
assert.equal(25, res);
done();
Expand Down
10 changes: 5 additions & 5 deletions test/test002.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 02', function () {
it('Create table', function (done) {
test('Create table', function (done) {
alasql('create database test02; use test02;');
alasql('DROP TABLE IF EXISTS schools');
alasql('CREATE TABLE schools (schoolid INT, schoolname STRING)');
Expand Down
69 changes: 30 additions & 39 deletions test/test003.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,71 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
var zt = require('./lib/zt/zt.js');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

var NUMTESTS = 10000;
var testId = 3;

describe('Test 03 - ' + NUMTESTS + 'times', function () {
describe.skip('Test 03 - ' + testId + 'times', function () {
var sql1 = 'CREATE TABLE IF NOT EXISTS schools (schoolid INT, schoolname STRING)';
var sql2 = "INSERT INTO schools (schoolid, schoolname) VALUES (999,'Northern Pacific School')";
var sql3 = "INSERT INTO schools VALUES (998,'Western Pacific School')";

zt('Start', NUMTESTS, function () {});
// zt('Start', testId, function () {});

it('0. Create table', function (done) {
test('0. Create table', function (done) {
alasql('create database test03; use test03');
alasql('drop table if exists schools');
var res = alasql(sql1);
assert.equal(res, 1, 'CREATE TABLE should return 1');
done();
});

it('1. Test insert with columns ', function (done) {
zt('Test insert with columns', function () {
alasql(sql2);
});
test('1. Test insert with columns ', function (done) {
var res = alasql(sql2);
assert.equal(res, 1, 'INSERT should affect 1 row');
done();
});

it('2. Test insert without columns', function (done) {
zt('Test insert without columns ', function () {
alasql(sql3);
});
test('2. Test insert without columns', function (done) {
var res = alasql(sql3);
assert.equal(res, 1, 'INSERT should affect 1 row');
done();
});

it('3. Test insert without compilation #1', function (done) {
this.timeout(5000);
zt('Test insert without compilation #1', function () {
alasql(sql3);
});
test('3. Test insert without compilation #1', function (done) {
var res = alasql(sql3);
assert.equal(res, 1, 'INSERT should affect 1 row');
done();
});

it('4. Test insert without compilation and caching', function (done) {
this.timeout(5000);
zt('Test insert without compilation and caching', function () {
alasql(sql3.replace('999', (Math.random() * 1000) | 0));
});
test('4. Test insert without compilation and caching', function (done) {
var res = alasql(sql3.replace('999', (Math.random() * 1000) | 0));
assert.equal(res, 1, 'INSERT should affect 1 row');
done();
});

it('5. Test compiled insert', function (done) {
this.timeout(5000);
test('5. Test compiled insert', function (done) {
var insert1 = alasql.compile(sql3);
zt('Test compiled insert', function () {
insert1();
});
var res = insert1();
assert.equal(res, 1, 'Compiled INSERT should affect 1 row');
done();
});

it('6. Test compiled insert with parameters', function (done) {
test('6. Test compiled insert with parameters', function (done) {
var insert2 = alasql.compile('INSERT INTO schools VALUES (?,?)');
zt('Test compiled insert with parameters', function () {
insert2([1, 'Canterberry High School']);
});
var res = insert2([1, 'Canterberry High School']);
assert.equal(res, 1, 'Compiled INSERT with params should affect 1 row');
done();
});

it('COUNT(*)', function (done) {
test('COUNT(*)', function (done) {
var res = alasql('SELECT COUNT(*) FROM schools');
// console.log(res);
assert.equal(6 * NUMTESTS, res[0]['COUNT(*)']);
assert.equal(6 * testId, res[0]['COUNT(*)']);
done();
});

it('Drop database', function (done) {
test('Drop database', function (done) {
alasql('drop database test03');
done();
});
Expand Down
12 changes: 6 additions & 6 deletions test/test004.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('004 Callbacks', function () {
it('Callback', function (done) {
test('Callback', function (done) {
alasql('CREATE DATABASE test04;use test04');
// alasql.exec('DROP TABLE IF EXISTS schools');

Expand All @@ -26,7 +26,7 @@ describe('004 Callbacks', function () {
// console.log(888,res);
});

it('Works without params set', function (done) {
test('Works without params set', function (done) {
alasql('VALUE OF SELECT 1', function (data) {
assert.equal(1, data);
done();
Expand Down
10 changes: 5 additions & 5 deletions test/test005.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 05 - DELETE', function () {
it('DELETE WHERE ', function (done) {
test('DELETE WHERE ', function (done) {
alasql('create database test05;use test05');
alasql('DROP TABLE IF EXISTS schools');
var sql1 = 'CREATE TABLE IF NOT EXISTS schools (schoolid INT, schoolname STRING)';
Expand Down
10 changes: 5 additions & 5 deletions test/test006.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 06', function () {
it('Fiddle test ', function (done) {
test('Fiddle test ', function (done) {
var db = new alasql.Database();

db.exec('CREATE TABLE person (name STRING, sex STRING, income INT)');
Expand Down
10 changes: 5 additions & 5 deletions test/test007.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 007', function () {
it('UPDATE WHERE test ', function (done) {
test('UPDATE WHERE test ', function (done) {
var db = new alasql.Database('test007');

db.exec('CREATE TABLE test (a INT, b INT, c INT)');
Expand Down
10 changes: 5 additions & 5 deletions test/test008.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 08', function () {
it('UPDATE WHERE with conditions test ', function (done) {
test('UPDATE WHERE with conditions test ', function (done) {
var db = new alasql.Database();

db.exec('CREATE TABLE test (a INT, b INT, c INT)');
Expand Down
10 changes: 5 additions & 5 deletions test/test009.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 09', function () {
it('Test LEFT JOIN', function (done) {
test('Test LEFT JOIN', function (done) {
alasql.exec('DROP TABLE IF EXISTS test');
alasql.exec('CREATE TABLE test (a int, b int)');
alasql.exec('INSERT INTO test VALUES (1,1)');
Expand Down
10 changes: 5 additions & 5 deletions test/test010.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 10', function () {
it('Test JOIN ON variations', function (done) {
test('Test JOIN ON variations', function (done) {
alasql.exec('DROP TABLE IF EXISTS test1');
alasql.exec('DROP TABLE IF EXISTS test2');

Expand Down
10 changes: 5 additions & 5 deletions test/test011.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 11', function () {
it('Test compile with parameters', function (done) {
test('Test compile with parameters', function (done) {
alasql.exec('DROP TABLE IF EXISTS test');

alasql.exec('CREATE TABLE test (a int, b int)');
Expand Down
10 changes: 5 additions & 5 deletions test/test012.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}
// @ts-ignore
import {describe, expect, test, beforeAll, afterAll} from 'bun:test';
import assert from 'assert';
import alasql from '..';

describe('Test 12', function () {
it('store and restore - test not ready yet! ', function (done) {
test('store and restore - test not ready yet! ', function (done) {
if (false) {
var db = alasql.restore('mydb');
// console.log(!!db);
Expand Down
Loading
Loading