Skip to content

Commit

Permalink
Lint: Tests indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Apr 21, 2018
1 parent 5c9a3ba commit 189787b
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 158 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@

* `.close` method works for zip files from `.fromBuffer`
* Tests for all access methods
* Lint: Tests indentation
315 changes: 157 additions & 158 deletions test/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,215 +197,214 @@ function runMainTests(methodName, method) {
});
});

describe('.close()', function() {
it('returns a Promise', function() {
return method().then(zipFile => {
const promise = zipFile.close();
expect(promise).to.be.instanceof(Promise);
return promise;
});
});
});

describe('Entry methods', function() {
beforeEach(function() {
return method().then(zipFile => {
this.zipFile = zipFile;
describe('.close()', function() {
it('returns a Promise', function() {
return method().then(zipFile => {
const promise = zipFile.close();
expect(promise).to.be.instanceof(Promise);
return promise;
});
});
});

afterEach(function() {
return this.zipFile.close();
});

describe('.readEntry()', function() {
describe('Entry methods', function() {
beforeEach(function() {
this.promise = this.zipFile.readEntry();
return this.promise.then(entry => {
this.entry = entry;
return method().then(zipFile => {
this.zipFile = zipFile;
});
});

it('returns a Promise', function() {
expect(this.promise).to.be.instanceof(Promise);
afterEach(function() {
return this.zipFile.close();
});

it('resolves to instance of yauzl.Entry', function() {
expect(this.entry).to.be.instanceof(yauzl.Entry);
});
describe('.readEntry()', function() {
beforeEach(function() {
this.promise = this.zipFile.readEntry();
return this.promise.then(entry => {
this.entry = entry;
});
});

it('returns first entry', function() {
expect(this.entry.fileName).to.equal(FILES[0]);
});
it('returns a Promise', function() {
expect(this.promise).to.be.instanceof(Promise);
});

it('when called again, returns next entry', function() {
return this.zipFile.readEntry().then(entry => {
expect(entry.fileName).to.equal(FILES[1]);
it('resolves to instance of yauzl.Entry', function() {
expect(this.entry).to.be.instanceof(yauzl.Entry);
});
});

it('returns `null` when all entries consumed', function() {
expect(this.entry.fileName).to.equal(FILES[0]);
return this.zipFile.readEntry().then(entry => {
expect(entry.fileName).to.equal(FILES[1]);
return this.zipFile.readEntry();
}).then(entry => {
expect(entry.fileName).to.equal(FILES[2]);
return this.zipFile.readEntry();
}).then(entry => {
expect(entry.fileName).to.equal(FILES[3]);
return this.zipFile.readEntry();
}).then(entry => {
expect(entry).to.be.null;
it('returns first entry', function() {
expect(this.entry.fileName).to.equal(FILES[0]);
});
});
});

describe('.readEntries()', function() {
it('returns a Promise', function() {
const promise = this.zipFile.readEntries();
expect(promise).to.be.instanceof(Promise);
return promise;
});
it('when called again, returns next entry', function() {
return this.zipFile.readEntry().then(entry => {
expect(entry.fileName).to.equal(FILES[1]);
});
});

it('returns array of `numEntries` entries', function() {
return this.zipFile.readEntries(2).then(entries => {
expect(entries).to.be.an('array');
expect(entries).to.have.lengthOf(2);
const fileNames = entries.map(entry => entry.fileName);
expect(fileNames).to.deep.equal(FILES.slice(0, 2));
it('returns `null` when all entries consumed', function() {
expect(this.entry.fileName).to.equal(FILES[0]);
return this.zipFile.readEntry().then(entry => {
expect(entry.fileName).to.equal(FILES[1]);
return this.zipFile.readEntry();
}).then(entry => {
expect(entry.fileName).to.equal(FILES[2]);
return this.zipFile.readEntry();
}).then(entry => {
expect(entry.fileName).to.equal(FILES[3]);
return this.zipFile.readEntry();
}).then(entry => {
expect(entry).to.be.null;
});
});
});

it('when called again, returns next entries', function() {
return this.zipFile.readEntries(2).then(() => {
return this.zipFile.readEntries(2);
}).then(entries => {
expect(entries).to.be.an('array');
expect(entries).to.have.lengthOf(2);
const fileNames = entries.map(entry => entry.fileName);
expect(fileNames).to.deep.equal(FILES.slice(2, 4));
describe('.readEntries()', function() {
it('returns a Promise', function() {
const promise = this.zipFile.readEntries();
expect(promise).to.be.instanceof(Promise);
return promise;
});
});

it('with no `numEntries` specified, returns all entries', function() {
return this.zipFile.readEntries().then(entries => {
expect(entries).to.be.an('array');
expect(entries).to.have.lengthOf(FILES.length);
const fileNames = entries.map(entry => entry.fileName);
expect(fileNames).to.deep.equal(FILES);
it('returns array of `numEntries` entries', function() {
return this.zipFile.readEntries(2).then(entries => {
expect(entries).to.be.an('array');
expect(entries).to.have.lengthOf(2);
const fileNames = entries.map(entry => entry.fileName);
expect(fileNames).to.deep.equal(FILES.slice(0, 2));
});
});
});
});

describe('.walkEntries()', function() {
it('returns a Promise', function() {
const promise = this.zipFile.walkEntries(() => {});
expect(promise).to.be.instanceof(Promise);
return promise;
});
it('when called again, returns next entries', function() {
return this.zipFile.readEntries(2).then(() => {
return this.zipFile.readEntries(2);
}).then(entries => {
expect(entries).to.be.an('array');
expect(entries).to.have.lengthOf(2);
const fileNames = entries.map(entry => entry.fileName);
expect(fileNames).to.deep.equal(FILES.slice(2, 4));
});
});

it('calls callback for each entry', function() {
const entries = [];
return this.zipFile.walkEntries(entry => {
entries.push(entry);
}).then(() => {
const fileNames = entries.map(entry => entry.fileName);
expect(fileNames).to.deep.equal(FILES);
it('with no `numEntries` specified, returns all entries', function() {
return this.zipFile.readEntries().then(entries => {
expect(entries).to.be.an('array');
expect(entries).to.have.lengthOf(FILES.length);
const fileNames = entries.map(entry => entry.fileName);
expect(fileNames).to.deep.equal(FILES);
});
});
});

it('awaits promise returned by callback before reading next entry', function() {
const events = [];
let count = 0;
return this.zipFile.walkEntries(() => {
count++;
events.push(`callback${count}`);

return new Promise(resolve => {
setTimeout(() => {
events.push(`resolve${count}`);
resolve();
}, 100);
describe('.walkEntries()', function() {
it('returns a Promise', function() {
const promise = this.zipFile.walkEntries(() => {});
expect(promise).to.be.instanceof(Promise);
return promise;
});

it('calls callback for each entry', function() {
const entries = [];
return this.zipFile.walkEntries(entry => {
entries.push(entry);
}).then(() => {
const fileNames = entries.map(entry => entry.fileName);
expect(fileNames).to.deep.equal(FILES);
});
}).then(() => {
expect(events).to.deep.equal(['callback1', 'resolve1', 'callback2', 'resolve2', 'callback3', 'resolve3', 'callback4', 'resolve4']);
});
});

it('rejects promise if callback throws', function() {
const err = new Error('test');
const p = this.zipFile.walkEntries(() => {
throw err;
it('awaits promise returned by callback before reading next entry', function() {
const events = [];
let count = 0;
return this.zipFile.walkEntries(() => {
count++;
events.push(`callback${count}`);

return new Promise(resolve => {
setTimeout(() => {
events.push(`resolve${count}`);
resolve();
}, 100);
});
}).then(() => {
expect(events).to.deep.equal(['callback1', 'resolve1', 'callback2', 'resolve2', 'callback3', 'resolve3', 'callback4', 'resolve4']);
});
});
return expect(p).be.rejectedWith(err);
});

it('rejects promise if callback returns rejected promise', function() {
const err = new Error('test');
const p = this.zipFile.walkEntries(() => {
return new Promise((resolve, reject) => reject(err)); // jshint ignore:line
it('rejects promise if callback throws', function() {
const err = new Error('test');
const p = this.zipFile.walkEntries(() => {
throw err;
});
return expect(p).be.rejectedWith(err);
});
return expect(p).be.rejectedWith(err);
});
});
});

describe('Stream methods', function() {
beforeEach(function() {
return method().then(zipFile => {
this.zipFile = zipFile;
return zipFile.readEntry();
}).then(entry => {
this.entry = entry;
it('rejects promise if callback returns rejected promise', function() {
const err = new Error('test');
const p = this.zipFile.walkEntries(() => {
return new Promise((resolve, reject) => reject(err)); // jshint ignore:line
});
return expect(p).be.rejectedWith(err);
});
});
});

afterEach(function() {
return this.zipFile.close();
});

describe('zipFile.openReadStream()', function() {
describe('Stream methods', function() {
beforeEach(function() {
this.promise = this.zipFile.openReadStream(this.entry);
return this.promise.then(stream => {
this.stream = stream;
return method().then(zipFile => {
this.zipFile = zipFile;
return zipFile.readEntry();
}).then(entry => {
this.entry = entry;
});
});

afterEach(function() {
this.stream.on('error', () => {}).destroy();
return this.zipFile.close();
});

it('returns a Promise', function() {
expect(this.promise).to.be.instanceof(Promise);
});
describe('zipFile.openReadStream()', function() {
beforeEach(function() {
this.promise = this.zipFile.openReadStream(this.entry);
return this.promise.then(stream => {
this.stream = stream;
});
});

it('resolves to Readable Stream', function() {
expect(this.stream).to.be.instanceof(ReadableStream);
});
});
afterEach(function() {
this.stream.on('error', () => {}).destroy();
});

describe('entry.openReadStream()', function() {
beforeEach(function() {
this.promise = this.entry.openReadStream();
return this.promise.then(stream => {
this.stream = stream;
it('returns a Promise', function() {
expect(this.promise).to.be.instanceof(Promise);
});
});

afterEach(function() {
this.stream.on('error', () => {}).destroy();
it('resolves to Readable Stream', function() {
expect(this.stream).to.be.instanceof(ReadableStream);
});
});

it('returns a Promise', function() {
expect(this.promise).to.be.instanceof(Promise);
});
describe('entry.openReadStream()', function() {
beforeEach(function() {
this.promise = this.entry.openReadStream();
return this.promise.then(stream => {
this.stream = stream;
});
});

afterEach(function() {
this.stream.on('error', () => {}).destroy();
});

it('resolves to Readable Stream', function() {
expect(this.stream).to.be.instanceof(ReadableStream);
it('returns a Promise', function() {
expect(this.promise).to.be.instanceof(Promise);
});

it('resolves to Readable Stream', function() {
expect(this.stream).to.be.instanceof(ReadableStream);
});
});
});
});

}

0 comments on commit 189787b

Please sign in to comment.