diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2467007 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: node_js + +notifications: + email: + - eward.song@gmail.com + +node_js: + - '6.11.0' + +install: + - npm install + +script: + - npm run ci diff --git a/__tests__/hotModuleReplacement-test.js b/__tests__/hotModuleReplacement-test.js new file mode 100644 index 0000000..d71b904 --- /dev/null +++ b/__tests__/hotModuleReplacement-test.js @@ -0,0 +1,31 @@ +'use strict'; + +test('basic reload', () => { + document.body.innerHTML = ` + + + + + + `; + const reload = require('../hotModuleReplacement')(1, { + fileMap: '{fileName}', + }); + const spy = jest.spyOn(EventTarget.prototype, 'addEventListener'); + let cb; + spy.mockImplementation((event, _cb) => { + cb = _cb; + }); + reload(); + expect(spy).toHaveBeenCalled(); + + expect(document.querySelectorAll('link').length === 3); + cb(); + + expect(document.querySelectorAll('link').length === 2); + expect(document.querySelector('link').href.indexOf('?') > -1); + + spy.mockReset(); + spy.mockRestore(); +}); + diff --git a/examples/commons-chunk/dist/index.html b/examples/commons-chunk/dist/index.html new file mode 100644 index 0000000..96e1bd2 --- /dev/null +++ b/examples/commons-chunk/dist/index.html @@ -0,0 +1,20 @@ + + + + + css hot loader example + + + + + + + +
hello world
+ + + + + + + diff --git a/package.json b/package.json index 9dcefa1..672f789 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "main": "index.js", "scripts": { "pub": "npm version patch && npm publish && git push origin && git push origin --tags", - "test": "echo \"Error: no test specified\" && exit 1" + "cov": "jest --collectCoverageFrom='[\"*.js\"]' --coverage", + "ci": "npm run cov && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", + "test": "jest" }, "files": [ "loader.js", @@ -22,5 +24,10 @@ "dependencies": { "loader-utils": "^1.1.0", "normalize-url": "^1.9.1" + }, + "devDependencies": { + "coveralls": "^2.13.1", + "jest": "^20.0.4", + "strict-uri-encode": "^2.0.0" } }