From 11538454ff545fe8e540ddedc020c818736a828b Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Thu, 3 May 2018 12:42:40 +0100 Subject: [PATCH] fix: handle windows-style paths on the client - fixes #1553 --- .gitignore | 3 ++- client/lib/utils.ts | 12 +++++++++--- cypress/integration/file-reloading.js | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index bafcc9f6a..571984f4d 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +client/dist/index.min.js.map diff --git a/client/lib/utils.ts b/client/lib/utils.ts index 48e03a7ec..8e91ad978 100644 --- a/client/lib/utils.ts +++ b/client/lib/utils.ts @@ -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; @@ -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(); +} diff --git a/cypress/integration/file-reloading.js b/cypress/integration/file-reloading.js index 2f776f6f4..2174e37c2 100644 --- a/cypress/integration/file-reloading.js +++ b/cypress/integration/file-reloading.js @@ -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 ', () => {