From 189787b87bda2214c9f09f4e06651841d8a9e5b8 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Sat, 21 Apr 2018 18:38:37 +0100 Subject: [PATCH] Lint: Tests indentation --- changelog.md | 1 + test/all.test.js | 315 +++++++++++++++++++++++------------------------ 2 files changed, 158 insertions(+), 158 deletions(-) diff --git a/changelog.md b/changelog.md index ecdc7fa..ecade6b 100644 --- a/changelog.md +++ b/changelog.md @@ -35,3 +35,4 @@ * `.close` method works for zip files from `.fromBuffer` * Tests for all access methods +* Lint: Tests indentation diff --git a/test/all.test.js b/test/all.test.js index 026ed26..ab4ea17 100644 --- a/test/all.test.js +++ b/test/all.test.js @@ -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); + }); }); }); -}); - }