Skip to content

Commit

Permalink
Initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
kai-inokuchi committed Nov 11, 2015
0 parents commit 3e7a9b0
Show file tree
Hide file tree
Showing 20 changed files with 628 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.classpath
.settings
.project
target/
src/main/webapp/WEB-INF/classes/
node_modules/
coverage/
dist/
npm-debug.log
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# webpack-test-sample

## Install

```
$ npm install
```

* Maven (`mvn`) should be installed to test and send coverage data

## Test

### JavaScript

```
$ npm run test
```

### Java

```
$ mvn test
```

## Build

### JavaScript

```
$ npm run build
# => dist/bundle.js
```

### Java

```
$ mvn clean assembly:assembly
# => target/webpack-test-sample-{version}.jar
```

## Execute Tests and Send Coverage to Coveralls

```
$ npm run coverage
```

(Coveralls token shoud be exported as `COVERALLS_REPO_TOKEN` environment variable.)
18 changes: 18 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
machine:
node:
version: 0.12.7

dependencies:
override:
- mvn --fail-never dependency:go-offline || true
- npm install
cache_directories:
- ~/.m2
- ~/webpack-test-sample/node_modules

test:
override:
- "mvn clean test jacoco:report coveralls:report -DdryRun -DcoverallsFile=coverage/java.json"
- node_modules/gulp/bin/gulp.js test
- node_modules/gulp/bin/gulp.js coveralls:merge
- "[ -d coverage/ ] && rm -rf coverage/"
106 changes: 106 additions & 0 deletions gulpfile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
gulp = require 'gulp'
rename = require 'gulp-rename'
gutil = require 'gulp-util'
coveralls = require 'coveralls'
gulpCoveralls = require 'gulp-coveralls'

webpack = require 'webpack-stream'
webpackConf = require './webpack.config.coffee'

KarmaServer = require('karma').Server

path = require 'path'
util = require 'util'
merge2 = require 'merge2'
through = require 'through2'

gulp.task 'build', ->
gulp.src 'src/main/js/index.js'
.pipe webpack webpackConf
.pipe rename 'bundle.js'
.pipe gulp.dest 'dist/'

gulp.task 'test', (cb) ->
server = new KarmaServer {
configFile: path.join __dirname, 'karma.conf.coffee'
singleRun: true
}, cb
do server.start

gulp.task 'coveralls', ->
gulp.src 'coverage/**/lcov.info'
.pipe do gulpCoveralls

gulp.task 'coveralls:merge', ->
error = (cb, err) ->
@emit 'error', new gutil.PluginError 'xxxx', err
do cb

mapper = (lcov, fileName) ->
return through.obj (file, enc, cb) ->
if file.isNull()
@push file
return do cb

done = (str) =>
newFile = new gutil.File
cwd: file.cwd,
base: file.base,
path: file.base + fileName

newFile.contents = new Buffer str
@push newFile
return do cb

output = file.contents.toString enc
if lcov
coveralls.convertLcovToCoveralls output, {}, (err, json) ->
if err
error.call @, cb, err
done JSON.stringify json
else
done output

merger = () ->
json =
source_files: []

transformer = (file, enc, cb) ->
data = JSON.parse(file.contents)
data.source_files.forEach (source) ->
json.source_files.push source

@push file
do cb

flush = (cb) ->
coveralls.getBaseOptions (err, options) =>
if err
error.call @, cb, err
options.filepath = '.'
util._extend(json, options)
coveralls.sendToCoveralls json, (err, response, body) =>
if err
error.call @, cb, err
else if response.statusCode != 200
error.call @, cb, JSON.stringify(body)
else
console.log body
do cb

return through.obj transformer, flush

inputs = [{
# JavaScript
file: 'coverage/lcov.info'
lcov: true
}, {
# Java
file: 'coverage/java.json'
}]

return merge2(inputs.map (input) ->
gulp.src(input.file)
.pipe mapper input.lcov, input.file + '.mapped'
)
.pipe do merger
112 changes: 112 additions & 0 deletions karma.conf.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Karma configuration
# Generated on Tue Nov 10 2015 10:31:29 GMT+0900 (JST)

module.exports = (config) ->
config.set

# base path that will be used to resolve all patterns (eg. files, exclude)
basePath: ''


# frameworks to use
# available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine']


# list of files / patterns to load in the browser
files: [
'src/test/js/entry.coffee'
]


# list of files to exclude
exclude: [
]


# preprocess matching files before serving them to the browser
# available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors:
'src/test/js/entry.coffee': ['webpack']

# test results reporter to use
# possible values: 'dots', 'progress'
# available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'coverage']


# web server port
port: 9876


# 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: false


# start these browsers
# available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS']


# Continuous Integration mode
# if true, Karma captures browsers, runs the tests and exits
singleRun: false

# Concurrency level
# how many browser should be started simultanous
concurrency: Infinity

plugins: [
'karma-phantomjs-launcher'
'karma-jasmine'
'karma-webpack'
'karma-coverage'
]

coverageReporter:
type: 'lcov'
dir: 'coverage'
subdir: '.'

webpack: addCoffeeLoader addIstanbulPreLoader require('./webpack.config')

extend = (require 'util')._extend

addIstanbulPreLoader = (input) ->
output = extend {}, input
output.module ||= {}
output.module.preLoaders ||= []
output.module.preLoaders.every((l) -> l.loader isnt 'istanbul-instrumenter') and output.module.preLoaders.push
loader: 'istanbul-instrumenter'
test: /\.js$/
include: require('path').resolve('src/main/js/components')

return output

addCoffeeLoader = (input) ->
output = extend {}, input
output.module ||= {}
output.module.loaders ||= []
output.module.loaders.every((l) -> l.loader isnt 'coffee-loader') and output.module.loaders.push
loader: 'coffee-loader'
test: /\.coffee$/

output.resolve ||= {}
output.resolve.extensions ||= []
output.resolve.extensions.indexOf('.coffee') < 0 and output.resolve.extensions.push '.coffee'

return output
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "webpack-test-sample",
"version": "1.0.0",
"description": "webpack-test-sample",
"main": "dist/bundle.js",
"scripts": {
"build": "gulp build",
"test": "gulp test",
"coverage": "mvn clean test jacoco:report coveralls:report -DdryRun -DcoverallsFile=coverage/java.json; npm test; node_modules/gulp/bin/gulp.js coveralls:merge"
},
"repository": {
"type": "git",
"url": "https://github.com/kainoku/webpack-test-sample.git"
},
"author": "kainoku",
"license": "ISC",
"bugs": {
"url": "https://github.com/kainoku/webpack-test-sample/issues"
},
"homepage": "https://github.com/kainoku/webpack-test-sample",
"devDependencies": {
"coffee-loader": "^0.7.2",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.4",
"gulp": "^3.9.0",
"gulp-coveralls": "^0.1.4",
"gulp-rename": "^1.2.2",
"gulp-util": "^3.0.7",
"istanbul-instrumenter-loader": "^0.1.3",
"jasmine-core": "^2.3.4",
"karma": "^0.13.15",
"karma-coffee-preprocessor": "^0.3.0",
"karma-coverage": "^0.5.3",
"karma-jasmine": "^0.3.6",
"karma-phantomjs-launcher": "^0.2.1",
"karma-webpack": "^1.7.0",
"merge2": "^0.3.6",
"phantomjs": "^1.9.18",
"through2": "^2.0.0",
"webpack": "^1.12.3",
"webpack-stream": "^2.1.1"
}
}

0 comments on commit 3e7a9b0

Please sign in to comment.