diff --git a/.eslintrc b/.eslintrc index 5a89adf..b4c2f5f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,4 +1,5 @@ { + "parser": "babel-eslint", "extends": "eslint-config-airbnb/base", "rules": { "no-console": [0] @@ -6,5 +7,9 @@ "ecmaFeatures": { "generators": 1, "experimentalObjectRestSpread": true + }, + "env": { + "node": true, + "mocha": true } } diff --git a/Makefile b/Makefile index 6517210..35a254d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ - -# ref: https://github.com/npm/npm/issues/3059 publish: - npm run build + npm run compile npm publish + +publish-sync: publish + cnpm sync + tnpm sync \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index bfe25a2..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,25 +0,0 @@ -# AppVeyor file -# http://www.appveyor.com/docs/appveyor-yml - -# Build version format -version: "{build}" - -# What combinations to test -environment: - matrix: - - nodejs_version: 5 - - nodejs_version: 4 - -install: - # Get the latest stable version of Node.js or io.js - - ps: Install-Product node $env:nodejs_version - # install modules - - npm install - -build: off - -test_script: - - npm test - -matrix: - fast_finish: true # set this flag to immediately finish build once one of the jobs fails. diff --git a/package.json b/package.json index cb666b6..8e90afa 100644 --- a/package.json +++ b/package.json @@ -11,33 +11,32 @@ "main": "./lib", "scripts": { "build": "rm -rf lib && babel src --out-dir lib", - "test": "babel-node node_modules/.bin/babel-istanbul cover node_modules/.bin/_mocha --no-timeouts", - "lint": "eslint --ext .js src", + "test": "babel-node $(npm bin)/babel-istanbul cover $(npm bin)/_mocha -- --no-timeouts", + "lint": "eslint --ext .js src test", "coveralls": "cat ./coverage/lcov.info | coveralls" }, - "pre-commit": [ - "lint" - ], "dependencies": { "coffee-script": "^1.10.0", "internal-ip": "^1.2.0", "weinre": "^2.0.0-pre-I0Z7U9OV" }, "devDependencies": { - "babel-cli": "~6.2.0", - "babel-core": "~6.1.21", - "babel-istanbul": "^0.5.9", - "babel-plugin-add-module-exports": "~0.1.1", - "babel-preset-es2015": "~6.1.18", - "babel-preset-stage-0": "~6.1.18", + "atool-build": "0.7.x", + "babel-cli": "^6.10.1", + "babel-core": "^6.10.4", + "babel-eslint": "^6.1.0", + "babel-istanbul": "^0.11.0", + "babel-plugin-add-module-exports": "^0.2.1", + "babel-preset-es2015": "^6.9.0", + "babel-preset-stage-0": "^6.5.0", "coveralls": "^2.11.6", "dora": "0.3.x", - "eslint": "~1.9.0", - "eslint-config-airbnb": "~1.0.0", - "internal-ip": "^1.1.0", - "mocha": "~2.3.4", - "pre-commit": "~1.1.2", - "supertest": "^1.1.0" + "dora-plugin-webpack": "0.6.x", + "eslint": "^2.9.0", + "eslint-config-airbnb": "^9.0.1", + "eslint-plugin-import": "^1.10.2", + "mocha": "^2.5.3", + "supertest": "^1.2.0" }, "babel": { "presets": [ diff --git a/src/index.js b/src/index.js index 457e1de..4b45e60 100644 --- a/src/index.js +++ b/src/index.js @@ -25,7 +25,7 @@ export default { 'middleware.before'() { const { log, query } = this; defaultOpts.boundHost = localIP; - defaultOpts = {...defaultOpts, ...query}; + defaultOpts = { ...defaultOpts, ...query }; run(defaultOpts); log.info(`weinre is started, servering at http://${defaultOpts.boundHost}:${defaultOpts.httpPort}`); @@ -34,7 +34,7 @@ export default { 'middleware'() { const { cwd } = this; - return function* (next) { + return function* middleFunc(next) { const fileName = parse(this.url).pathname; const filePath = join(cwd, fileName); const isHTML = /\.html?$/.test(this.url.split('?')[0]); diff --git a/test/index-test.js b/test/index-test.js index 4ef60c2..281142c 100644 --- a/test/index-test.js +++ b/test/index-test.js @@ -5,19 +5,16 @@ import request from 'supertest'; const localIP = require('internal-ip')(); const port = '12345'; -describe('index', function() { - this.timeout(50000); +describe('index', () => { describe('livereload.js', () => { - const cwd = process.cwd(); before(done => { - process.chdir(join(__dirname, './fixtures/normal')); + process.chdir(join(__dirname, './fixtures/normal')); dora({ port, plugins: ['../../../src/index?{httpPort:8888}'], cwd: join(__dirname, './fixtures/normal'), - }); - setTimeout(done, 1000); + }, done); }); after(() => { @@ -25,14 +22,18 @@ describe('index', function() { }); it('GET weinre /target/target-script-min.js#anonymous', done => { - request(`http://${localIP}:8888`) .get('/target/target-script-min.js#anonymous') .expect(200) - .end(function(err, res){ + .end((err, res) => { if (err) return done(err); - if (res.text.indexOf(`modjewel.require('weinre/target/Target').main()`) < 0) throw new Error("/target/target-script-min.js#anonymous is not correct"); - done(); + if (res.text.indexOf("modjewel.require('weinre/target/Target').main()") < 0) { + const e = new Error('/target/target-script-min.js#anonymous is not correct'); + + return done(e); + } + + return done(); }); }); @@ -40,10 +41,15 @@ describe('index', function() { request(`http://localhost:${port}`) .get('/index.html') .expect(200) - .end(function(err, res){ + .end((err, res) => { if (err) return done(err); - if (res.text.indexOf(``) < 0) throw new Error("/target/target-script-min.js#anonymous is not injected"); - done(); + if (res.text.indexOf(``) < 0) { + const e = new Error('/target/target-script-min.js#anonymous is not injected'); + + return done(e); + } + + return done(); }); }); @@ -51,10 +57,15 @@ describe('index', function() { request(`http://localhost:${port}`) .get('/lackdoctype.html') .expect(200) - .end(function(err, res){ + .end((err, res) => { if (err) return done(err); - if (res.text.indexOf(``) < 0) throw new Error("/target/target-script-min.js#anonymous is not injected"); - done(); + if (res.text.indexOf(``) < 0) { + const e = new Error('/target/target-script-min.js#anonymous is not injected'); + + return done(e); + } + + return done(); }); }); @@ -62,14 +73,16 @@ describe('index', function() { request(`http://localhost:${port}`) .get('/index.js') .expect(200) - .end(function(err, res){ + .end((err, res) => { if (err) return done(err); - if (res.text.indexOf('console.log(1);') < 0) throw new Error("other types of files should not be handled"); - done(); + if (res.text.indexOf('console.log(1);') < 0) { + const e = new Error('other types of files should not be handled'); + + return done(e); + } + + return done(); }); }); }); }); - - -