diff --git a/.gitignore b/.gitignore index fd1bffce..25e93d9b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,8 @@ fixtures/typings-test/*.js package-lock.json # Directories needed for code coverage -/coverage/ +coverage/ +.nyc_output/ # Keep bundled code out of Git dist/ diff --git a/.travis.yml b/.travis.yml index 1f3c9079..c212b19d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ env: matrix: - NPM_COMMAND=tsc - NPM_COMMAND=lint - - NPM_COMMAND=test + - NPM_COMMAND=test-coverage notifications: email: false script: npm run $NPM_COMMAND diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 064f0f5e..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "Mocha Tests", - "cwd": "${workspaceRoot}", - "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/mocha", - "windows": { - "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/mocha.cmd" - }, - "runtimeArgs": [ - "--colors", - "--recursive", - "${workspaceRoot}/lib" - ], - "sourceMaps": true, - "outFiles": [ "${workspaceRoot}/lib/**/*.js" ], - "internalConsoleOptions": "openOnSessionStart" - } - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index f78b3f81..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "search.exclude": { - "**/node_modules": true, - "**/dist": true, - "**/build": true, - "**/lib": true - } -} diff --git a/README.md b/README.md index a8325bf2..ae003783 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,8 @@ computational environment for Jupyter, supporting interactive data science and s - [**Hyper**](https://hyper.is): A terminal built on web technologies - [**Diag**](https://diag.ai): A better way to troubleshoot problems faster. Capture, share and reapply troubleshooting knowledge so you can focus on solving problems that matter. - [**GoTTY**](https://github.com/yudai/gotty): A simple command line tool that shares your terminal as a web application based on xterm.js. +- [**genact**](https://github.com/svenstaro/genact): A nonsense activity generator. + Do you use xterm.js in your application as well? Please [open a Pull Request](https://github.com/sourcelair/xterm.js/pulls) to include it here. We would love to have it in our list. @@ -224,6 +226,16 @@ Then open http://127.0.0.1:3000 in a web browser to access the demo. *Note: Do not use ConEmu, as it seems to break the demo for some reason.* +## Testing + +Tests are run using the following npm scripts: + +- `npm test`: This will run both unit tests and the linter +- `npm run test-suite `: This will run all tests within a particular file, <file> is the test file name excluding the extension (eg. "Linkifier.test") +- `npm run test-debug`: This will run unit tests with `--inspect-brk`, this can then be automatically debugged using [VS Code auto attach](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_auto-attach-feature) or manually attached to by a debugger +- `npm run test-coverage`: This will run all unit tests and produce a coverage report +- `npm run lint`: This will run the linter only + ## Releases Xterm.js follows a monthly release cycle roughly. diff --git a/gulpfile.js b/gulpfile.js index 8fe5bf9c..7026ec43 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,11 +4,9 @@ const browserify = require('browserify'); const buffer = require('vinyl-buffer'); -const coveralls = require('gulp-coveralls'); const fs = require('fs-extra'); const gulp = require('gulp'); const path = require('path'); -const istanbul = require('gulp-istanbul'); const merge = require('merge-stream'); const mocha = require('gulp-mocha'); const sorcery = require('sorcery'); @@ -25,6 +23,13 @@ let outDir = tsProject.config.compilerOptions.outDir; const addons = fs.readdirSync(`${__dirname}/src/addons`); +const TEST_PATHS = [ + `${outDir}/*test.js`, + `${outDir}/**/*test.js`, + `${outDir}/*integration.js`, + `${outDir}/**/*integration.js` +]; + // Under some environments like TravisCI, this comes out at absolute which can // break the build. This ensures that the outDir is absolute. if (path.normalize(outDir).indexOf(__dirname) !== 0) { @@ -95,37 +100,22 @@ gulp.task('browserify-addons', function() { return merge(...bundles); }); -gulp.task('instrument-test', function () { - return gulp.src([`${outDir}/**/*.js`]) - // Covering files - .pipe(istanbul()) - // Force `require` to return covered files - .pipe(istanbul.hookRequire()); -}); - -gulp.task('mocha', ['instrument-test'], function () { - return gulp.src([ - `${outDir}/*test.js`, - `${outDir}/**/*test.js`, - `${outDir}/*integration.js`, - `${outDir}/**/*integration.js` - ], {read: false}) +gulp.task('mocha', function () { + return gulp.src(TEST_PATHS, {read: false}) .pipe(mocha()) - .once('error', () => process.exit(1)) - .pipe(istanbul.writeReports()); + .once('error', () => process.exit(1)); }); /** - * Run single test file by file name(without file extension). Example of the command: - * gulp mocha-test --test InputHandler.test + * Run single test suite (file) by file name (without file extension). Example of the command: + * gulp mocha-suite --test InputHandler.test */ -gulp.task('mocha-test', ['instrument-test'], function () { +gulp.task('mocha-suite', [], function () { let testName = util.env.test; util.log("Run test by Name: " + testName); return gulp.src([`${outDir}/${testName}.js`, `${outDir}/**/${testName}.js`], {read: false}) .pipe(mocha()) - .once('error', () => process.exit(1)) - .pipe(istanbul.writeReports()); + .once('error', () => process.exit(1)); }); /** @@ -158,14 +148,6 @@ gulp.task('watch-demo', ['webpack'], () => { gulp.watch(['./demo/*', './lib/**/*'], ['webpack']); }); -/** - * Submit coverage results to coveralls.io - */ -gulp.task('coveralls', function () { - gulp.src('coverage/**/lcov.info') - .pipe(coveralls()); -}); - gulp.task('build', ['sorcery', 'sorcery-addons']); gulp.task('test', ['mocha']); gulp.task('default', ['build']); diff --git a/package.json b/package.json index 5e869e32..c7f6f81c 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,13 @@ "devDependencies": { "@types/chai": "^3.4.34", "@types/glob": "^5.0.35", - "@types/jsdom": "^11.0.1", + "@types/jsdom": "11.0.1", "@types/mocha": "^2.2.33", "@types/node": "6.0.108", "browserify": "^13.3.0", "chai": "3.5.0", "concurrently": "^3.5.1", + "coveralls": "^3.0.1", "express": "4.13.4", "express-ws": "2.0.0-rc.1", "fs-extra": "^1.0.0", @@ -22,18 +23,17 @@ "gulp": "3.9.1", "gulp-cli": "^1.2.2", "gulp-concat": "^2.6.1", - "gulp-coveralls": "^0.1.4", - "gulp-istanbul": "^1.1.1", "gulp-mocha": "^3.0.1", "gulp-sourcemaps": "1.9.1", "gulp-typescript": "^3.1.3", "gulp-util": "3.0.8", "jsdoc": "3.4.3", - "jsdom": "^11.1.0", + "jsdom": "^11.11.0", "merge-stream": "^1.0.1", "node-pty": "^0.7.2", "nodemon": "1.10.2", "npm-run-all": "^4.1.2", + "nyc": "^11.8.0", "sorcery": "^0.10.0", "tslint": "^5.9.1", "tslint-consistent-codestyle": "^1.13.0", @@ -49,13 +49,16 @@ "start-zmodem": "node demo/zmodem/app", "lint": "tslint 'src/**/*.ts'", "test": "npm-run-all mocha lint", + "test-debug": "node --inspect-brk node_modules/.bin/gulp test", + "test-suite": "gulp mocha-suite --test", + "test-coverage": "nyc -x gulpfile.js -x '**/*test*' npm run mocha", "mocha": "gulp test", "build:docs": "jsdoc -c jsdoc.json", "tsc": "tsc", "prebuild": "concurrently --kill-others-on-fail --names \"lib,attach,fit,fullscreen,search,terminado,webLinks,winptyCompat,zmodem,css\" \"tsc\" \"tsc -p ./src/addons/attach\" \"tsc -p ./src/addons/fit\" \"tsc -p ./src/addons/fullscreen\" \"tsc -p ./src/addons/search\" \"tsc -p ./src/addons/terminado\" \"tsc -p ./src/addons/webLinks\" \"tsc -p ./src/addons/winptyCompat\" \"tsc -p ./src/addons/zmodem\" \"gulp css\"", "build": "gulp build", "prepublish": "npm run build", - "coveralls": "gulp coveralls", + "coveralls": "nyc report --reporter=text-lcov | coveralls", "webpack": "gulp webpack", "watch": "concurrently --kill-others-on-fail --names \"lib,attach,fit,fullscreen,search,terminado,webLinks,winptyCompat,zmodem,css\" \"tsc -w\" \"tsc -w -p ./src/addons/attach\" \"tsc -w -p ./src/addons/fit\" \"tsc -w -p ./src/addons/fullscreen\" \"tsc -w -p ./src/addons/search\" \"tsc -w -p ./src/addons/terminado\" \"tsc -w -p ./src/addons/webLinks\" \"tsc -w -p ./src/addons/winptyCompat\" \"tsc -w -p ./src/addons/zmodem\" \"gulp watch-css\"" }