@@ -21,6 +21,9 @@ const test = require(`ava`);
21
21
const tools = require ( `@google-cloud/nodejs-repo-tools` ) ;
22
22
const uuid = require ( `uuid` ) ;
23
23
24
+ const vision = require ( '@google-cloud/vision' ) ;
25
+ const client = new vision . ImageAnnotatorClient ( ) ;
26
+
24
27
const bucketName = `nodejs-docs-samples-test-${ uuid . v4 ( ) } ` ;
25
28
const cmd = `node detect.js` ;
26
29
const cwd = path . join ( __dirname , `..` ) ;
@@ -195,25 +198,55 @@ test(`should detect crop hints in a remote file`, async t => {
195
198
196
199
test ( `should detect similar web images in a local file` , async t => {
197
200
const output = await tools . runAsync ( `${ cmd } web ${ files [ 5 ] . localPath } ` , cwd ) ;
198
- t . true ( output . includes ( 'Full matches found:' ) ) ;
199
- t . true ( output . includes ( 'Partial matches found:' ) ) ;
200
- t . true ( output . includes ( 'Web entities found:' ) ) ;
201
- t . true ( output . includes ( 'Description: Google Cloud Platform' ) ) ;
202
- t . true ( output . includes ( 'Best guess labels found' ) ) ;
203
- t . true ( output . includes ( 'Label:' ) ) ;
201
+
202
+ const [ results ] = await client . webDetection ( files [ 5 ] . localPath ) ;
203
+ const webDetection = results [ 0 ] . webDetection ;
204
+
205
+ if ( webDetection . fullMatchingImages . length ) {
206
+ t . true ( output . includes ( 'Full matches found:' ) ) ;
207
+ }
208
+
209
+ if ( webDetection . partialMatchingImages . length ) {
210
+ t . true ( output . includes ( 'Partial matches found:' ) ) ;
211
+ }
212
+
213
+ if ( webDetection . webEntities . length ) {
214
+ t . true ( output . includes ( 'Web entities found:' ) ) ;
215
+ t . true ( output . includes ( 'Description: Google Cloud Platform' ) ) ;
216
+ }
217
+
218
+ if ( webDetection . bestGuessLabels . length ) {
219
+ t . true ( output . includes ( 'Best guess labels found' ) ) ;
220
+ t . true ( output . includes ( 'Label:' ) ) ;
221
+ }
204
222
} ) ;
205
223
206
224
test ( `should detect similar web images in a remote file` , async t => {
207
225
const output = await tools . runAsync (
208
226
`${ cmd } web-gcs ${ bucketName } ${ files [ 5 ] . name } ` ,
209
227
cwd
210
228
) ;
211
- t . true ( output . includes ( 'Full matches found:' ) ) ;
212
- t . true ( output . includes ( 'Partial matches found:' ) ) ;
213
- t . true ( output . includes ( 'Web entities found:' ) ) ;
214
- t . true ( output . includes ( 'Description: Google Cloud Platform' ) ) ;
215
- t . true ( output . includes ( 'Best guess labels found' ) ) ;
216
- t . true ( output . includes ( 'Label:' ) ) ;
229
+
230
+ const [ results ] = await client . webDetection ( `gs://${ bucketName } /${ files [ 5 ] . name } ` ) ;
231
+ const webDetection = results [ 0 ] . webDetection ;
232
+
233
+ if ( webDetection . fullMatchingImages . length ) {
234
+ t . true ( output . includes ( 'Full matches found:' ) ) ;
235
+ }
236
+
237
+ if ( webDetection . partialMatchingImages . length ) {
238
+ t . true ( output . includes ( 'Partial matches found:' ) ) ;
239
+ }
240
+
241
+ if ( webDetection . webEntities . length ) {
242
+ t . true ( output . includes ( 'Web entities found:' ) ) ;
243
+ t . true ( output . includes ( 'Description: Google Cloud Platform' ) ) ;
244
+ }
245
+
246
+ if ( webDetection . bestGuessLabels . length ) {
247
+ t . true ( output . includes ( 'Best guess labels found' ) ) ;
248
+ t . true ( output . includes ( 'Label:' ) ) ;
249
+ }
217
250
} ) ;
218
251
219
252
test ( `should detect web entities with geo metadata in local file` , async t => {
0 commit comments