Skip to content

Commit

Permalink
fix: 404 when html file lack of doctype and add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
soda-x committed Dec 29, 2015
1 parent 00f8b9c commit 37ec442
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.idea
.DS_Store
.coveralls.yml
tmp
node_modules/*
src/__tests__/fixtures/**/dist
coverage
lib

2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ node_js:
- "5"


after_success:
- npm run coveralls
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"main": "./lib",
"scripts": {
"build": "rm -rf lib && babel src --out-dir lib",
"test": "mocha --require babel-core/register --no-timeouts",
"lint": "eslint --ext .js src"
"test": "babel-node node_modules/.bin/babel-istanbul cover node_modules/.bin/_mocha --no-timeouts",
"lint": "eslint --ext .js src",
"coveralls": "cat ./coverage/lcov.info | coveralls"
},
"pre-commit": [
"lint"
Expand All @@ -21,11 +22,13 @@
"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-polyfill": "^6.3.14",
"babel-preset-es2015": "~6.1.18",
"babel-preset-stage-0": "~6.1.18",
"dora": "0.x",
"coveralls": "^2.11.6",
"dora": "~0.2.2",
"eslint": "~1.9.0",
"eslint-config-airbnb": "~1.0.0",
"mocha": "~2.3.4",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default {
return;
}
content = injectScript + content;
this.body = content;

return;
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/normal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(2);
1 change: 1 addition & 0 deletions test/fixtures/normal/lackdoctype.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
33 changes: 33 additions & 0 deletions test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,38 @@ describe('debug-corner', () => {
done();
});
});

it('GET /index.html is injected the script dora-plugin-debug-corner.js', done => {
request(`http://localhost:${port}`)
.get('/index.html')
.expect(200)
.end(function(err, res){
if (err) return done(err);
if (res.text.indexOf('<script src="./dora-plugin-debug-corner.js"></script>') < 0) throw new Error("dora-plugin-debug-corner.js is not injected");
done();
});
});

it('GET /lackdoctype.html is injected the script dora-plugin-debug-corner.js', done => {
request(`http://localhost:${port}`)
.get('/lackdoctype.html')
.expect(200)
.end(function(err, res){
if (err) return done(err);
if (res.text.indexOf('<script src="./dora-plugin-debug-corner.js"></script>') < 0) throw new Error("dora-plugin-debug-corner.js is not injected");
done();
});
});

it('GET /index.js should not be handled', done => {
request(`http://localhost:${port}`)
.get('/index.js')
.expect(200)
.end(function(err, res){
if (err) return done(err);
if (res.text.indexOf('console.log(2);') < 0) throw new Error("other types of files should not be handled");
done();
});
});
});

0 comments on commit 37ec442

Please sign in to comment.