Skip to content

Commit 963e935

Browse files
committed
build process changes
1 parent c2bc975 commit 963e935

File tree

14 files changed

+245
-227
lines changed

14 files changed

+245
-227
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/nbproject/
2-
/tests/.jsqldatastore
2+
/test/.jsqldatastore
33
.jsqldatastore
44
package-lock.json
5-
node_modules
5+
node_modules
6+
coverage
7+
.coveralls.yml

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
language: node_js
22
node_js:
33
- "node"
4+
script: npm run coverage
5+
after_success: 'npm run coveralls'
File renamed without changes.
File renamed without changes.
File renamed without changes.

coveralls.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
repo_token: 9bgpsLWzkdOMWCgv2HQqoi5B9Lh8ieMXg

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"example": "tests"
88
},
99
"scripts": {
10-
"test": "node ./tests/test1.js && node ./tests/test2.js && node ./tests/test3.js && node ./tests/test4.js && node ./tests/test5.js && node ./tests/test6.js && node ./tests/test7.js"
10+
"test": "node node_modules/.bin/mocha",
11+
"coverage": "node node_modules/.bin/istanbul cover _mocha -- -R spec",
12+
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls"
1113
},
1214
"repository": {
1315
"type": "git",
@@ -34,9 +36,13 @@
3436
},
3537
"homepage": "http://pamblam.github.io/jSQL/",
3638
"devDependencies": {
39+
"chai": "^4.1.2",
40+
"coveralls": "^3.0.0",
3741
"grunt": "^1.0.1",
3842
"grunt-contrib-concat": "^1.0.1",
3943
"grunt-contrib-uglify": "^3.1.0",
40-
"grunt-string-replace": "^1.3.1"
44+
"grunt-string-replace": "^1.3.1",
45+
"istanbul": "^0.4.5",
46+
"mocha": "^4.0.1"
4147
}
4248
}

test/test1.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
var expect = require('chai').expect;
2+
var jSQL = require("../jSQL.js");
3+
4+
jSQL.onError(function(e){
5+
console.log(e.message);
6+
});
7+
8+
jSQL.load(function () {
9+
jSQL.reset();
10+
describe('Lexer/Parser tests', function () {
11+
12+
it('create wtf_test table', function(){
13+
jSQL.query("create table wtf_test (id, name, `somekey` varchar(), something enum('hello','goodbye'), primary key(`id`, name), unique key (somekey) )").execute();
14+
expect((jSQL.tables.wtf_test !== undefined)).to.be.true;
15+
});
16+
17+
it('create typetest table', function(){
18+
jSQL.query("create table typetest (id numeric(3), data json, greet function, active boolean, `number` int(3), code char(4), name varchar(4), created date, anything ambi, something enum('hello','goodbye') )").execute();
19+
expect((jSQL.tables.typetest.colmap.number === 4 && jSQL.tables.typetest.types[9].args[0] === 'hello' && jSQL.tables.typetest.types[9].args[1] === 'goodbye')).to.be.true;
20+
});
21+
22+
it('create keytest table', function(){
23+
jSQL.query("create table keytest (id int auto_increment primary key, data, greet, active, `number`, code, name varchar, created date, anything ambi, something enum('hello','goodbye') )").execute();
24+
expect((jSQL.tables.keytest.keys.primary.column === 'id' && jSQL.tables.keytest.auto_inc_col === 'id')).to.be.true;
25+
});
26+
27+
it('create keytest2 table', function(){
28+
jSQL.query("create table keytest2 (id int auto_increment, data, greet, active, `number`, code, name varchar, created date, anything ambi, something enum('hello','goodbye'), primary key(`id`, name) )").execute();
29+
expect((jSQL.tables.keytest2.keys.primary.column[0] === 'id' && jSQL.tables.keytest2.keys.primary.column[1] === 'name' && jSQL.tables.keytest2.auto_inc_col === 'id')).to.be.true;
30+
});
31+
32+
it('create smalltest table', function(){
33+
jSQL.query("create table `smalltest` (id int, str varchar)").execute();
34+
expect((!!jSQL.tables.smalltest)).to.be.true;
35+
});
36+
37+
it('insert into smalltest table', function(){
38+
jSQL.query("insert into smalltest (id, str) values (7, 'testing')").execute();
39+
expect((jSQL.tables.smalltest.data.length === 1)).to.be.true;
40+
});
41+
42+
it('insert into smalltest table again', function(){
43+
jSQL.query("insert into `smalltest` values (11, 'testing again')").execute();
44+
expect((jSQL.tables.smalltest.data.length === 2)).to.be.true;
45+
});
46+
47+
it('insert into typetest table', function(){
48+
jSQL.query("insert into `typetest` values (11, '{\"greeting\":\"hello\"}', 'function(){console.log(\"hello world\")}', true, 3, '72', 'rob', 'Mon, 25 Dec 1995 13:30:00 +0430', 'scooby doo', \"hello\")").execute();
49+
expect((jSQL.tables.typetest.data.length === 1)).to.be.true;
50+
});
51+
52+
it('insert into keytest2 table', function(){
53+
jSQL.query("insert into `keytest2` (id, `greet`) values (11, 'holla')").execute();
54+
expect((jSQL.tables.keytest2.data[0][0] === 11)).to.be.true;
55+
});
56+
57+
it('insert into keytest2 table again', function(){
58+
jSQL.query("insert into `keytest2` (`greet`) values ('poopums')").execute();
59+
expect((jSQL.tables.keytest2.data[1][0] === 12)).to.be.true;
60+
});
61+
62+
it('select from typetest table', function(){
63+
var res = jSQL.query("select * from `typetest`").execute().fetchAll("ARRAY");
64+
expect((res[0][7] instanceof Date && "function" === typeof res[0][2])).to.be.true;
65+
});
66+
67+
it('select from keytest2 table', function(){
68+
var q = jSQL.query("SELECT id, greet FROM `keytest2` WHERE `id` > 11").execute();
69+
expect((q.fetch("ASSOC").greet === "poopums")).to.be.true;
70+
});
71+
72+
it('select from keytest2 table again', function(){
73+
var q = jSQL.query("SELECT id, greet FROM `keytest2` WHERE `id` < 12").execute();
74+
expect((q.fetch("ASSOC").greet === "holla")).to.be.true;
75+
});
76+
77+
it('select from keytest2 table again again', function(){
78+
var q = jSQL.query("SELECT * FROM `keytest2` WHERE `id` < 12 and greet = 'holla'").execute();
79+
expect((q.fetch("ASSOC").greet === "holla")).to.be.true;
80+
});
81+
82+
it('select from keytest2 table once again', function(){
83+
var q = jSQL.query("SELECT * FROM `keytest2` WHERE `id` < 12 and greet = 'holla' and greet <> \"poo\" or id = 11").execute();
84+
expect((q.fetch("ASSOC").greet === "holla")).to.be.true;
85+
});
86+
87+
it('select from keytest2 table again once again', function(){
88+
var q = jSQL.query("SELECT * FROM `keytest2` WHERE `greet` LIKE '%olla'").execute();
89+
expect((q.fetch("ASSOC").greet === "holla")).to.be.true;
90+
});
91+
92+
it('select from keytest2 table again once again once', function(){
93+
var q = jSQL.query("SELECT * FROM `keytest2` WHERE `greet` LIKE '%o%'").execute();
94+
expect((q.fetchAll("ASSOC").length === 2)).to.be.true;
95+
});
96+
97+
it('select from keytest2 table again once again once more', function(){
98+
var q = jSQL.query("SELECT * FROM `keytest2` WHERE `greet` LIKE 'p%'").execute();
99+
expect((q.fetchAll("ASSOC").length === 1)).to.be.true;
100+
});
101+
102+
it('update keytest2 table', function(){
103+
var q = jSQL.query("update `keytest2` set `greet` = 'yyyyo' where id = 12").execute();
104+
expect((jSQL.tables.keytest2.data[1][2] === 'yyyyo')).to.be.true;
105+
});
106+
107+
it('update keytest2 table again', function(){
108+
var q = jSQL.query("update`keytest2`set`greet`='waddapp',data=\"data\"where`id`=11").execute();
109+
expect((jSQL.tables.keytest2.data[0][2] === 'waddapp' && jSQL.tables.keytest2.data[0][1] === 'data')).to.be.true;
110+
});
111+
112+
it('delete from keytest2 table', function(){
113+
var q = jSQL.query("delete from `keytest2` where `greet` = 'waddapp'").execute();
114+
expect((jSQL.tables.keytest2.data.length === 1)).to.be.true;
115+
});
116+
117+
it('drop keytest2 table', function(){
118+
var q = jSQL.query("drop table `keytest2`").execute();
119+
expect((jSQL.tables.keytest2 === undefined)).to.be.true;
120+
});
121+
122+
});
123+
});

test/test2.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var expect = require('chai').expect;
2+
var jSQL = require("../jSQL.js");
3+
4+
jSQL.onError(function(e){
5+
console.log(e.message);
6+
});
7+
8+
jSQL.load(function () {
9+
jSQL.reset();
10+
describe('FuNkY TaBlE TeSts', function () {
11+
12+
it('inserting inconsistent objects', function(){
13+
jSQL.createTable("oTable", [
14+
{a:1, b:2, c:3, d:4, e:5, f:6, g:7},
15+
{a:2, b:3, c:3, d:54, e:7, f:6},
16+
{a:2, b:3, c:3, d:54, e:7, f:6, g:7, h:"d"}
17+
]).execute();
18+
expect((jSQL.tables.oTable.data.length === 3 && jSQL.tables.oTable.columns.length === 8)).to.be.true;
19+
});
20+
21+
it('dynamically adding columns', function(){
22+
jSQL.createTable("aTable", ["a", "b", "c"]).execute([
23+
[12, 34, 56, 78],
24+
[23, 45, 67, 89, 78, 78],
25+
[7]
26+
]);
27+
expect((jSQL.tables.aTable.data.length === 3 && jSQL.tables.aTable.columns.length === 6)).to.be.true;
28+
});
29+
30+
it('mixing arrays and objects', function(){
31+
jSQL.createTable("ceTable", ['a', 'b', 'c', 'd', 'e', 'f', 'g']).execute([
32+
[12, 34, 56, 78],
33+
[23, 45, 67, 89, 78, 78],
34+
[7], {"a": 1, "b": 2, "g": 3}
35+
]);
36+
expect((jSQL.tables.ceTable.data.length === 4 && jSQL.tables.ceTable.columns.length === 7)).to.be.true;
37+
});
38+
39+
});
40+
});

test/test3.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var expect = require('chai').expect;
2+
var jSQL = require("../jSQL.js");
3+
4+
jSQL.onError(function(e){
5+
console.log(e.message);
6+
});
7+
8+
function hat(type,color){
9+
this.type = type;
10+
this.color = color;
11+
this.getName = function(){
12+
return "a "+this.color+" "+this.type;
13+
};
14+
}
15+
16+
jSQL.types.add({
17+
type: "HAT",
18+
serialize: function(value, args){
19+
return JSON.stringify(value);
20+
},
21+
unserialize: function(value, args){
22+
var o = JSON.parse(value);
23+
return new hat(o.type, o.color);
24+
}
25+
});
26+
27+
jSQL.load(function () {
28+
jSQL.reset();
29+
describe('Custom objects test', function () {
30+
31+
it('storing custom objects', function(){
32+
33+
// create the table and populate it,
34+
// if it does not already exist
35+
var query = jSQL.query("Create table if not exists hatTable "+
36+
"(name varchar(50,5), age int, created date, greet function, favorite_hat hat)");
37+
38+
// execute the query and insert the data
39+
// (if the table doesn't already exist)
40+
query.execute([{
41+
name: "bob",
42+
age: 27,
43+
created: new Date(),
44+
greet: function(){alert("hi!");},
45+
favorite_hat: new hat("cowboy hat","blue")
46+
},{
47+
name: "ned",
48+
age: 29,
49+
created: new Date(),
50+
greet: function(){alert("hello!");},
51+
favorite_hat: new hat("baseball cap","green")
52+
},{
53+
name: "Fred",
54+
age: 34,
55+
created: new Date(),
56+
greet: function(){alert("sup dawg!");},
57+
favorite_hat: new hat("tophat","purple")
58+
}]);
59+
60+
61+
62+
expect((jSQL.tables.hatTable.data.length === 3)).to.be.true;
63+
});
64+
65+
});
66+
});

0 commit comments

Comments
 (0)