Skip to content

Commit

Permalink
Use Travis-ci matrix to run the build on multiple versions of node.js
Browse files Browse the repository at this point in the history
fixes #109
  • Loading branch information
Shahar Soel committed Dec 25, 2015
1 parent 681e5a3 commit d8f987d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 55 deletions.
36 changes: 29 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@ language: node_js
cache:
directories:
- node_modules
node_js:
- "4"
- "5"
env:
- CXX=g++-4.8
matrix:
include:
- node_js: "5"
env: CXX=g++-4.8 GRUNT_TASK=unit_tests DEPLOY=true
- node_js: "4"
env: CXX=g++-4.8 GRUNT_TASK=unit_tests
- node_js: "0.12"
env: CXX=g++-4.8 GRUNT_TASK=unit_tests
- node_js: "0.10"
env: CXX=g++-4.8 GRUNT_TASK=unit_tests
- node_js: "5"
env: CXX=g++-4.8 GRUNT_TASK=integration_tests
- node_js: "4"
env: CXX=g++-4.8 GRUNT_TASK=integration_tests
- node_js: "0.12"
env: CXX=g++-4.8 GRUNT_TASK=integration_tests
- node_js: "0.10"
env: CXX=g++-4.8 GRUNT_TASK=integration_tests
addons:
apt:
sources:
Expand All @@ -19,8 +32,8 @@ install:
- bower install
before_script:
- grunt build
- chmod +x ./scripts/test_examples.sh
after_script: cat ./bin/coverage/lcov.info | node ./node_modules/coveralls/bin/coveralls.js
script:
- grunt $GRUNT_TASK
deploy:
- provider: releases
api_key:
Expand All @@ -31,6 +44,7 @@ deploy:
on:
tags : true
all_branches: true
condition: $DEPLOY = true
skip_cleanup: true

- provider: npm
Expand All @@ -40,4 +54,12 @@ deploy:
on:
tags: true
all_branches: true
condition: $DEPLOY = true
skip_cleanup: true

- provider: script
script: grunt coveralls:publish
on:
condition: $DEPLOY = true
branch: master
skip_cleanup: true
4 changes: 3 additions & 1 deletion examples/nodejs/json_parser_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var assert = require("assert");
var parseJson = require("./jsonParser");
var parseJsonES6 = require("./jsonParserES6");

describe('The Json Parser', function () {

Expand All @@ -13,6 +12,9 @@ describe('The Json Parser', function () {
});

it('can parse a simple Json without errors - Parser implemented using ES6 syntax', function () {
// only load a file containing ES6 syntax when actually running the test
// thus if this test is ignored the other tests can still be run in old node.js versions
var parseJsonES6 = require("./jsonParserES6");
var inputText = '{ "arr": [1,null,true], "obj": {"num":666}}';
var lexAndParseResult = parseJsonES6(inputText);

Expand Down
109 changes: 85 additions & 24 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var _ = require('lodash')
var specsFiles = require('./scripts/findSpecs')("bin/tsc/test/", "test")
var srcFiles = require('./scripts/findRefs')('build/chevrotain.ts')

var semver = require("semver")

var githubReleaseFiles = ['./package.json',
'./LICENSE.txt',
Expand All @@ -11,6 +11,14 @@ var githubReleaseFiles = ['./package.json',
'bin/docs'
]

var INSTALL_LINK_TEST = 'npm install && npm link chevrotain && npm test'

// Integration tests using older versions of node.js will
// avoid running tests that require ES6 capabilities only aviliable in node.js >= 4
var nodejs_examples_test_command = semver.gte(process.version, "4.0.0") ?
"mocha *spec.js" :
"mocha *spec.js -i -g ES6"

module.exports = function(grunt) {

var pkg = grunt.file.readJSON('package.json')
Expand All @@ -25,6 +33,39 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: pkg,

run: {
options: {
failOnError: true
},
npm_link: {
exec: 'npm link'
},
test_examples_nodejs: {
options: {
cwd: process.cwd() + "/examples/nodejs"
},
exec: "npm install && npm link chevrotain && " + nodejs_examples_test_command
},
test_examples_lexer: {
options: {
cwd: process.cwd() + "/examples/lexer"
},
exec: INSTALL_LINK_TEST
},
test_examples_jison_lex: {
options: {
cwd: process.cwd() + "/examples/jison_lex"
},
exec: INSTALL_LINK_TEST
},
test_examples_typescript_ecma5: {
options: {
cwd: process.cwd() + "/examples/typescript_ecma5"
},
exec: INSTALL_LINK_TEST
}
},

karma: {
options: {
configFile: 'karma.conf.js',
Expand Down Expand Up @@ -148,7 +189,7 @@ module.exports = function(grunt) {
}
},

clean: {
clean: {
release: ['bin/*.*', 'bin/tsc', 'bin/docs'],
dev: ['bin/gen']
},
Expand Down Expand Up @@ -239,18 +280,18 @@ module.exports = function(grunt) {
typedoc: {
build_docs: {
options: {
mode : 'file',
target: 'es5',
out: 'bin/docs',
name: 'Chevrotain',
mode: 'file',
target: 'es5',
out: 'bin/docs',
name: 'Chevrotain',
excludeExternals: '',
// see: https://github.com/sebastian-lenz/typedoc/issues/73
// double negative for the win!
externalPattern: '!**/*public**'
externalPattern: '!**/*public**'
},
// must include all the files explicitly instead of just targeting build/chevrotain.ts
// otherwise the include(exclude !...) won't work
src: srcFiles
src: srcFiles
}
},

Expand All @@ -267,10 +308,28 @@ module.exports = function(grunt) {
},
files: [{src: githubReleaseFiles, dest: '/'}]
}
},

coveralls: {
publish: {
src: 'bin/coverage/lcov.info'
}
}
})

var releaseBuildTasks = [
grunt.loadNpmTasks('grunt-karma')
grunt.loadNpmTasks('grunt-tslint')
grunt.loadNpmTasks("grunt-ts")
grunt.loadNpmTasks('grunt-umd')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-contrib-compress')
grunt.loadNpmTasks('grunt-mocha-istanbul')
grunt.loadNpmTasks('grunt-typedoc')
grunt.loadNpmTasks('grunt-run')
grunt.loadNpmTasks('grunt-coveralls')

var buildTasks = [
'clean:release',
'ts:release',
'ts:release_test_code',
Expand All @@ -284,25 +343,27 @@ module.exports = function(grunt) {
'compress'
]

var commonReleaseTasks = releaseBuildTasks.concat(['mocha_istanbul', 'istanbul_check_coverage'])
var unitTestsTasks = [
'mocha_istanbul',
'istanbul_check_coverage'
]

grunt.loadNpmTasks('grunt-karma')
grunt.loadNpmTasks('grunt-tslint')
grunt.loadNpmTasks("grunt-ts")
grunt.loadNpmTasks('grunt-umd')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-contrib-compress')
grunt.loadNpmTasks('grunt-mocha-istanbul')
grunt.loadNpmTasks('grunt-typedoc')
var integrationTestsTasks = [
'run:npm_link',
'run:test_examples_nodejs',
'run:test_examples_lexer',
'run:test_examples_jison_lex',
'run:test_examples_typescript_ecma5'
]

var buildTestTasks = buildTasks.concat(unitTestsTasks)

grunt.registerTask('build', releaseBuildTasks)
grunt.registerTask('build_and_test', commonReleaseTasks)
grunt.registerTask('test', ['mocha_istanbul', 'istanbul_check_coverage'])
grunt.registerTask('build_and_test_plus_browsers', commonReleaseTasks.concat(['karma:tests_on_browsers']))
grunt.registerTask('build', buildTasks)
grunt.registerTask('build_test', buildTestTasks)
grunt.registerTask('unit_tests', unitTestsTasks)
grunt.registerTask('integration_tests', integrationTestsTasks)

grunt.registerTask('dev_build', [
grunt.registerTask('dev_build_test', [
'clean:dev',
'ts:dev_build',
'tslint',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"url": "git://github.com/SAP/chevrotain.git"
},
"scripts": {
"test": "grunt test && npm link && bash ./scripts/test_examples.sh",
"release_patch": "node scripts/pre_release_build.js patch && grunt build && node scripts/post_release_build.js patch && upload_docs.bat",
"release_minor": "node scripts/pre_release_build.js minor && grunt build && node scripts/post_release_build.js minor && upload_docs.bat"
},
Expand All @@ -57,8 +56,10 @@
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-compress": "^0.14.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-coveralls": "^1.0.0",
"grunt-karma": "~0.12.1",
"grunt-mocha-istanbul": "^3.0.1",
"grunt-run": "^0.5.2",
"grunt-ts": "~5.3.0-beta.2",
"grunt-tslint": "~3.0.0",
"grunt-typedoc": "^0.2.3",
Expand Down
22 changes: 0 additions & 22 deletions scripts/test_examples.sh

This file was deleted.

0 comments on commit d8f987d

Please sign in to comment.