Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: tests + coffee + coverage #1

Merged
merged 6 commits into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
Expand All @@ -24,10 +23,8 @@ coverage
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
/test-compiled
/coverage
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: node_js
node_js:
- "0.12"
- "1"
- "2"
- "4.1.2"
- "6.10.0"
- "7.0.0"
- "7.7.1"
script: npm test
sudo: false
after_success: 'npm run cover'
25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@ COFFEE = ./node_modules/coffee-script/bin/coffee
usage:
@echo ''
@echo 'make compile: Compile sources'
@echo 'make compile-tests: Compile test sources'
@echo ''

# --

# Compile Assets
.PHONY: compile
# Compile sources
.PHONY: compile compile-tests
compile:
[ -d ./lib ] && rm -r ./lib || 0
@$(COFFEE) --no-header -cbo ./lib ./src
@$(COFFEE) --output ./lib --no-header --compile -b ./src

# Compile tests
compile-tests: compile
@$(COFFEE) --output ./test-compiled --no-header --compile -b ./test

# Run lint for coffeescript
run-coffee-lint:
./node_modules/coffeelint/bin/coffeelint src/ test/

test: compile-tests run-coffee-lint
./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha ./test-compiled/**/*.js

test-debug: compile-tests
./node_modules/mocha/bin/mocha --debug-brk ./test-compiled/**/*.js

cover:
cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![Build Status](https://travis-ci.org/ajuste/jaune-tasks.svg?branch=master)](https://travis-ci.org/ajuste/jaune-tasks)
[![Coverage Status](https://coveralls.io/repos/ajuste/jaune-tasks/badge.svg?branch=master)](https://coveralls.io/r/ajuste/jaune-tasks?branch=master)

# jaune-tasks

Use gulp tasks only through configuration -- don't code.
Expand Down Expand Up @@ -115,7 +118,7 @@ Adds support for [gulp-webpack](https://www.npmjs.com/package/gulp-webpack)
1. **entry** should always be used to sepecify entry points, even there is only one.
2. **test** property for loaders must be a regular expression.
3. plugins names must be a [jaune-util reflection reference](https://github.com/ajuste/jaune-util#reflection).

The following is an example that outputs two scripts 'page_1_script_name' and 'page_2_script_name'. Those scripts require handlebars files as template plus we want to minify them:

```json
Expand Down
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "jaune-tasks",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepublish": "make compile"
"test": "make test",
"prepublish": "make compile",
"cover": "make cover"
},
"repository": {
"type": "git",
Expand All @@ -28,7 +29,15 @@
"require-linked-peer": "^0.1.0"
},
"devDependencies": {
"coffee-script": "^1.10.0",
"jaune-tasks": "git+ssh://github.com/ajuste/jaune-tasks.git#master"
"assert": "^1.3.0",
"coffee-script": "^1.12.5",
"coffeelint": "^1.16.0",
"coveralls": "^2.13.0",
"gulp-stylus": "^2.6.0",
"gulp-uglify": "^2.1.2",
"gulp-webpack": "^1.5.0",
"istanbul": "^0.4.5",
"mocha": "^2.4.5",
"mock-require": "^2.0.2"
}
}
3 changes: 2 additions & 1 deletion src/tasks/webpack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = (settings, task, gulp) ->

# if there are loaders then parse regex
if loaders?
args.module.loaders = loaders.map (l) -> loader: l.loader, test: new RegExp l.test
args.module.loaders = loaders.map (l) ->
loader: l.loader, test: new RegExp l.test

if plugins?
args.plugins = plugins.map (l) -> Reflection.evaluateName l
Expand Down
81 changes: 81 additions & 0 deletions test/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
mock = require 'mock-require'

{
create
} = require '../'

{
equal
ok
} = require 'assert'

SettingsPath = 'the-path'
EnvConfig = {}
Settings =
doMyStuff: [
{name: 'stylus', prop1: 'a'}
{name: 'uglify', prop2: 'b'}
]
doThatThing: [
{name: 'webpack', propb: 'z'}
]

TaskStylus = (settings, conf, gulp) ->
assert settings, Settings
assert Settings.doMyStuff[0]

TaskUglify = (settings, conf, gulp) ->
assert settings, Settings
assert Settings.doMyStuff[1]

TaskDoThatThing = (settings, conf, gulp) ->
assert settings, Settings
assert Settings.doThatThing[0]

describe 'exports', ->

@timeout 10000

before ->

mock 'jaune-util',
Reflection:
evaluateName: (settingsPath) ->
equal settingsPath, SettingsPath
EnvConfig

mock 'jaune-env',
class
constructor: (config) ->
equal config, EnvConfig
getEnvProperty: (configName) ->
equal 'jaune.build_tasks', configName
Settings

mock './tasks/stylus', TaskStylus

mock './tasks/uglify', TaskUglify

mock './tasks/webpack', TaskDoThatThing

after ->
mock.stopAll()
@gulp = null

it 'creates gulp on export', (cb) ->
@gulp = require('../') SettingsPath
ok @gulp
ok @gulp.tasks
cb()

it 'contains default task', ->
ok @gulp.tasks.default

it 'contains help task', ->
ok @gulp.tasks.help

it 'contains doMyStuff task', ->
ok @gulp.tasks.doMyStuff

it 'contains doThatThing task', ->
ok @gulp.tasks.doThatThing