Skip to content

Commit

Permalink
add basic test for #84
Browse files Browse the repository at this point in the history
  • Loading branch information
smhg committed Dec 28, 2019
1 parent 2104ee4 commit 3613885
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/reloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const splitUrl = function (url) {

const pathFromUrl = function (url) {
if (!url) {
return "";
return '';
}
let path;
({ url } = splitUrl(url));
Expand Down Expand Up @@ -292,7 +292,11 @@ class Reloader {
}

this.console.log(`LiveReload found ${links.length} LINKed stylesheets, ${imported.length} @imported stylesheets`);
const match = pickBestMatch(path, links.concat(imported), l => pathFromUrl(this.linkHref(l)));
const match = pickBestMatch(
path,
links.concat(imported),
link => pathFromUrl(this.linkHref(link))
);

if (match) {
if (match.object.rule) {
Expand Down
15 changes: 15 additions & 0 deletions test/reloader_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ describe('Reloader', () => {
assert(reloader);
});

describe('linkHref()', () => {
it('should not throw when no value is available', () => {
const reloader = new Reloader(
{ },
console,
Timer
);

assert.doesNotThrow(() => {
reloader.linkHref({});
});
});
});

describe('reload()', () => {
it('should reload the page', (done) => {
const reloader = new Reloader(
Expand Down Expand Up @@ -152,6 +166,7 @@ describe('Reloader', () => {
}, 100);
});
});

describe('reload() with plugin order', () => {
it('should reload with same plugin order', (done) => {
const reloader = new Reloader(
Expand Down

0 comments on commit 3613885

Please sign in to comment.