From bf901c2256baba37fb5f53bb727699924cd240d8 Mon Sep 17 00:00:00 2001 From: French Ben Date: Wed, 23 Dec 2015 20:10:57 -0500 Subject: [PATCH] Updated tests to pass Signed-off-by: French Ben --- .eslintrc | 1 + .travis.yml | 3 +-- __mocks__/app.js | 5 +++++ __mocks__/electron.js | 7 +++++++ __tests__/Util-test.js | 20 ++++++++++---------- package.json | 4 ++-- 6 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 __mocks__/app.js create mode 100644 __mocks__/electron.js diff --git a/.eslintrc b/.eslintrc index bde0456e..0f74bd19 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,6 +13,7 @@ env: node: true es6: true browser: true + jest: true extends: "eslint:recommended" diff --git a/.travis.yml b/.travis.yml index 49d2dc07..be3929ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: false language: node_js node_js: - - "4.1" + - "4.2.2" cache: directories: @@ -11,4 +11,3 @@ cache: script: - npm install - npm test - diff --git a/__mocks__/app.js b/__mocks__/app.js new file mode 100644 index 00000000..099bad49 --- /dev/null +++ b/__mocks__/app.js @@ -0,0 +1,5 @@ +module.exports = { + require: jest.genMockFunction(), + match: jest.genMockFunction(), + on: jest.genMockFunction() +}; diff --git a/__mocks__/electron.js b/__mocks__/electron.js new file mode 100644 index 00000000..a2deca4d --- /dev/null +++ b/__mocks__/electron.js @@ -0,0 +1,7 @@ +module.exports = { + require: jest.genMockFunction(), + match: jest.genMockFunction(), + app: jest.genMockFunction(), + remote: jest.genMockFunction(), + dialog: jest.genMockFunction() +}; diff --git a/__tests__/Util-test.js b/__tests__/Util-test.js index 6b4367a8..e891a592 100644 --- a/__tests__/Util-test.js +++ b/__tests__/Util-test.js @@ -1,9 +1,9 @@ -jest.dontMock('../src/utils/Util'); -var util = require('../src/utils/Util'); +jest.dontMock('../src/utils/Util').dontMock('console'); +const util = require('../src/utils/Util'); -describe('Util', function () { - describe('when removing sensitive data', function () { - it('filters ssh certificate data', function () { +describe('Util', () => { + describe('when removing sensitive data', () => { + it('filters ssh certificate data', () => { var testdata = String.raw`time="2015-04-17T21:43:47-04:00" level="debug" msg="executing: ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectionAttempts=30 -o LogLevel=quiet -p 50483 -i /Users/johnappleseed/.docker/machine/machines/dev2/id_rsa docker@localhost sudo mkdir -p /var/lib/boot2docker" time="2015-04-17T21:43:47-04:00" level="debug" msg="executing: ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectionAttempts=30 -o LogLevel=quiet -p 50483 -i /Users/johnappleseed/.docker/machine/machines/dev2/id_rsa docker@localhost echo \"-----BEGIN CERTIFICATE-----\nMIIC+DCCAeKgAwIBAgIRANfIbsa2M94gDY+fBiBiQBkwCwYJKoZIhvcNAQELMBIx\nEDAOBgNVBAoTB2ptb3JnYW4wHhcNMTUwNDE4MDEzODAwWhcNMTgwNDAyMDEzODAw\nWjAPMQ0wCwYDVQQKEwRkZXYyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC\nAQEA1yamWT0bk0pRU7eiStjiXe2jkzdeI0SdJZo+bjczkl6kzNW/FmR/OkcP8gHX\nCO3fUCWkR/+rBgz3nuM1Sy0BIUo0EMQGfx17OqIJPXO+BrpCHsXlphHmbQl5bE2Y\nF+bAsGc6WCippw/caNnIHRsb6zAZVYX2AHLYY0fwIDAQABo1AwTjAOBgNVHQ8BAf8EBAMCAKAwHQYD\nVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMAwGA1UdEwEB/wQCMAAwDwYDVR0R\nBAgwBocEwKhjZTALBgkqhkiG9w0BAQsDggEBAKBdD86+kl4X1VMjgGlNYnc42tWa\nbo1iDl/frxiLkfPSc2McAOm3AqX1ao+ynjqq1XTlBLPTQByu/oNZgA724LRJDfdG\nCKGUV8latW7rB1yhf/SZSmyhNjufuWlgCtbkw7Q/oPddzYuSOdDW8tVok9gMC0vL\naqKCWfVKkCmvGH+8/wPrkYmro/f0uwJ8ee+yrbBPlBE/qE+Lqcfr0YcXEDaS8CmL\nDjWg7KNFpA6M+/tFNQhplbjwRsCt7C4bzQu0aBIG5XH1Jr2HrKlLjWdmluPHWUL6\nX5Vh1bslYJzsSdBNZFWSKShZ+gtRpjtV7NynANDJPQNIRhDxAf4uDY9hA2c=\n-----END CERTIFICATE-----\n\" | sudo tee /var/lib/boot2docker/server.pem" time="2015-04-17T21:43:47-04:00" level="debug" msg="executing: /usr/bin/VBoxManage showvminfo dev2 --machinereadable"`; expect(util.removeSensitiveData(testdata).indexOf('CERTIFICATE')).toEqual(-1); @@ -11,7 +11,7 @@ describe('Util', function () { expect(util.removeSensitiveData(testdata).indexOf('')).toNotEqual(-1); }); - it('filters ssh private key data', function () { + it('filters ssh private key data', () => { var testdata = String.raw`hZbuxglOtQv2AQqOp/luhZ3Y8kDs4cqRzoA1o+k+LAyjEb+Nk\nGA8=\n-----END CERTIFICATE-----\n\" | sudo tee /var/lib/boot2docker/ca.pem" time="2015-04-17T21:43:47-04:00" level="debug" msg="executing: ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectionAttempts=30 -o LogLevel=quiet -p 50483 -i /Users/johnappleseed/.docker/machine/machines/dev2/id_rsa docker@localhost echo \"-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA1yamWT0bk0pRU7eiStjiXe2jkzdeI0SdJZo+bjczkl6kzNW/\nFmR/OkcP8gHXCO3fUCWkR/+rBgz3nuM1Sy0BIUo0EMQGfx17OqIJPXO+BrpCHsXl\nphHmbQl5bE2YF+bAsGc6WCippczQIu5bPweeAkR1WdlkhD08tHD4o1ESe09fXx5G\nXcZFfd2xQWdvAJX3fTuGBk3IMEF2fye5b69zUyVDGbTylyjKDOi9Xxdlc4y9cOPw\nzcwQFCOJiCBYlxDO0fbinA+KigCs29Dd5U3oXbloLr3JQTE/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NRM6qVao3+A7Rf57S/Lv6vldBAKR+OpviSVw5gew7OZ0RYS5caz\nhcEtXKECgYAJb7t67nococm0PsRe8Xv1SQOQjetrhzwzD1PLOSC9TrzwA22/ZktZ\neu/qfvYgOPT4LkDGVCzn8J+TAcUVnIvAnJRQTsBu55uiL8YC5jZQ8E1hBf7kskMq\nh16WD19Djv3WhfBNXBxvnagDDWw5DxmiiKzSf0k3QDDoX7wjDAV1dQ==\n-----END RSA PRIVATE KEY-----\n\" | sudo tee /var/lib/boot2docker/server-key.pem" time="2015-04-17T21:43:47-04:00" level="debug" msg="executing: ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectionAttempts=30 -o LogLevel=quiet -p 50483 -i /Users/johnappleseed/.docker/machine/machines/dev2/id_rsa docker@localhost echo \"-----BEGIN CERTIFICATE-----\nMIIC+DCCAeKgAwIBAgIRANfIbsa2M94gDY+fBiBiQBkwCwYJKoZIhvcNAQELMBIx\nEDAOBg`; @@ -20,7 +20,7 @@ describe('Util', function () { expect(util.removeSensitiveData(testdata).indexOf('')).toNotEqual(-1); }); - it('filters username data', function () { + it('filters username data', () => { var testdata = String.raw`/Users/johnappleseed/.docker/machine/machines/dev2/id_rsa docker@localhost echo`; expect(util.removeSensitiveData(testdata).indexOf('/Users/johnappleseed/')).toEqual(-1); expect(util.removeSensitiveData(testdata).indexOf('/Users//')).toNotEqual(-1); @@ -30,20 +30,20 @@ describe('Util', function () { expect(util.removeSensitiveData(testdata).indexOf('/Users//.docker')).toNotEqual(-1); }); - it('filters Windows username data', function () { + it('filters Windows username data', () => { var testdata = String.raw`C:\\Users\\johnappleseed\\.docker\\machine`; expect(util.removeSensitiveData(testdata).indexOf('johnappleseed')).toEqual(-1); expect(util.removeSensitiveData(testdata).indexOf('')).toNotEqual(-1); }); - it ('returns input if empty or not a string', function () { + it ('returns input if empty or not a string', () => { expect(util.removeSensitiveData('')).toBe(''); expect(util.removeSensitiveData(1)).toBe(1); expect(util.removeSensitiveData(undefined)).toBe(undefined); }); }); - describe('when verifying that a repo is official', function () { + describe('when verifying that a repo is official', () => { it('accepts official repo', () => { expect(util.isOfficialRepo('redis')).toBe(true); }); diff --git a/package.json b/package.json index 49caedb2..c61c40a6 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "devDependencies": { "babel": "^5.8.23", "babel-jest": "^5.2.0", - "electron-prebuilt": "^0.35.4", + "electron-prebuilt": "^0.36", "eslint": "^1.3.1", "eslint-plugin-react": "^3.3.0", "grunt": "^0.4.5", @@ -79,7 +79,7 @@ "grunt-rename": "^0.1.4", "grunt-shell": "^1.1.2", "grunt-shell-spawn": "^0.3.8", - "jest-cli": "^0.5.8", + "jest-cli": "^0.8.2", "jsxhint": "^0.15.1", "load-grunt-tasks": "^3.2.0", "minimist": "^1.1.1",