From 3a1794c114e480f703fbecd210279a73ab1b5236 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Sep 2016 09:44:47 -0700 Subject: [PATCH 1/6] Move tests into test/ folder --- .npmignore | 2 +- test.js => test/test.js | 0 test_404.js => test/test_404.js | 0 test_symbols.js => test/test_symbols.js | 0 test_with_checksum.js => test/test_with_checksum.js | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename test.js => test/test.js (100%) rename test_404.js => test/test_404.js (100%) rename test_symbols.js => test/test_symbols.js (100%) rename test_with_checksum.js => test/test_with_checksum.js (100%) diff --git a/.npmignore b/.npmignore index cc77174dd..88746ae67 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,4 @@ .npmignore .travis.yml appveyor.yml -test*.js +test diff --git a/test.js b/test/test.js similarity index 100% rename from test.js rename to test/test.js diff --git a/test_404.js b/test/test_404.js similarity index 100% rename from test_404.js rename to test/test_404.js diff --git a/test_symbols.js b/test/test_symbols.js similarity index 100% rename from test_symbols.js rename to test/test_symbols.js diff --git a/test_with_checksum.js b/test/test_with_checksum.js similarity index 100% rename from test_with_checksum.js rename to test/test_with_checksum.js From 007dc1b2cc010a7974fb4679e3cf48e2bfbd7af8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Sep 2016 09:57:23 -0700 Subject: [PATCH 2/6] Run tests via tape --- package.json | 5 +++-- test/test.js | 20 +++++++++++--------- test/test_404.js | 24 ++++++++++++------------ test/test_symbols.js | 22 ++++++++++++---------- test/test_with_checksum.js | 22 ++++++++++++---------- 5 files changed, 50 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 13cad5fb9..df5b78646 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "electron-download": "cli.js" }, "scripts": { - "test": "eslint . && node test.js && node test_symbols.js && node test_404.js && node test_with_checksum.js && echo PASSED" + "test": "tape test/*.js && eslint ." }, "repository": { "type": "git", @@ -34,7 +34,8 @@ "eslint": "^3.2.0", "eslint-config-standard": "^5.2.0", "eslint-plugin-promise": "^2.0.0", - "eslint-plugin-standard": "^2.0.0" + "eslint-plugin-standard": "^2.0.0", + "tape": "^4.6.0" }, "eslintConfig": { "extends": "standard", diff --git a/test/test.js b/test/test.js index e16a394f4..0721fd81e 100644 --- a/test/test.js +++ b/test/test.js @@ -1,13 +1,15 @@ 'use strict' -const download = require('./') +const download = require('..') +const test = require('tape') -console.log('Basic test') -download({ - version: '0.25.1', - arch: 'ia32', - platform: 'win32' -}, (err, zipPath) => { - if (err) throw err - console.log('OK! zip:', zipPath) +test('Basic test', (t) => { + download({ + version: '0.25.1', + arch: 'ia32', + platform: 'win32' + }, (err, zipPath) => { + t.error(err, 'The error should be null') + t.end() + }) }) diff --git a/test/test_404.js b/test/test_404.js index e2cb556bb..1f7560c2e 100644 --- a/test/test_404.js +++ b/test/test_404.js @@ -1,16 +1,16 @@ 'use strict' -const download = require('./') +const download = require('..') +const test = require('tape') -console.log('404 test') -download({ - version: '0.25.1', - arch: 'ia32', - platform: 'darwin' -}, (err, zipPath) => { - if (!err) throw Error('Download did not throw an error') - if (err.message !== 'Failed to find Electron v0.25.1 for darwin-ia32 at https://github.com/electron/electron/releases/download/v0.25.1/electron-v0.25.1-darwin-ia32.zip') { - throw Error('Download did not throw an error with a custom 404 message: ' + err.message) - } - console.log('OK! got expected error:', err.message) +test('404 test', (t) => { + download({ + version: '0.25.1', + arch: 'ia32', + platform: 'darwin' + }, (err, zipPath) => { + if (!err) t.fail('Download did not throw an error') + t.equal(err.message, 'Failed to find Electron v0.25.1 for darwin-ia32 at https://github.com/electron/electron/releases/download/v0.25.1/electron-v0.25.1-darwin-ia32.zip', 'Error message should contain version and URL') + t.end() + }) }) diff --git a/test/test_symbols.js b/test/test_symbols.js index 0da40cd7c..34383a4c4 100644 --- a/test/test_symbols.js +++ b/test/test_symbols.js @@ -1,14 +1,16 @@ 'use strict' -const download = require('./') +const download = require('..') +const test = require('tape') -console.log('Symbols test') -download({ - version: '0.26.1', - arch: 'x64', - platform: 'darwin', - symbols: 'true' -}, (err, zipPath) => { - if (err) throw err - console.log('OK! zip:', zipPath) +test('Symbols test', (t) => { + download({ + version: '0.26.1', + arch: 'x64', + platform: 'darwin', + symbols: 'true' + }, (err, zipPath) => { + t.error(err, 'The error should be null') + t.end() + }) }) diff --git a/test/test_with_checksum.js b/test/test_with_checksum.js index b6e5dd298..feef6714b 100644 --- a/test/test_with_checksum.js +++ b/test/test_with_checksum.js @@ -1,14 +1,16 @@ 'use strict' -const download = require('./') +const download = require('..') +const test = require('tape') -console.log('Checksum test') -download({ - version: '1.3.3', - arch: 'x64', - platform: 'win32', - symbols: true -}, (err, zipPath) => { - if (err) throw err - console.log('OK! zip:', zipPath) +test('Checksum test', (t) => { + download({ + version: '1.3.3', + arch: 'x64', + platform: 'win32', + symbols: true + }, (err, zipPath) => { + t.error(err, 'The error should be null') + t.end() + }) }) From 8106d1ae0736062db0eab9803b7540afd15945e5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Sep 2016 10:01:44 -0700 Subject: [PATCH 3/6] Assert zip path exists and is non-empty --- test/test.js | 5 ++++- test/test_404.js | 4 +++- test/test_symbols.js | 5 ++++- test/test_with_checksum.js | 5 ++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/test/test.js b/test/test.js index 0721fd81e..60306c918 100644 --- a/test/test.js +++ b/test/test.js @@ -1,6 +1,7 @@ 'use strict' const download = require('..') +const fs = require('fs') const test = require('tape') test('Basic test', (t) => { @@ -9,7 +10,9 @@ test('Basic test', (t) => { arch: 'ia32', platform: 'win32' }, (err, zipPath) => { - t.error(err, 'The error should be null') + t.error(err, 'Error should be null') + t.equal(fs.statSync(zipPath).isFile(), true, 'Zip path should exist') + t.notEqual(fs.statSync(zipPath).size, 0, 'Zip path should be non-empty') t.end() }) }) diff --git a/test/test_404.js b/test/test_404.js index 1f7560c2e..49a0a734c 100644 --- a/test/test_404.js +++ b/test/test_404.js @@ -1,6 +1,7 @@ 'use strict' const download = require('..') +const fs = require('fs') const test = require('tape') test('404 test', (t) => { @@ -9,7 +10,8 @@ test('404 test', (t) => { arch: 'ia32', platform: 'darwin' }, (err, zipPath) => { - if (!err) t.fail('Download did not throw an error') + if (!err) t.fail('Download should throw an error') + t.equal(fs.existsSync(zipPath), false, 'Zip path should not exist') t.equal(err.message, 'Failed to find Electron v0.25.1 for darwin-ia32 at https://github.com/electron/electron/releases/download/v0.25.1/electron-v0.25.1-darwin-ia32.zip', 'Error message should contain version and URL') t.end() }) diff --git a/test/test_symbols.js b/test/test_symbols.js index 34383a4c4..b856a6682 100644 --- a/test/test_symbols.js +++ b/test/test_symbols.js @@ -1,6 +1,7 @@ 'use strict' const download = require('..') +const fs = require('fs') const test = require('tape') test('Symbols test', (t) => { @@ -10,7 +11,9 @@ test('Symbols test', (t) => { platform: 'darwin', symbols: 'true' }, (err, zipPath) => { - t.error(err, 'The error should be null') + t.error(err, 'Error should be null') + t.equal(fs.statSync(zipPath).isFile(), true, 'Zip path should exist') + t.notEqual(fs.statSync(zipPath).size, 0, 'Zip path should be non-empty') t.end() }) }) diff --git a/test/test_with_checksum.js b/test/test_with_checksum.js index feef6714b..55260697a 100644 --- a/test/test_with_checksum.js +++ b/test/test_with_checksum.js @@ -1,6 +1,7 @@ 'use strict' const download = require('..') +const fs = require('fs') const test = require('tape') test('Checksum test', (t) => { @@ -10,7 +11,9 @@ test('Checksum test', (t) => { platform: 'win32', symbols: true }, (err, zipPath) => { - t.error(err, 'The error should be null') + t.error(err, 'Error should be null') + t.equal(fs.statSync(zipPath).isFile(), true, 'Zip path should exist') + t.notEqual(fs.statSync(zipPath).size, 0, 'Zip path should be non-empty') t.end() }) }) From fcd13745a854a7d9118d1048f06ab787383d9864 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Sep 2016 10:07:32 -0700 Subject: [PATCH 4/6] Specify symbols as boolean --- test/test_symbols.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_symbols.js b/test/test_symbols.js index b856a6682..317f69485 100644 --- a/test/test_symbols.js +++ b/test/test_symbols.js @@ -9,7 +9,7 @@ test('Symbols test', (t) => { version: '0.26.1', arch: 'x64', platform: 'darwin', - symbols: 'true' + symbols: true }, (err, zipPath) => { t.error(err, 'Error should be null') t.equal(fs.statSync(zipPath).isFile(), true, 'Zip path should exist') From 34ec513b6556a74a6927e39b4357d73637f0ff0c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Sep 2016 10:15:31 -0700 Subject: [PATCH 5/6] Add helper to verify downloaded zip --- test/helpers.js | 9 +++++++++ test/test.js | 6 ++---- test/test_symbols.js | 6 ++---- test/test_with_checksum.js | 6 ++---- 4 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 test/helpers.js diff --git a/test/helpers.js b/test/helpers.js new file mode 100644 index 000000000..56d9d1bb1 --- /dev/null +++ b/test/helpers.js @@ -0,0 +1,9 @@ +'use strict' + +const fs = require('fs') + +exports.verifyDownloadedZip = (t, err, zipPath) => { + t.error(err, 'Error should be null') + t.equal(fs.statSync(zipPath).isFile(), true, 'Zip path should exist') + t.notEqual(fs.statSync(zipPath).size, 0, 'Zip path should be non-empty') +} diff --git a/test/test.js b/test/test.js index 60306c918..10b5524f2 100644 --- a/test/test.js +++ b/test/test.js @@ -1,8 +1,8 @@ 'use strict' const download = require('..') -const fs = require('fs') const test = require('tape') +const verifyDownloadedZip = require('./helpers').verifyDownloadedZip test('Basic test', (t) => { download({ @@ -10,9 +10,7 @@ test('Basic test', (t) => { arch: 'ia32', platform: 'win32' }, (err, zipPath) => { - t.error(err, 'Error should be null') - t.equal(fs.statSync(zipPath).isFile(), true, 'Zip path should exist') - t.notEqual(fs.statSync(zipPath).size, 0, 'Zip path should be non-empty') + verifyDownloadedZip(t, err, zipPath) t.end() }) }) diff --git a/test/test_symbols.js b/test/test_symbols.js index 317f69485..52d89ceb1 100644 --- a/test/test_symbols.js +++ b/test/test_symbols.js @@ -1,8 +1,8 @@ 'use strict' const download = require('..') -const fs = require('fs') const test = require('tape') +const verifyDownloadedZip = require('./helpers').verifyDownloadedZip test('Symbols test', (t) => { download({ @@ -11,9 +11,7 @@ test('Symbols test', (t) => { platform: 'darwin', symbols: true }, (err, zipPath) => { - t.error(err, 'Error should be null') - t.equal(fs.statSync(zipPath).isFile(), true, 'Zip path should exist') - t.notEqual(fs.statSync(zipPath).size, 0, 'Zip path should be non-empty') + verifyDownloadedZip(t, err, zipPath) t.end() }) }) diff --git a/test/test_with_checksum.js b/test/test_with_checksum.js index 55260697a..9b4ef2b93 100644 --- a/test/test_with_checksum.js +++ b/test/test_with_checksum.js @@ -1,8 +1,8 @@ 'use strict' const download = require('..') -const fs = require('fs') const test = require('tape') +const verifyDownloadedZip = require('./helpers').verifyDownloadedZip test('Checksum test', (t) => { download({ @@ -11,9 +11,7 @@ test('Checksum test', (t) => { platform: 'win32', symbols: true }, (err, zipPath) => { - t.error(err, 'Error should be null') - t.equal(fs.statSync(zipPath).isFile(), true, 'Zip path should exist') - t.notEqual(fs.statSync(zipPath).size, 0, 'Zip path should be non-empty') + verifyDownloadedZip(t, err, zipPath) t.end() }) }) From 85fad596af48f5f6abee1611f8b41518ff424c6e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Sep 2016 10:18:53 -0700 Subject: [PATCH 6/6] Assert path ends with -symbols.zip --- test/test_symbols.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_symbols.js b/test/test_symbols.js index 52d89ceb1..3f36fbe9a 100644 --- a/test/test_symbols.js +++ b/test/test_symbols.js @@ -12,6 +12,7 @@ test('Symbols test', (t) => { symbols: true }, (err, zipPath) => { verifyDownloadedZip(t, err, zipPath) + t.ok(/-symbols\.zip$/.test(zipPath), 'Zip path should end with -symbols.zip') t.end() }) })