add tests and gitlab ci

This commit is contained in:
Philipp Kunz 2016-09-11 16:22:53 +02:00
parent 08897a75f2
commit 529d4c155f
13 changed files with 237 additions and 1 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
node_modules/
test/data
pages/
coverage/
public/

43
.gitlab.ci.yml Normal file
View File

@ -0,0 +1,43 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
before_script:
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
- echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
- sudo apt-get update
- sudo apt-get install -y mongodb-org
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
environment: npm_registry
script:
- npmci publish
only:
- tags
tags:
- docker

14
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
/// <reference types="q" />
import * as plugins from './smartdata.plugins';
export declare class DbCollection<T> {
constructor(nameArg: string, db: plugins.mongodb.Db);
}
export declare type TDbConnectionStatus = 'disconnected' | 'connected' | 'failed';
export declare class DbConnection {
dbUrl: string;
db: plugins.mongodb.Db;
status: TDbConnectionStatus;
constructor(dbUrl: string);
connect(): plugins.q.Promise<any>;
close(): plugins.q.Promise<any>;
}

35
dist/index.js vendored Normal file
View File

@ -0,0 +1,35 @@
"use strict";
const plugins = require('./smartdata.plugins');
class DbCollection {
constructor(nameArg, db) {
let collection = db.collection(nameArg);
}
}
exports.DbCollection = DbCollection;
class DbConnection {
constructor(dbUrl) {
this.dbUrl = dbUrl;
}
connect() {
let done = plugins.q.defer();
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
if (err) {
console.log(err);
}
plugins.assert.equal(null, err);
this.db = db;
plugins.beautylog.success(`connected to database at ${this.dbUrl}`);
done.resolve(this.db);
});
return done.promise;
}
close() {
let done = plugins.q.defer();
this.db.close();
plugins.beautylog.ok(`disconnected to database at ${this.dbUrl}`);
done.resolve();
return done.promise;
}
}
exports.DbConnection = DbConnection;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0scUJBRXpCLENBQUMsQ0FGNkM7QUFFOUM7SUFDSSxZQUFZLE9BQWUsRUFBRSxFQUFzQjtRQUMvQyxJQUFJLFVBQVUsR0FBRyxFQUFFLENBQUMsVUFBVSxDQUFDLE9BQU8sQ0FBQyxDQUFBO0lBQzNDLENBQUM7QUFDTCxDQUFDO0FBSlksb0JBQVksZUFJeEIsQ0FBQTtBQUlEO0lBS0ksWUFBWSxLQUFhO1FBQ3JCLElBQUksQ0FBQyxLQUFLLEdBQUcsS0FBSyxDQUFBO0lBQ3RCLENBQUM7SUFFRCxPQUFPO1FBQ0gsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUM1QixPQUFPLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDLEdBQUcsRUFBRSxFQUFFO1lBQ3BELEVBQUUsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUM7Z0JBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQTtZQUFDLENBQUM7WUFDN0IsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFBO1lBQy9CLElBQUksQ0FBQyxFQUFFLEdBQUcsRUFBRSxDQUFBO1lBQ1osT0FBTyxDQUFDLFNBQVMsQ0FBQyxPQUFPLENBQUMsNEJBQTRCLElBQUksQ0FBQyxLQUFLLEVBQUUsQ0FBQyxDQUFBO1lBQ25FLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFBO1FBQ3pCLENBQUMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVELEtBQUs7UUFDRCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQzVCLElBQUksQ0FBQyxFQUFFLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDZixPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQywrQkFBK0IsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDLENBQUE7UUFDakUsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztBQUNMLENBQUM7QUE1Qlksb0JBQVksZUE0QnhCLENBQUEifQ==

5
dist/smartdata.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
import 'typings-global';
export import assert = require('assert');
export import beautylog = require('beautylog');
export import mongodb = require('mongodb');
export import q = require('q');

7
dist/smartdata.plugins.js vendored Normal file
View File

@ -0,0 +1,7 @@
"use strict";
require('typings-global');
exports.assert = require('assert');
exports.beautylog = require('beautylog');
exports.mongodb = require('mongodb');
exports.q = require('q');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBQ1QsY0FBTSxXQUFXLFFBQVEsQ0FBQyxDQUFBO0FBQzFCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUE7QUFDaEMsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFBO0FBQzVCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQSJ9

View File

@ -3,6 +3,7 @@
"version": "1.0.0", "version": "1.0.0",
"description": "do more with data", "description": "do more with data",
"main": "dist/index.js", "main": "dist/index.js",
"typings":"dist/index.d.ts",
"scripts": { "scripts": {
"test": "(npmts)" "test": "(npmts)"
}, },
@ -15,5 +16,20 @@
"bugs": { "bugs": {
"url": "https://gitlab.com/pushrocks/smartdata/issues" "url": "https://gitlab.com/pushrocks/smartdata/issues"
}, },
"homepage": "https://gitlab.com/pushrocks/smartdata#README" "homepage": "https://gitlab.com/pushrocks/smartdata#README",
"dependencies": {
"@types/mongodb": "^2.1.32",
"@types/q": "0.0.30",
"beautylog": "^5.0.23",
"mongodb": "^2.2.9",
"q": "^1.4.1",
"typings-global": "^1.0.14"
},
"devDependencies": {
"@types/shelljs": "^0.3.30",
"@types/should": "^8.1.29",
"shelljs": "^0.7.4",
"should": "^11.1.0",
"typings-test": "^1.0.3"
}
} }

1
test/test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import 'typings-test';

29
test/test.js Normal file
View File

@ -0,0 +1,29 @@
"use strict";
require('typings-test');
const shelljs = require('shelljs');
const smartdata = require('../dist/index');
let mongoChildProcess;
let testDbConnection;
describe('mongodb', function () {
it('should start mongodb', function (done) {
mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017', { async: true });
setTimeout(() => { done(); }, 1500);
});
});
describe('smartdata', function () {
it('should establish a connection to mongodb', function (done) {
testDbConnection = new smartdata.DbConnection('mongodb://localhost:27017/smartdata');
testDbConnection.connect().then(() => { done(); });
});
it('should create a collection', function () {
});
it('should close the db Connection', function () {
testDbConnection.close();
});
});
describe('mongodb', function () {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0FBQyw0QkFBNEIsRUFBQztJQUVoQyxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyxnQ0FBZ0MsRUFBQztRQUNoQyxnQkFBZ0IsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBO0FBRUYsUUFBUSxDQUFDLFNBQVMsRUFBQztJQUNmLEVBQUUsQ0FBQyxxQkFBcUIsRUFBQztRQUNyQixpQkFBaUIsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDckMsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9

34
test/test.ts Normal file
View File

@ -0,0 +1,34 @@
import 'typings-test'
import * as shelljs from 'shelljs'
import * as should from 'should'
import * as smartdata from '../dist/index'
let mongoChildProcess
let testDbConnection: smartdata.DbConnection
describe('mongodb',function(){
it('should start mongodb',function(done){
mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017',{async: true})
setTimeout(() => { done() }, 1500)
})
})
describe('smartdata',function(){
it('should establish a connection to mongodb',function(done){
testDbConnection = new smartdata.DbConnection('mongodb://localhost:27017/smartdata')
testDbConnection.connect().then(() => { done() })
})
it('should create a collection',function(){
})
it('should close the db Connection',function(){
testDbConnection.close()
})
})
describe('mongodb',function(){
it('should kill mongodb',function(){
mongoChildProcess.kill('SIGTERM')
})
})

39
ts/index.ts Normal file
View File

@ -0,0 +1,39 @@
import * as plugins from './smartdata.plugins'
export class DbCollection<T> {
constructor(nameArg: string, db: plugins.mongodb.Db) {
let collection = db.collection(nameArg)
}
}
export type TDbConnectionStatus = 'disconnected' | 'connected' | 'failed'
export class DbConnection {
dbUrl: string
db: plugins.mongodb.Db
status: TDbConnectionStatus
constructor(dbUrl: string) {
this.dbUrl = dbUrl
}
connect(): plugins.q.Promise<any> {
let done = plugins.q.defer()
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
if (err) { console.log(err) }
plugins.assert.equal(null, err)
this.db = db
plugins.beautylog.success(`connected to database at ${this.dbUrl}`)
done.resolve(this.db)
})
return done.promise
}
close(): plugins.q.Promise<any> {
let done = plugins.q.defer()
this.db.close()
plugins.beautylog.ok(`disconnected to database at ${this.dbUrl}`)
done.resolve()
return done.promise
}
}

5
ts/smartdata.plugins.ts Normal file
View File

@ -0,0 +1,5 @@
import 'typings-global'
export import assert = require('assert')
export import beautylog = require('beautylog')
export import mongodb = require('mongodb')
export import q = require('q')

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}