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

Changed fs.watch.spec.js according to filed issue-666 #680

Merged
merged 1 commit into from
Jan 31, 2019
Merged
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
30 changes: 16 additions & 14 deletions tests/spec/fs.watch.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
'use strict';

const util = require('../lib/test-utils.js');
const expect = require('chai').expect;

describe('fs.watch', function() {
// Our watch infrastucture is dependent on document.localStorage
Expand All @@ -16,14 +18,14 @@ describe('fs.watch', function() {
afterEach(util.cleanup);

it('should be a function', function() {
var fs = util.fs();
const fs = util.fs();
expect(typeof fs.watch).to.equal('function');
});

it('should get a change event when writing a file', function(done) {
var fs = util.fs();
const fs = util.fs();

var watcher = fs.watch('/myfile', function(event, filename) {
const watcher = fs.watch('/myfile', function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal('/myfile');
watcher.close();
Expand All @@ -36,9 +38,9 @@ describe('fs.watch', function() {
});

it('should get a change event when writing a file beneath root dir with recursive=true', function(done) {
var fs = util.fs();
const fs = util.fs();

var watcher = fs.watch('/', { recursive: true }, function(event, filename) {
const watcher = fs.watch('/', { recursive: true }, function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal('/');
watcher.close();
Expand All @@ -51,12 +53,12 @@ describe('fs.watch', function() {
});

it('should get a change event when writing a file in a dir with recursive=true', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.mkdir('/foo', function(err) {
if(err) throw err;

var watcher = fs.watch('/foo', { recursive: true }, function(event, filename) {
const watcher = fs.watch('/foo', { recursive: true }, function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal('/foo');
watcher.close();
Expand All @@ -77,15 +79,15 @@ describe('fs.watch', function() {

// Bug to deal with this is filed at https://github.com/filerjs/filer/issues/594
it.skip('should get a change event when a hardlink is watched and the original file is changed', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.writeFile('/myfile', 'data', function(error) {
if(error) throw error;

fs.link('/myfile', '/hardlink', function(error) {
if(error) throw error;

var watcher = fs.watch('/hardlink', function(event, filename) {
const watcher = fs.watch('/hardlink', function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal('/hardlink');

Expand All @@ -107,14 +109,14 @@ describe('fs.watch', function() {
});

it('should get a change event when renaming a file', function(done) {
var fs = util.fs();
const fs = util.fs();

fs.writeFile('/myfile', 'data', function(error) {
if(error) throw error;

//Normaly A 'rename' event should be thrown, but filer doesn't support that event at this time.
//For now renaming a file will throw a change event.
var watcher = fs.watch('/myfile', function(event, filename) {
const watcher = fs.watch('/myfile', function(event, filename) {
expect(event).to.equal('change');
expect(filename).to.equal('/myfile');
watcher.close();
Expand All @@ -126,4 +128,4 @@ describe('fs.watch', function() {
});
});
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One tip: it's always a good idea to end files with a newline. We do this for cases where files get processed/concatenated together, and you want to avoid the case that the last line of one file, and the first line of the next, get joined and cause an error.