-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from express-promise-router/default-export
Default Export
- Loading branch information
Showing
15 changed files
with
420 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
var resolve = require('path').resolve; | ||
var assert = require('chai').assert; | ||
var spawnBabel = require('./util/launch-utils').spawnBabel; | ||
var GET = require('./util/http-utils').GET; | ||
|
||
describe('Babel', function() { | ||
it('should run the example and respond', function(done) { | ||
this.timeout(5000); | ||
var js_file = resolve(__dirname, './test-resources/babel-base-case.js'); | ||
var target = spawnBabel(js_file); | ||
var called = false; | ||
|
||
target.stdout.on('data', function(data) { | ||
if (data.toString().indexOf('START') === -1) { | ||
return; | ||
} | ||
|
||
GET('/').then(function() { | ||
called = true; | ||
target.kill('SIGINT'); | ||
}); | ||
}); | ||
|
||
target.stderr.on('data', function(data) { | ||
console.error(data.toString()); | ||
}); | ||
|
||
target.on('close', function() { | ||
assert(called); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
var resolve = require('path').resolve; | ||
var assert = require('chai').assert; | ||
var spawnJavaScript = require('./util/launch-utils').spawnJavaScript; | ||
var GET = require('./util/http-utils').GET; | ||
|
||
describe('CommonJs', function() { | ||
it('should run the example and respond', function(done) { | ||
this.timeout(5000); | ||
var js_file = resolve(__dirname, './test-resources/commonjs-base-case.js'); | ||
var target = spawnJavaScript(js_file); | ||
var called = false; | ||
|
||
target.stdout.on('data', function(data) { | ||
if (data.toString().indexOf('START') === -1) { | ||
return; | ||
} | ||
|
||
GET('/').then(function() { | ||
called = true; | ||
target.kill('SIGINT'); | ||
}); | ||
}); | ||
|
||
target.stderr.on('data', function(data) { | ||
console.error(data.toString()); | ||
}); | ||
|
||
target.on('close', function() { | ||
assert(called); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parserOptions": { | ||
"ecmaVersion": 2015, | ||
"sourceType": "module" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import express from 'express'; | ||
import Router from '../../lib/express-promise-router.js'; | ||
const router = Router(); | ||
|
||
router.get('/', function(req, res) { | ||
res.send('Hi!'); | ||
}); | ||
|
||
const app = express(); | ||
app.use(router); | ||
app.listen(12345); | ||
console.log('START'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var express = require('express'); | ||
var Router = require('../../lib/express-promise-router.js'); | ||
var router = Router(); | ||
|
||
router.get('/', function(req, res) { | ||
res.send('Hi!'); | ||
}); | ||
|
||
var app = express(); | ||
app.use(router); | ||
app.listen(12345); | ||
console.log('START'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/// <reference path="../../index.d.ts"/> | ||
import * as express from 'express'; | ||
import Router from '../../lib/express-promise-router.js'; | ||
const router = Router(); | ||
|
||
router.get('/', function(req, res) { | ||
res.send('Hi!'); | ||
}); | ||
|
||
const app = express(); | ||
app.use(router); | ||
app.listen(12345); | ||
console.log('START'); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var request = require('request-promise'); | ||
var assert = require('chai').assert; | ||
|
||
exports.GET = function(route) { | ||
return request({ url: 'http://localhost:12345' + route, resolveWithFullResponse: true }).then(function(res) { | ||
// Express sends 500 errors for uncaught exceptions (like failed assertions) | ||
// Make sure to still fail the test if an assertion in middleware failed. | ||
assert.equal(res.statusCode, 200); | ||
return res; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var ts = require('typescript'); | ||
var babel = require('babel-core'); | ||
var fs = require('fs'); | ||
var spawn = require('child_process').spawn; | ||
var dirname = require('path').dirname; | ||
|
||
function spawnString(source, dir) { | ||
return spawn('node', ['-e', source], { | ||
cwd: dir, | ||
}); | ||
} | ||
|
||
// path has to be fully qualified | ||
exports.spawnTypeScript = function spawnTypeScript(path) { | ||
var content = fs.readFileSync(path, 'utf-8'); | ||
|
||
var compilerOptions = { | ||
module: ts.ModuleKind.CommonJS, | ||
}; | ||
|
||
var transpiled = ts.transpile(content, compilerOptions); | ||
|
||
return spawnString(transpiled, dirname(path)); | ||
}; | ||
|
||
exports.spawnJavaScript = function spawnJavaScript(path) { | ||
var content = fs.readFileSync(path, 'utf-8'); | ||
|
||
return spawnString(content, dirname(path)); | ||
}; | ||
|
||
exports.spawnBabel = function spawnBabel(path) { | ||
var content = fs.readFileSync(path, 'utf-8'); | ||
|
||
var result = babel.transform(content, { | ||
plugins: ['transform-es2015-modules-commonjs'], | ||
}); | ||
|
||
return spawnString(result.code, dirname(path)); | ||
}; |
Oops, something went wrong.