Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
Merge pull request #13 from shepherdwind/add-ci
Browse files Browse the repository at this point in the history
test: add ci
  • Loading branch information
shepherdwind authored Jul 3, 2017
2 parents 6b3bc9f + 4d4d493 commit 3182efd
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js

notifications:
email:
- [email protected]

node_js:
- '6.11.0'

install:
- npm install

script:
- npm run ci
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
### CSS Hot Loader

[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/css-hot-loader.svg?style=flat-square
[npm-url]: http://npmjs.org/package/css-hot-loader
[download-image]: https://img.shields.io/npm/dm/css-hot-loader.svg?style=flat-square
[download-url]: https://npmjs.org/package/css-hot-loader
[travis-image]: https://img.shields.io/travis/shepherdwind/css-hot-loader.svg?style=flat-square
[travis-url]: https://travis-ci.org/shepherdwind/css-hot-loader
[coveralls-image]: https://img.shields.io/coveralls/shepherdwind/css-hot-loader.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/shepherdwind/css-hot-loader?branch=master


This is a css hot loader, which supprot hot module replacement for an extracted css file.
Expand Down
31 changes: 31 additions & 0 deletions __tests__/hotModuleReplacement-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

test('basic reload', () => {
document.body.innerHTML = `
<head>
<link href="a.css">
<link href="b.css">
<script src="a.js"></script>
</head>
`;
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();
});

20 changes: 20 additions & 0 deletions examples/commons-chunk/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>css hot loader example</title>

<link rel="stylesheet" href="common.css">
<link rel="stylesheet" href="output.css">
</head>
<body>

<!-- React stuff -->
<div id="root"> hello world</div>

<script src="common.js"></script> <!-- webpack javascript output -->
<script src="output.js"></script> <!-- webpack javascript output -->

</body>
</html>

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}

0 comments on commit 3182efd

Please sign in to comment.