diff --git a/packages/google-cloud-vision/samples/package.json b/packages/google-cloud-vision/samples/package.json index a3043b8145f..28a99d7e50b 100644 --- a/packages/google-cloud-vision/samples/package.json +++ b/packages/google-cloud-vision/samples/package.json @@ -5,8 +5,7 @@ "license": "Apache Version 2.0", "author": "Google Inc.", "scripts": { - "test": "cd ..; npm run t -- vision/test/*.test.js", - "system-test": "cd ..; npm run st -- vision/system-test/*.test.js" + "test": "cd ..; npm run st -- vision/system-test/*.test.js" }, "dependencies": { "@google-cloud/vision": "0.7.0", diff --git a/packages/google-cloud-vision/samples/quickstart.js b/packages/google-cloud-vision/samples/quickstart.js index fafa46b1a27..e650314dbdf 100644 --- a/packages/google-cloud-vision/samples/quickstart.js +++ b/packages/google-cloud-vision/samples/quickstart.js @@ -31,13 +31,11 @@ const visionClient = Vision({ const fileName = './resources/wakeupcat.jpg'; // Performs label detection on the image file -visionClient.detectLabels(fileName, (err, labels) => { - if (err) { - console.error(err); - return; - } +visionClient.detectLabels(fileName) + .then((results) => { + const labels = results[0]; - console.log('Labels:'); - labels.forEach((label) => console.log(label)); -}); + console.log('Labels:'); + labels.forEach((label) => console.log(label)); + }); // [END vision_quickstart] diff --git a/packages/google-cloud-vision/samples/test/quickstart.test.js b/packages/google-cloud-vision/samples/test/quickstart.test.js deleted file mode 100644 index 9a75af8f179..00000000000 --- a/packages/google-cloud-vision/samples/test/quickstart.test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright 2016, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const proxyquire = require(`proxyquire`).noCallThru(); - -describe(`vision:quickstart`, () => { - let visionMock, VisionMock; - const error = new Error(`error`); - const fileName = `./resources/wakeupcat.jpg`; - - before(() => { - visionMock = { - detectLabels: sinon.stub().yields(error) - }; - VisionMock = sinon.stub().returns(visionMock); - }); - - it(`should handle error`, () => { - proxyquire(`../quickstart`, { - '@google-cloud/vision': VisionMock - }); - - assert.equal(VisionMock.calledOnce, true); - assert.deepEqual(VisionMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); - assert.equal(visionMock.detectLabels.calledOnce, true); - assert.deepEqual(visionMock.detectLabels.firstCall.args.slice(0, -1), [fileName]); - assert.equal(console.error.calledOnce, true); - assert.deepEqual(console.error.firstCall.args, [error]); - }); -});