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

Commit

Permalink
test: add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
shepherdwind committed Jul 3, 2017
1 parent 6b3bc9f commit 65f4aa7
Show file tree
Hide file tree
Showing 4 changed files with 73 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
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 65f4aa7

Please sign in to comment.