Skip to content

Commit

Permalink
Some updates:
Browse files Browse the repository at this point in the history
- Add test with mocha
- Add webpack test browser
- Update tsconfig to generate typings
  • Loading branch information
jinhduong committed Apr 25, 2018
1 parent d4818cf commit 1001d4d
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 268 deletions.
66 changes: 0 additions & 66 deletions demo/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "LINQ for Javascript, written by TypeScript",
"main": "index.js",
"scripts": {
"test": "mocha -r ts-node/register src/**/*.test.ts"
"test": "mocha -r ts-node/register test/*.ts"
},
"repository": {
"type": "git",
Expand Down
69 changes: 0 additions & 69 deletions src/demo/test.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/test/join.test.tss

This file was deleted.

38 changes: 0 additions & 38 deletions src/test/leftJoin.test.tss

This file was deleted.

27 changes: 0 additions & 27 deletions src/test/selectMany.test.tss

This file was deleted.

26 changes: 0 additions & 26 deletions src/test/source.ts

This file was deleted.

29 changes: 29 additions & 0 deletions test/join.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Queryable } from "../dist";
import { nations, players, continents } from "./source";
import { expect } from "chai";

describe('join', () => {
const query = Queryable.from(players)
.join(nations, (x, y) => x.nationId === y.id)

it('can run', () => {
query.toList().then(data => {
expect(data).not.equal(undefined);
});
});

it('put out {x,y} object have value', () => {
query.toList().then(data => {
expect(data[0].x).not.equal(undefined);
expect(data[0].y).not.equal(undefined);
expect(data[0].y).not.equal(null);
expect(data[0].y).not.equal(null);
});
});

it('cannot over original length', () => {
Promise.all([query.toList(), players]).then((arr: any[]) => {
expect(arr[0].length).not.greaterThan(arr[1].length);
});
})
});
30 changes: 30 additions & 0 deletions test/leftJoin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Queryable } from "../dist";
import { nations, players, continents } from "./source";
import { expect } from "chai";

describe('leftJoin', () => {
const query = Queryable.from(players)
.leftJoin(nations, (x, y) => x.nationId === y.id);

it('can run', () => {
query.toList().then(data => {
expect(data).not.equal(undefined);
});
});

it('all properties in new object is inside input object properties', () => {
Promise.all([query.toList(), players, nations]).then((arr: any[]) => {
const arr0Keys = Object.keys(arr[0][0]);
const arr1Keys = Object.keys(arr[1][0]);
const arr2Keys = Object.keys(arr[2][0]);

arr1Keys.forEach(p => {
expect(arr0Keys.includes(p)).to.equal(true);
})

arr2Keys.forEach(p => {
expect(arr0Keys.includes(p)).to.equal(true);
})
});
})
});
15 changes: 15 additions & 0 deletions test/selectMany.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { players, continents, nations } from './source';
import { expect } from 'chai';
import { Queryable } from '../dist';

describe('selectMany', () => {
const query = Queryable.from(players)
.selectMany(x => x.skills);

it('is fatten list (this case is number)', async () => {
const data: any[] = await query.toList();
data.forEach(item => {
expect(Number.isInteger(item)).to.equal(true)
});
})
});
32 changes: 32 additions & 0 deletions test/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export let players = new Promise<{ name, overall, nationId, skills }[]>((resolve, reject) => {
// skills: attack, stamia, speed, shoot
setTimeout(() => {
resolve([
{ name: 'Ronaldo', overall: 96, nationId: 1, skills: [96, 85, 87, 91] },
{ name: 'Messi', overall: 98, nationId: 2, skills: [97, 85, 91, 93] },
{ name: 'Mbappe', overall: 86, nationId: 3, skills: [89, 81, 95, 83] },
{ name: 'Matial', overall: 81, nationId: 3, skills: [81, 80, 89, 81] },
{ name: 'Salah', overall: 89, nationId: 4, skills: [88, 82, 97, 86] }
]);
}, 1000);
})

export let nations = new Promise<{ id, name, areaId }[]>(resolve => {
setTimeout(() => {
resolve([
{ id: 1, name: 'Portugal', areaId: 1 },
{ id: 2, name: 'Argentina', areaId: 2 },
{ id: 3, name: 'France', areaId: 1 },
{ id: 4, name: 'Egypt', areaId: 3 }
]);
}, 2000);
})

export let continents = new Promise<{ id, areaName }[]>(resolve => {
setTimeout(() => {
resolve([
{ id: 1, areaName: 'Euro' },
{ id: 2, areaName: 'South America' },
]);
}, 2300);
})

0 comments on commit 1001d4d

Please sign in to comment.