Skip to content

Commit

Permalink
test: add unit/integration tests (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba committed Apr 22, 2016
1 parent 498c951 commit 0788e46
Show file tree
Hide file tree
Showing 35 changed files with 1,205 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ gulpfile.babel.js
# logs
/log
npm-debug.log

# tests
/test
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: node_js

node_js:
- "5"

services:
- mysql

before_script:
- cat test/fixtures/data.sql | mysql -u travis
- npm install -g gulp
- npm install -g lux-framework

env:
- NODE_ENV="test"
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Lux

[![Join the chat at https://gitter.im/postlight/lux](https://badges.gitter.im/postlight/lux.svg)](https://gitter.im/postlight/lux?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/postlight/lux.svg?branch=master)](https://travis-ci.org/postlight/lux) [![Join the chat at https://gitter.im/postlight/lux](https://badges.gitter.im/postlight/lux.svg)](https://gitter.im/postlight/lux?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

A MVC style framework for building highly performant, large scale JSON APIs that anybody who knows the JavaScript language and its modern features will understand.

Expand Down Expand Up @@ -159,8 +159,15 @@ npm install

### Testing

Coming Soon!
```bash
git clone https://github.com/postlight/lux
cd lux
npm install
cat test/fixtures/data.sql | mysql -u root -p
npm test
```

*Note:* Make sure you have MySQL installed and accessible on port `3306`.

## Useful Links

Expand Down
29 changes: 28 additions & 1 deletion gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import gulp from 'gulp';
import babel from 'gulp-babel';
import mocha from 'gulp-mocha';
import eslint from 'gulp-eslint';
import uglify from 'gulp-uglify';

import exec from './src/packages/cli/utils/exec';
import rmrf from './src/packages/cli/utils/rmrf';

gulp.task('clean', () => {
Expand All @@ -16,11 +18,36 @@ gulp.task('build', ['lint', 'clean'], () => {
.pipe(gulp.dest('dist'));
});

gulp.task('build:test', ['build'], () => {
return exec('npm install', {
cwd: `${__dirname}/test/test-app`
});
});

gulp.task('lint', () => {
return gulp.src('src/**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('default', ['lint']);
gulp.task('test', ['build:test'], () => {
return gulp.src([
'test/helper.js',
'test/unit/**/*.js',
'test/integration/**/*.js'
], { read: false })
.pipe(
mocha({
bail: true,
timeout: 600000,
require: [
'babel-core/register'
]
})
)
.once('error', () => process.exit(1))
.once('end', () => process.exit());
});

gulp.task('default', ['build']);
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
},
"scripts": {
"start": "lux serve",
"test": "lux test"
"test": "gulp test"
},
"author": "Zachary Golba",
"license": "MIT",
"engines": {
"node": ">= 4.0"
},
"dependencies": {
"ansi-regex": "2.0.0",
"babel-runtime": "6.6.1",
Expand All @@ -31,11 +34,15 @@
"babel-plugin-transform-runtime": "6.6.0",
"babel-preset-es2015": "6.6.0",
"babel-preset-stage-1": "6.5.0",
"chai": "3.5.0",
"eslint": "2.7.0",
"gulp": "3.9.1",
"gulp-babel": "6.1.2",
"gulp-eslint": "2.0.0",
"gulp-mocha": "2.2.0",
"gulp-uglify": "1.5.3",
"isomorphic-fetch": "2.2.1",
"mocha": "2.4.5",
"mysql": "2.10.2"
}
}
85 changes: 85 additions & 0 deletions test/fixtures/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
DROP DATABASE IF EXISTS `lux_test`;
CREATE DATABASE `lux_test` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `lux_test`;
-- MySQL dump 10.13 Distrib 5.6.24, for osx10.8 (x86_64)
--
-- Host: 127.0.0.1 Database: lux_test
-- ------------------------------------------------------
-- Server version 5.7.11

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `author`
--

DROP TABLE IF EXISTS `author`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `author` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `author`
--

LOCK TABLES `author` WRITE;
/*!40000 ALTER TABLE `author` DISABLE KEYS */;
INSERT INTO `author` VALUES (1,'2016-04-16 19:02:28','2016-04-16 19:02:28','New Author 1'),(2,'2016-04-16 19:02:31','2016-04-16 19:02:31','New Author 2');
/*!40000 ALTER TABLE `author` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `post`
--

DROP TABLE IF EXISTS `post`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `post` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`title` varchar(255) DEFAULT NULL,
`body` varchar(255) DEFAULT NULL,
`is_public` tinyint(1) DEFAULT '0',
`author_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `post`
--

LOCK TABLES `post` WRITE;
/*!40000 ALTER TABLE `post` DISABLE KEYS */;
INSERT INTO `post` VALUES (1,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 1','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(2,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 2','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(3,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 5','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(4,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 3','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(5,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 6','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(6,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 4','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(7,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 7','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(8,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 12','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(9,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 11','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(10,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 10','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(11,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 8','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(12,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 9','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(13,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 13','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(14,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 14','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(15,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 15','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(16,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 17','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(17,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 16','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(18,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 19','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(19,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 18','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(20,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 20','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(21,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 23','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(22,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 22','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(23,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 21','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(24,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 24','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(25,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 25','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,1),(26,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 26','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(27,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 27','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(28,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 29','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(29,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 28','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(30,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 31','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(31,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 30','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(32,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 34','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(33,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 35','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(34,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 32','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(35,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 33','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(36,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 36','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(37,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 39','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(38,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 40','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(39,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 41','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(40,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 37','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(41,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 38','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(42,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 42','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(43,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 43','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(44,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 48','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(45,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 46','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(46,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 45','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(47,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 44','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(48,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 47','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(49,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 49','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2),(50,'2016-04-16 19:00:53','2016-04-16 19:10:04','New Post 50','Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',1,2);
/*!40000 ALTER TABLE `post` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2016-04-18 18:20:06
43 changes: 43 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os from 'os';
import path from 'path';
import { spawn } from 'child_process';

import Promise from 'bluebird';

let app;

before(done => {
const testApp = path.join(__dirname, 'test-app');

app = spawn('lux', ['serve'], {
cwd: testApp,
env: {
...process.env,
PWD: testApp
}
});

app.once('error', done);

app.stdout.setEncoding('utf8');
app.stderr.setEncoding('utf8');

app.stdout.on('data', data => {
const isListening = /^.+listening\son\sport\s\d+\n$/g.test(data);

if (isListening) {
done();
}
});

app.stderr.once('data', err => {
err = new Error(err);
done(err);
});
});

after(() => {
if (app) {
app.kill();
}
});
Loading

0 comments on commit 0788e46

Please sign in to comment.