Skip to content

Commit

Permalink
fix: handle windows-style paths on the client - fixes #1553
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed May 3, 2018
1 parent af79226 commit 1153845
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -21,7 +21,8 @@ bs-config.js
/lodash.custom.min.js
/dist
/cypress/videos
/cypress/screenshots/*
client/dist/index.js
client/dist/index.js.map
client/dist/index.min.js
client/dist/index.min.js.map
client/dist/index.min.js.map
12 changes: 9 additions & 3 deletions client/lib/utils.ts
Expand Up @@ -61,9 +61,8 @@ export const pickBestMatch = function(path, objects, pathFunc): any {
};

export const numberOfMatchingSegments = function(path1, path2) {
// get rid of leading slashes and normalize to lower case
path1 = path1.replace(/^\/+/, "").toLowerCase();
path2 = path2.replace(/^\/+/, "").toLowerCase();
path1 = normalisePath(path1);
path2 = normalisePath(path2);

if (path1 === path2) {
return 10000;
Expand Down Expand Up @@ -153,3 +152,10 @@ export function createTimedBooleanSwitch(source$, timeout = 1000) {
export function array(incoming) {
return [].slice.call(incoming);
}

export function normalisePath(path: string): string {
return path
.replace(/^\/+/, "")
.replace(/\\/g, "/")
.toLowerCase();
}
14 changes: 14 additions & 0 deletions cypress/integration/file-reloading.js
Expand Up @@ -34,6 +34,20 @@ describe('Reloading files', function() {
});
});
});
it('should reload with windows style paths', function() {
cy.get('#__bs_notify__').should('have.length', 1);
cy.request('POST', 'http://localhost:3000/__browser_sync__',
JSON.stringify([
"file:reload",
{"ext":"css","path":"C:\\#server\\test\\gulp-test\\assets\\style.css","basename":"style.css","event":"change","type":"inject","log":false}
])
);
cy.get('[id="css-style"]').should('have.length', 1);
cy.get('[id="css-style"]').eq(0).should((link) => {
const url = new URL(link[0].href);
return expect(url.search).to.contain('?browsersync=');
})
});
});
context('CSS IMPORTS', function() {
it('can import 1 stylesheet from <style>@import</style>', () => {
Expand Down

0 comments on commit 1153845

Please sign in to comment.