Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix oc-cli breaking on Windows when modifying files #899

Merged
merged 1 commit into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cli/domain/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(dirs, baseDir, changed) {
(fileName, currentStat, previousStat) => {
if (!!currentStat || !!previousStat) {
const componentDir = dirs.find(dir =>
Boolean(fileName.match(dir + path.sep))
Boolean(fileName.match(escapeRegularExpression(dir + path.sep)))
);
changed(null, fileName, componentDir);
}
Expand All @@ -29,3 +29,7 @@ module.exports = function(dirs, baseDir, changed) {
changed(err);
}
};

function escapeRegularExpression(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
37 changes: 35 additions & 2 deletions test/unit/cli-domain-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const injectr = require('injectr');
const sinon = require('sinon');

describe('cli : domain : watch', () => {
const execute = (fileChanged, cb) => {
const execute = (fileChanged, separator, cb) => {
class Stats {
constructor(settings) {
this.stuff = settings.stuff;
Expand All @@ -15,7 +15,7 @@ describe('cli : domain : watch', () => {
const watch = injectr('../../src/cli/domain/watch.js', {
path: {
resolve: x => x,
sep: '/'
sep: separator
},
watch: {
watchTree: sinon
Expand All @@ -30,6 +30,7 @@ describe('cli : domain : watch', () => {

watch(
[
'C:\\Windows-like\\path\\to\\yet-another-component',
'/path/to/my-component',
'/path/to/my-component2',
'/path/to/some-other-component'
Expand All @@ -44,6 +45,7 @@ describe('cli : domain : watch', () => {
before(done => {
execute(
'/path/to/my-component/server.js',
'/',
(error, fileName, componentDir) => {
result = { error, fileName, componentDir };
done();
Expand All @@ -69,6 +71,7 @@ describe('cli : domain : watch', () => {
before(done => {
execute(
'/path/to/my-component2/server.js',
'/',
(error, fileName, componentDir) => {
result = { error, fileName, componentDir };
done();
Expand All @@ -88,4 +91,34 @@ describe('cli : domain : watch', () => {
expect(result.componentDir).to.equal('/path/to/my-component2');
});
});

describe('when a file from a component on Windows-like path changes', () => {
let result;
before(done => {
execute(
'C:\\Windows-like\\path\\to\\yet-another-component\\server.js',
'\\',
(error, fileName, componentDir) => {
result = { error, fileName, componentDir };
done();
}
);
});

it('should return no error', () => {
expect(result.error).to.be.null;
});

it('should return the fileName', () => {
expect(result.fileName).to.equal(
'C:\\Windows-like\\path\\to\\yet-another-component\\server.js'
);
});

it('should return the component folder', () => {
expect(result.componentDir).to.equal(
'C:\\Windows-like\\path\\to\\yet-another-component'
);
});
});
});