From f2eeaafbe7d09375cfdec59d243321b48ebca165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C5=A0p=C3=A1c?= Date: Mon, 12 Oct 2015 21:19:00 +0200 Subject: [PATCH] first skeleton of a test --- .travis.yml | 4 ++++ jspm-hot-reloader.js | 2 +- package.json | 4 +++- run-tests.js | 26 ++++++++++++++++++++++++++ test/jspm-hot-reloader.spec.js | 20 ++++++++++++++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .travis.yml create mode 100644 run-tests.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..de48798 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - "4.1" + - "4.0" diff --git a/jspm-hot-reloader.js b/jspm-hot-reloader.js index ca1e58b..e3353b6 100644 --- a/jspm-hot-reloader.js +++ b/jspm-hot-reloader.js @@ -40,7 +40,7 @@ class JspmHotReloader extends Emitter { } hotReload (moduleName) { const self = this - + this.moduleRecordsBackup = cloneDeep(System._loader.moduleRecords) // in case some module fails to import this.modulesJustDeleted = {} return this.getModuleRecord(moduleName).then(module => { diff --git a/package.json b/package.json index a86cf72..0efd326 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "precommit": "npm test", "pretest": "node_modules/.bin/standard", - "test": "mocha" + "test": "node run-tests" }, "repository": { "type": "git", @@ -24,6 +24,8 @@ "lodash.clonedeep": "^3.0.2" }, "devDependencies": { + "babel": "^5.8.23", + "chai": "^3.3.0", "husky": "^0.10.1", "mocha": "^2.3.3", "standard": "^5.3.1" diff --git a/run-tests.js b/run-tests.js new file mode 100644 index 0000000..6db4007 --- /dev/null +++ b/run-tests.js @@ -0,0 +1,26 @@ +'use strict' +const Mocha = require('mocha') +const fs = require('fs') +const path = require('path') + +// Instantiate a Mocha instance. +var mocha = new Mocha() + +var testDir = 'test' +require('babel/register')({ + ignore: false +}) +// Add each .js file to the mocha instance +fs.readdirSync(testDir).filter(function (file) { + // Only keep the .js files + return file.substr(-3) === '.js' +}).forEach(function (file) { + mocha.addFile(path.join(testDir, file)) +}) + +// Run the tests. +mocha.run(function (failures) { + process.on('exit', function () { + process.exit(failures) + }) +}) diff --git a/test/jspm-hot-reloader.spec.js b/test/jspm-hot-reloader.spec.js index e69de29..d0bc0f7 100644 --- a/test/jspm-hot-reloader.spec.js +++ b/test/jspm-hot-reloader.spec.js @@ -0,0 +1,20 @@ +/* eslint-env node, mocha */ +import HotReloader from '../jspm-hot-reloader' +import {expect} from 'chai' +describe('jspm-hot-reloader', function () { + let hr + it('should listen to socket.io and call hotReload on itself, when a change event comes', () => { + hr = new HotReloader('') + hr.on('change', (file) => { + expect(file).to.equal(file) + }) + }) + + it('should revert back the tree if some import during hotReload fails', () => { + + }) + + after(() => { + hr.socket.disconnect() + }) +})