-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f95613
commit 4394cab
Showing
12 changed files
with
5,803 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"globals" : { | ||
"define" : true, | ||
"describe" : true, | ||
"xdescribe" : true, | ||
"it" : true, | ||
"xit" : true, | ||
"beforeEach" : true, | ||
"beforeAll" : true, | ||
"afterEach" : true, | ||
"afterAll" : true, | ||
"expect" : true, | ||
"__karma__" : true, | ||
"ynn" : true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"sourceType": "module", | ||
"ecmaVersion" : 2017 | ||
}, | ||
"rules": { | ||
"no-console" : 0, | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ "error", "single" ], | ||
"semi": [ 0 ] | ||
} | ||
} |
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,25 @@ | ||
.*.swp | ||
._* | ||
.DS_Store | ||
.git | ||
.hg | ||
.npmrc | ||
.lock-wscript | ||
.svn | ||
.wafpickle-* | ||
config.gypi | ||
CVS | ||
npm-debug.log | ||
.babelrc | ||
.eslintrc.json | ||
.eslintignore | ||
test | ||
karma.conf.js | ||
rollup.conf.js | ||
node_modules | ||
logs | ||
*.log | ||
log | ||
.audit.json | ||
.tox | ||
.toxrc |
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,32 @@ | ||
# karma-server | ||
|
||
Building a http server for testing easily. Based on [Ynn](https://github.com/ynnjs/ynn); | ||
|
||
## Install | ||
```js | ||
npm i --save-dev karma-server | ||
``` | ||
|
||
## Configuration | ||
|
||
```js | ||
config.set( { | ||
frameworks : [ 'server' ], | ||
server : { | ||
namespace : 'S', | ||
root : 'test/server', | ||
static : 'test/server', | ||
modules : { | ||
home : './home' | ||
} | ||
} | ||
} ) | ||
|
||
``` | ||
|
||
Code in test cases: | ||
```js | ||
it( 'xx', () => { | ||
fetch( S.host ); | ||
} ); | ||
``` |
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,72 @@ | ||
const fs = require( 'fs' ); | ||
const path = require( 'path' ); | ||
const Ynn = require( 'ynn' ); | ||
const is = require( '@lvchengbin/is' ); | ||
|
||
const createServer = ( config, basePath, files, logger ) => { | ||
const log = logger.create( 'server' ); | ||
config || ( config = {} ); | ||
const root = config.root ? path.resolve( basePath, config.root ) : basePath; | ||
const host = config.host || '127.0.0.1'; | ||
const ns = config.namespace || 'server'; | ||
|
||
const app = new Ynn( { | ||
root, | ||
debugging : is.undefined( config.debugging ) ? Ynn.DEBUGGING_ERROR : config.debugging, | ||
modules : config.modules || {}, | ||
logging : Ynn.LOGGING_DISABLE_ALL, | ||
static : { | ||
'/static/home.html' : config.static || root | ||
}, | ||
routers() { | ||
this.router.options( /.*/, async ctx => { | ||
const origin = ctx.request.get( 'origin' ); | ||
ctx.set( 'Access-Control-Allow-Origin', origin ); | ||
if( config[ 'Access-Control-Allow-Headers' ] ) { | ||
ctx.set( 'Access-Control-Allow-Headers', config[ 'Access-Controller-Allow-Headers' ] ); | ||
} | ||
ctx.body = {}; | ||
} ); | ||
|
||
this.router.any( '*', /.*/, async ( ctx, next ) => { | ||
const origin = ctx.request.get( 'origin' ); | ||
ctx.set( 'Access-Control-Allow-Origin', origin ); | ||
if( config[ 'Access-Control-Allow-Headers' ] ) { | ||
ctx.set( 'Access-Control-Allow-Headers', config[ 'Access-Control-Allow-Headers' ] ); | ||
} | ||
return next(); | ||
} ); | ||
} | ||
} ); | ||
const listen = app.listen( config.port ); | ||
const port = listen.address().port; | ||
|
||
const DECLARATION = ` | ||
( function() { | ||
// This file is generated by karma-server. | ||
window.${ns} = window.${ns} || {}; | ||
window.${ns}.time = ${+new Date}; | ||
window.${ns}.port = ${port}; | ||
window.${ns}.host = 'http://${host}:${port}'; | ||
} )(); | ||
`; | ||
|
||
const file = path.join( __dirname, 'server-declaration.js' ); | ||
|
||
fs.writeFileSync( file, DECLARATION ); | ||
|
||
log.info( `Ynn is listening to the port: ${port}. [http://${host}:${port}]` ); | ||
|
||
files.unshift( { | ||
pattern : file, | ||
included : true, | ||
served : true, | ||
watched : false | ||
} ); | ||
|
||
}; | ||
createServer.$inject = [ 'config.server', 'config.basePath', 'config.files', 'logger' ]; | ||
|
||
module.exports = { | ||
'framework:server' : [ 'factory', createServer ] | ||
}; |
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,132 @@ | ||
// Karma configuration | ||
// Generated on Tue Jul 11 2017 12:49:06 GMT+0800 (CST) | ||
|
||
process.env.CHROME_BIN = require( 'puppeteer' ).executablePath(); | ||
|
||
const argv = require( 'optimist' ).argv; | ||
const resolve = require( 'rollup-plugin-node-resolve' ); | ||
|
||
module.exports = function(config) { | ||
config.set({ | ||
|
||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: '', | ||
|
||
plugins : [ | ||
'karma-jasmine', | ||
'karma-rollup-preprocessor', | ||
'karma-chrome-launcher', | ||
require( './index' ) | ||
], | ||
|
||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
// Most versions of PhantomJS do not suppport ES5 and ES6, so add es6-shim here to make sure all | ||
// test cases could be executed in PhantomJS | ||
frameworks: [ 'jasmine', 'server' ], | ||
|
||
|
||
// list of files / patterns to load in the browser | ||
files : ( () => { | ||
const files = [ | ||
//{ pattern : 'src/**/*.js', included : false, watched : false } | ||
]; | ||
|
||
if( argv.file || argv.files ) { | ||
argv.file && files.push( { | ||
pattern : argv.file.trim(), | ||
included : true, | ||
watched : false | ||
} ); | ||
|
||
argv.files && argv.files.split( ',' ).forEach( file => { | ||
files.push( { | ||
pattern : file.trim(), | ||
included : true, | ||
watched : false | ||
} ); | ||
} ); | ||
} else { | ||
files.push( { | ||
pattern : 'test/**/*.spec.js', | ||
included : true, | ||
watched : false | ||
} ); | ||
} | ||
|
||
return files; | ||
} )(), | ||
|
||
// list of files to exclude | ||
exclude: [ | ||
'test/server/**/*.js' | ||
], | ||
|
||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
'test/**/*.js' : [ 'rollup' ] | ||
}, | ||
|
||
// configuration for rollup | ||
rollupPreprocessor : { | ||
plugins : [ | ||
resolve( { | ||
module : true, | ||
jsnext : true | ||
} ) | ||
], | ||
output : { | ||
format : 'iife' | ||
} | ||
}, | ||
|
||
// configuration for server | ||
server : { | ||
namespace : 'ynn', | ||
port : 3000, | ||
root : 'test/server', | ||
modules : { | ||
home : './home' | ||
} | ||
}, | ||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['progress'], | ||
|
||
// web server port | ||
port: 7997, | ||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
|
||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: true, | ||
|
||
// set delay time in order to avoid that the test cases executing before the testing server restart. | ||
autoWatchBatchDelay : 500, | ||
|
||
// start these browsers | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: [ 'ChromeHeadless' ], //PhantomJS, ChromeHeadless | ||
|
||
client : { | ||
captureConsole : true | ||
}, | ||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: false, | ||
|
||
// Concurrency level | ||
// how many browser should be started simultaneous | ||
concurrency: Infinity | ||
} ); | ||
}; |
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,24 @@ | ||
{ | ||
"keep": { | ||
"days": true, | ||
"amount": 30 | ||
}, | ||
"auditLog": "/Users/NextSeason/workspace/projects/ynn/karma-server/log/.audit.json", | ||
"files": [ | ||
{ | ||
"date": 1537101415747, | ||
"name": "/Users/NextSeason/workspace/projects/ynn/karma-server/log/2018-09-16.log", | ||
"hash": "47208996e61e4d8228b78ca0a6cb3623" | ||
}, | ||
{ | ||
"date": 1537101415750, | ||
"name": "/Users/NextSeason/workspace/projects/ynn/karma-server/log/warning-2018-09-16.log", | ||
"hash": "c0ddcbe7ae5db3538edc62c9815e4fe1" | ||
}, | ||
{ | ||
"date": 1537101415750, | ||
"name": "/Users/NextSeason/workspace/projects/ynn/karma-server/log/error-2018-09-16.log", | ||
"hash": "83aa40c68b188938e2303a83599dc550" | ||
} | ||
] | ||
} |
Oops, something went wrong.