diff --git a/vision/samples/package.json b/vision/samples/package.json index e6dee3aca7..7a49219afe 100644 --- a/vision/samples/package.json +++ b/vision/samples/package.json @@ -23,7 +23,6 @@ "devDependencies": { "@google-cloud/storage": "^2.0.0", "chai": "^4.2.0", - "execa": "^1.0.0", "mocha": "^6.0.0", "uuid": "^3.2.1" } diff --git a/vision/samples/system-test/async-batch-annotate-images.test.js b/vision/samples/system-test/async-batch-annotate-images.test.js index 87cf55b29f..6de8169fac 100644 --- a/vision/samples/system-test/async-batch-annotate-images.test.js +++ b/vision/samples/system-test/async-batch-annotate-images.test.js @@ -17,11 +17,12 @@ const path = require('path'); const {Storage} = require('@google-cloud/storage'); -const execa = require('execa'); +const cp = require('child_process'); const {assert} = require('chai'); const uuid = require('uuid'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + const storage = new Storage(); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; const cmd = `node async-batch-annotate-images.js`; @@ -46,7 +47,7 @@ describe(`detect v1 p4 beta1`, () => { }); it(`should annotate the remote landmark.jpg sample`, async () => { - const output = await exec( + const output = execSync( `${cmd} gs://${bucketName}/${files[1].name} gs://${bucketName}/out/` ); assert.match(output, /Json saved to: gs:\/\//); diff --git a/vision/samples/system-test/batch-annotate-files-gcs.test.js b/vision/samples/system-test/batch-annotate-files-gcs.test.js index 2651a23da9..29742a3301 100644 --- a/vision/samples/system-test/batch-annotate-files-gcs.test.js +++ b/vision/samples/system-test/batch-annotate-files-gcs.test.js @@ -17,11 +17,12 @@ const path = require('path'); const {Storage} = require('@google-cloud/storage'); -const execa = require('execa'); +const cp = require('child_process'); const {assert} = require('chai'); const uuid = require('uuid'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + const storage = new Storage(); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; const cmd = `node batch-annotate-files-gcs.js`; @@ -46,7 +47,7 @@ describe(`detect v1 p4 beta1`, () => { }); it(`should annotate the remote pdf-ocr.pdf in GCS bucket`, async () => { - const output = await exec(`${cmd} gs://${bucketName}/${files[0].name}`); + const output = execSync(`${cmd} gs://${bucketName}/${files[0].name}`); assert.match(output, /Word text: Boring/); assert.match(output, /Symbol: p/); }); diff --git a/vision/samples/system-test/batch-annotate-files.test.js b/vision/samples/system-test/batch-annotate-files.test.js index 7eb8d5f45c..0587a72d9e 100644 --- a/vision/samples/system-test/batch-annotate-files.test.js +++ b/vision/samples/system-test/batch-annotate-files.test.js @@ -17,11 +17,12 @@ const path = require('path'); const {Storage} = require('@google-cloud/storage'); -const execa = require('execa'); +const cp = require('child_process'); const {assert} = require('chai'); const uuid = require('uuid'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + const storage = new Storage(); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; const cmd = `node batch-annotate-files.js`; @@ -46,7 +47,7 @@ describe(`detect v1 p4 beta1`, () => { }); it(`should annotate the local pdf-ocr.pdf sample`, async () => { - const output = await exec(`${cmd} ${files[0].localPath}`); + const output = execSync(`${cmd} ${files[0].localPath}`); assert.match(output, /Word text: Boring/); assert.match(output, /Symbol: p/); }); diff --git a/vision/samples/system-test/detect.test.js b/vision/samples/system-test/detect.test.js index 8b55752168..ee467502e7 100644 --- a/vision/samples/system-test/detect.test.js +++ b/vision/samples/system-test/detect.test.js @@ -17,12 +17,13 @@ const path = require('path'); const {Storage} = require('@google-cloud/storage'); -const execa = require('execa'); +const cp = require('child_process'); const uuid = require('uuid'); const {assert} = require('chai'); const vision = require('@google-cloud/vision'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + const client = new vision.ImageAnnotatorClient(); const storage = new Storage(); @@ -61,41 +62,37 @@ describe(`detect`, () => { }); it(`should detect faces in a local file`, async () => { - const output = await exec(`${cmd} faces ${files[0].localPath}`); + const output = execSync(`${cmd} faces ${files[0].localPath}`); assert.match(output, /Faces:/); assert.match(output, /Face #1:/); }); it(`should detect faces in a remote file`, async () => { - const output = await exec( - `${cmd} faces-gcs ${bucketName} ${files[0].name}` - ); + const output = execSync(`${cmd} faces-gcs ${bucketName} ${files[0].name}`); assert.match(output, /Faces:/); assert.match(output, /Face #1:/); }); it(`should detect labels in a local file`, async () => { - const output = await exec(`${cmd} labels ${files[4].localPath}`); + const output = execSync(`${cmd} labels ${files[4].localPath}`); assert.match(output, /Labels:/); assert.match(output, /cat/); }); it(`should detect labels in a remote file`, async () => { - const output = await exec( - `${cmd} labels-gcs ${bucketName} ${files[4].name}` - ); + const output = execSync(`${cmd} labels-gcs ${bucketName} ${files[4].name}`); assert.match(output, /Labels:/); assert.match(output, /cat/); }); it(`should detect landmarks in a local file`, async () => { - const output = await exec(`${cmd} landmarks ${files[1].localPath}`); + const output = execSync(`${cmd} landmarks ${files[1].localPath}`); assert.match(output, /Landmarks:/); assert.match(output, /Palace of Fine Arts/); }); it(`should detect landmarks in a remote file`, async () => { - const output = await exec( + const output = execSync( `${cmd} landmarks-gcs ${bucketName} ${files[1].name}` ); assert.match(output, /Landmarks:/); @@ -103,39 +100,37 @@ describe(`detect`, () => { }); it(`should detect text in a local file`, async () => { - const output = await exec(`${cmd} text ${files[3].localPath}`); + const output = execSync(`${cmd} text ${files[3].localPath}`); assert.match(output, /Text:/); assert.match(output, /System Software Update/); }); it(`should detect text in a remote file`, async () => { - const output = await exec(`${cmd} text-gcs ${bucketName} ${files[3].name}`); + const output = execSync(`${cmd} text-gcs ${bucketName} ${files[3].name}`); assert.match(output, /Text:/); assert.match(output, /System Software Update/); }); it(`should detect logos in a local file`, async () => { - const output = await exec(`${cmd} logos ${files[9].localPath}`); + const output = execSync(`${cmd} logos ${files[9].localPath}`); assert.match(output, /Logos:/); assert.match(output, /google/); }); it(`should detect logos in a remote file`, async () => { - const output = await exec( - `${cmd} logos-gcs ${bucketName} ${files[9].name}` - ); + const output = execSync(`${cmd} logos-gcs ${bucketName} ${files[9].name}`); assert.match(output, /Logos:/); assert.match(output, /google/); }); it(`should detect properties in a local file`, async () => { - const output = await exec(`${cmd} properties ${files[1].localPath}`); + const output = execSync(`${cmd} properties ${files[1].localPath}`); assert.match(output, /{ color: { red: 69, green: 42, blue: 27/); assert.ok(output.split(`\n`).length > 4, `Multiple colors were detected.`); }); it(`should detect properties in a remote file`, async () => { - const output = await exec( + const output = execSync( `${cmd} properties-gcs ${bucketName} ${files[1].name}` ); assert.match(output, /{ color: { red: 69, green: 42, blue: 27/); @@ -143,34 +138,32 @@ describe(`detect`, () => { }); it(`should detect safe-search in a local file`, async () => { - const output = await exec(`${cmd} safe-search ${files[4].localPath}`); + const output = execSync(`${cmd} safe-search ${files[4].localPath}`); assert.match(output, /VERY_LIKELY/); assert.match(output, /Racy:/); }); it(`should detect safe-search in a remote file`, async () => { - const output = await exec( + const output = execSync( `${cmd} safe-search-gcs ${bucketName} ${files[4].name}` ); assert.match(output, /Medical:/); }); it(`should detect crop hints in a local file`, async () => { - const output = await exec(`${cmd} crops ${files[2].localPath}`); + const output = execSync(`${cmd} crops ${files[2].localPath}`); assert.match(output, /Crop Hint 0:/); assert.match(output, /Bound 2: \(280, 43\)/); }); it(`should detect crop hints in a remote file`, async () => { - const output = await exec( - `${cmd} crops-gcs ${bucketName} ${files[2].name}` - ); + const output = execSync(`${cmd} crops-gcs ${bucketName} ${files[2].name}`); assert.match(output, /Crop Hint 0:/); assert.match(output, /Bound 2: \(280, 43\)/); }); it(`should detect similar web images in a local file`, async () => { - const output = await exec(`${cmd} web ${files[5].localPath}`); + const output = execSync(`${cmd} web ${files[5].localPath}`); const [results] = await client.webDetection(files[5].localPath); const webDetection = results.webDetection; @@ -195,7 +188,7 @@ describe(`detect`, () => { }); it(`should detect similar web images in a remote file`, async () => { - const output = await exec(`${cmd} web-gcs ${bucketName} ${files[5].name}`); + const output = execSync(`${cmd} web-gcs ${bucketName} ${files[5].name}`); const [results] = await client.webDetection( `gs://${bucketName}/${files[5].name}` @@ -222,14 +215,14 @@ describe(`detect`, () => { }); it(`should detect web entities with geo metadata in local file`, async () => { - const output = await exec(`${cmd} web-geo ${files[1].localPath}`); + const output = execSync(`${cmd} web-geo ${files[1].localPath}`); assert.match(output, /Description:/); assert.match(output, /Score:/); assert.match(output, /Rome/); }); it(`should detect web entities with geo metadata in remote file`, async () => { - const output = await exec( + const output = execSync( `${cmd} web-geo-gcs ${bucketName} ${files[1].name}` ); assert.match(output, /Description:/); @@ -238,35 +231,35 @@ describe(`detect`, () => { }); it(`should read a document from a local file`, async () => { - const output = await exec(`${cmd} fulltext ${files[2].localPath}`); + const output = execSync(`${cmd} fulltext ${files[2].localPath}`); assert.match(output, /Google Cloud Platform/); assert.match(output, /Word text: Cloud/); assert.match(output, /Word confidence: 0.9/); }); it(`should read a document from a remote file`, async () => { - const output = await exec( + const output = execSync( `${cmd} fulltext-gcs ${bucketName} ${files[2].name}` ); assert.match(output, /Google Cloud Platform/); }); it(`should extract text from pdf file`, async () => { - const output = await exec( + const output = execSync( `${cmd} pdf ${bucketName} ${files[7].name} ${prefix}` ); assert.match(output, /results/); }); it(`should detect objects in a local file`, async () => { - const output = await exec(`${cmd} localize-objects ${files[8].localPath}`); + const output = execSync(`${cmd} localize-objects ${files[8].localPath}`); assert.match(output, /Name: Bird/); assert.match(output, /Name: Duck/); assert.match(output, /Name: Toy/); }); it(`should detect objects in a remote file`, async () => { - const output = await exec( + const output = execSync( `${cmd} localize-objects-gcs gs://${bucketName}/${files[8].name}` ); assert.match(output, /Name: Bird/); diff --git a/vision/samples/system-test/detect.v1p1beta1.test.js b/vision/samples/system-test/detect.v1p1beta1.test.js index 0554e56a67..ce7352194f 100644 --- a/vision/samples/system-test/detect.v1p1beta1.test.js +++ b/vision/samples/system-test/detect.v1p1beta1.test.js @@ -16,10 +16,11 @@ 'use strict'; const path = require('path'); -const execa = require('execa'); +const cp = require('child_process'); const {assert} = require('chai'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + const cmd = `node detect.v1p1beta1.js`; const files = [`text.jpg`, `wakeupcat.jpg`, `landmark.jpg`, `city.jpg`].map( name => { @@ -32,25 +33,25 @@ const files = [`text.jpg`, `wakeupcat.jpg`, `landmark.jpg`, `city.jpg`].map( describe(`detect v1 p1 beta1`, () => { it(`should extract text from image file and print confidence`, async () => { - const output = await exec(`${cmd} fulltext ${files[0].localPath}`); + const output = execSync(`${cmd} fulltext ${files[0].localPath}`); assert.match(output, /Word text: class/); assert.match(output, /Word confidence:/); }); it(`should detect safe search properties from image file`, async () => { - const output = await exec(`${cmd} safe-search ${files[1].localPath}`); + const output = execSync(`${cmd} safe-search ${files[1].localPath}`); assert.match(output, /VERY_LIKELY/); assert.match(output, /Racy:/); }); it(`should detect web entities including best guess labels`, async () => { - const output = await exec(`${cmd} web ${files[2].localPath}`); + const output = execSync(`${cmd} web ${files[2].localPath}`); assert.match(output, /Description: Palace Of Fine Arts/); assert.match(output, /Best guess label: palace of fine arts/); }); it(`should detect web entities using geographical metadata`, async () => { - const output = await exec(`${cmd} web-entities-geo ${files[3].localPath}`); + const output = execSync(`${cmd} web-entities-geo ${files[3].localPath}`); assert.match(output, /Score:/); }); }); diff --git a/vision/samples/system-test/detect.v1p3beta1.test.js b/vision/samples/system-test/detect.v1p3beta1.test.js index 3ddba915ed..1cf091f09c 100644 --- a/vision/samples/system-test/detect.v1p3beta1.test.js +++ b/vision/samples/system-test/detect.v1p3beta1.test.js @@ -17,11 +17,12 @@ const path = require('path'); const {Storage} = require('@google-cloud/storage'); -const execa = require('execa'); +const cp = require('child_process'); const {assert} = require('chai'); const uuid = require('uuid'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + const storage = new Storage(); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; const cmd = `node detect.v1p3beta1.js`; @@ -49,12 +50,12 @@ describe(`detect v1 p3 beta1`, () => { }); it(`should read handwriting in local handwritten.jpg sample`, async () => { - const output = await exec(`${cmd} detectHandwriting ${files[1]}`); + const output = execSync(`${cmd} detectHandwriting ${files[1]}`); assert.match(output, /hand written message/); }); it(`should read handwriting from handwritten.jpg in GCS bucket`, async () => { - const output = await exec( + const output = execSync( `${cmd} detectHandwritingGCS gs://${bucketName}/${files[1].name}` ); assert.match(output, /hand written message/); diff --git a/vision/samples/system-test/faceDetection.test.js b/vision/samples/system-test/faceDetection.test.js index 0cc297a801..564baedd86 100644 --- a/vision/samples/system-test/faceDetection.test.js +++ b/vision/samples/system-test/faceDetection.test.js @@ -17,16 +17,17 @@ const path = require('path'); const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const exec = async cmd => (await execa.shell(cmd)).stdout; const cmd = `node faceDetection.js`; const inputFile = path.join(__dirname, '../resources', 'face.png'); const outputFile = path.join(__dirname, '../../', 'out.png'); describe(`face detection`, () => { it(`should detect faces`, async () => { - const output = await exec(`${cmd} ${inputFile} ${outputFile}`); + const output = execSync(`${cmd} ${inputFile} ${outputFile}`); assert.match(output, /Found 1 face/); assert.match(output, /Highlighting.../); assert.match(output, /Finished!/); diff --git a/vision/samples/system-test/importProductSets.test.js b/vision/samples/system-test/importProductSets.test.js index 4290790b38..b029da69af 100644 --- a/vision/samples/system-test/importProductSets.test.js +++ b/vision/samples/system-test/importProductSets.test.js @@ -16,9 +16,10 @@ 'use strict'; const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const exec = async cmd => (await execa.shell(cmd)).stdout; const cmd = `node productSearch/importProductSets.js`; //Shared fixture data for product tests @@ -30,7 +31,7 @@ const testImportProductSets = { describe(`import product sets`, () => { it(`should import a Product Set`, async () => { - const output = await exec( + const output = execSync( `${cmd} importProductSets "${testImportProductSets.projectId}" "${ testImportProductSets.location }" "${testImportProductSets.gcsUri}"` diff --git a/vision/samples/system-test/productSearch.test.js b/vision/samples/system-test/productSearch.test.js index fd336b8c4e..f0ab06a85d 100644 --- a/vision/samples/system-test/productSearch.test.js +++ b/vision/samples/system-test/productSearch.test.js @@ -18,10 +18,11 @@ const uuid = require('uuid'); const vision = require('@google-cloud/vision'); const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const productSearchClient = new vision.ProductSearchClient(); -const exec = async cmd => (await execa.shell(cmd)).stdout; const cmd = `node productSearch/productSearch.js`; // Shared fixture data for product tests @@ -94,7 +95,7 @@ describe(`product search`, () => { }); it(`should add product to product set`, async () => { - const output = await exec( + const output = execSync( `${cmd} addProductToProductSet "${testProductSet.projectId}" "${ testProductSet.location }" "${testProductSet.productId}" "${testProductSet.productSetId}"` @@ -103,7 +104,7 @@ describe(`product search`, () => { }); it(`should remove a product from a product set`, async () => { - const output = await exec( + const output = execSync( `${cmd} removeProductFromProductSet "${testProductSet.projectId}" "${ testProductSet.location }" "${testProductSet.productId}" "${testProductSet.productSetId}"` diff --git a/vision/samples/system-test/productSets.test.js b/vision/samples/system-test/productSets.test.js index 0e431d696e..a6c8838ed4 100644 --- a/vision/samples/system-test/productSets.test.js +++ b/vision/samples/system-test/productSets.test.js @@ -18,10 +18,11 @@ const uuid = require('uuid'); const vision = require('@google-cloud/vision'); const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const productSearch = new vision.ProductSearchClient(); -const exec = async cmd => (await execa.shell(cmd)).stdout; const cmd = `node productSearch/productSets.js`; // Shared fixture data for product tests @@ -91,7 +92,7 @@ describe(`product sets`, () => { assert.strictEqual(await getProductSetOrFalse(newProductSetPath), false); testProductSet.createdProductSetPaths.push(newProductSetPath); - const output = await exec( + const output = execSync( `${cmd} createProductSet "${testProductSet.projectId}" "${ testProductSet.location }" "${newProductSetId}" "${testProductSet.productSetDisplayName}"` @@ -107,7 +108,7 @@ describe(`product sets`, () => { }); it(`should get product set`, async () => { - const output = await exec( + const output = execSync( `${cmd} getProductSet "${testProductSet.projectId}" "${ testProductSet.location }" "${testProductSet.productSetId}"` @@ -126,7 +127,7 @@ describe(`product sets`, () => { }); it(`should list product sets`, async () => { - const output = await exec( + const output = execSync( `${cmd} listProductSets "${testProductSet.projectId}" "${ testProductSet.location }"` @@ -150,7 +151,7 @@ describe(`product sets`, () => { }); assert.ok(productSet); - const output = await exec( + const output = execSync( `${cmd} deleteProductSet "${testProductSet.projectId}" "${ testProductSet.location }" "${testProductSet.productSetId}"` diff --git a/vision/samples/system-test/products.test.js b/vision/samples/system-test/products.test.js index 0de32dfe73..9c399f504f 100644 --- a/vision/samples/system-test/products.test.js +++ b/vision/samples/system-test/products.test.js @@ -18,9 +18,10 @@ const uuid = require('uuid'); const vision = require('@google-cloud/vision'); const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const exec = async cmd => (await execa.shell(cmd)).stdout; const cmd = `node productSearch/products.js`; const productSearch = new vision.ProductSearchClient(); @@ -90,7 +91,7 @@ describe(`products`, () => { const maybeProduct = await getProductOrFalse(newProductPath); assert.strictEqual(maybeProduct, false); - let output = await exec( + let output = execSync( `${cmd} createProduct "${testProduct.projectId}" "${ testProduct.location }" "${newProductId}" "${testProduct.productDisplayName}" "${ @@ -104,7 +105,7 @@ describe(`products`, () => { assert.ok(newProduct.displayName === testProduct.productDisplayName); assert.ok(newProduct.productCategory === testProduct.productCategory); - output = await exec( + output = execSync( `${cmd} deleteProduct "${testProduct.projectId}" "${ testProduct.location }" "${newProductId}"` @@ -120,7 +121,7 @@ describe(`products`, () => { newProductId ); assert.strictEqual(await getProductOrFalse(newProductPath), false); - let output = await exec( + let output = execSync( `${cmd} createProduct "${testProduct.projectId}" "${ testProduct.location }" "${newProductId}" "${testProduct.productDisplayName}" "${ @@ -130,7 +131,7 @@ describe(`products`, () => { assert.match(output, new RegExp(`Product name: ${newProductPath}`)); - output = await exec( + output = execSync( `${cmd} getProduct "${testProduct.projectId}" "${ testProduct.location }" "${newProductId}"` @@ -146,7 +147,7 @@ describe(`products`, () => { ); assert.match(output, /Product labels:/); - output = await exec( + output = execSync( `${cmd} deleteProduct "${testProduct.projectId}" "${ testProduct.location }" "${newProductId}"` @@ -155,7 +156,7 @@ describe(`products`, () => { }); it(`should list products`, async () => { - const output = await exec( + const output = execSync( `${cmd} listProducts "${testProduct.projectId}" "${testProduct.location}"` ); assert.match(output, new RegExp(`Product id: ${testProduct.productId}`)); @@ -169,7 +170,7 @@ describe(`products`, () => { testProduct.location, newProductId ); - let output = await exec( + let output = execSync( `${cmd} createProduct "${testProduct.projectId}" "${ testProduct.location }" "${newProductId}" "${testProduct.productDisplayName}" "${ @@ -178,7 +179,7 @@ describe(`products`, () => { ); assert.match(output, new RegExp(`Product name: ${newProductPath}`)); - output = await exec( + output = execSync( `${cmd} updateProductLabels "${testProduct.projectId}" "${ testProduct.location }" "${newProductId}" "${testProduct.productKey}" "${ @@ -211,7 +212,7 @@ describe(`products`, () => { newProductId ); assert.strictEqual(await getProductOrFalse(newProductPath), false); - let output = await exec( + let output = execSync( `${cmd} createProduct "${testProduct.projectId}" "${ testProduct.location }" "${newProductId}" "${testProduct.productDisplayName}" "${ @@ -221,7 +222,7 @@ describe(`products`, () => { assert.match(output, new RegExp(`Product name: ${newProductPath}`)); - output = await exec( + output = execSync( `${cmd} deleteProduct "${testProduct.projectId}" "${ testProduct.location }" "${newProductId}"` diff --git a/vision/samples/system-test/quickstart.test.js b/vision/samples/system-test/quickstart.test.js index b0e88b11c6..66eae95743 100644 --- a/vision/samples/system-test/quickstart.test.js +++ b/vision/samples/system-test/quickstart.test.js @@ -16,11 +16,13 @@ 'use strict'; const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); describe(`quickstart`, () => { it(`should detect labels in a remote file`, async () => { - const {stdout} = await execa.shell('node quickstart.js'); + const stdout = execSync('node quickstart.js'); assert.match(stdout, /Labels:/); assert.match(stdout, /cat/); }); diff --git a/vision/samples/system-test/referenceImages.test.js b/vision/samples/system-test/referenceImages.test.js index 9e8c7114ae..b15c6d7218 100644 --- a/vision/samples/system-test/referenceImages.test.js +++ b/vision/samples/system-test/referenceImages.test.js @@ -18,10 +18,11 @@ const uuid = require('uuid'); const vision = require('@google-cloud/vision'); const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const productSearchClient = new vision.ProductSearchClient(); -const exec = async cmd => (await execa.shell(cmd)).stdout; const cmd = `node productSearch/referenceImages.js`; // Shared fixture data for product tests @@ -71,7 +72,7 @@ describe(`reference images`, () => { }); it(`should create reference image`, async () => { - const output = await exec( + const output = execSync( `${cmd} createReferenceImage "${testProduct.projectId}" "${ testProduct.location }" "${testProduct.productId}" "${testProduct.productReferenceImageId}" "${ @@ -82,7 +83,7 @@ describe(`reference images`, () => { }); it(`should delete reference image`, async () => { - const output = await exec( + const output = execSync( `${cmd} deleteReferenceImage "${testProduct.projectId}" "${ testProduct.location }" "${testProduct.productId}" "${testProduct.productReferenceImageId}"` diff --git a/vision/samples/system-test/similarProducts.test.js b/vision/samples/system-test/similarProducts.test.js index 281b6d0cb7..98578b13e3 100644 --- a/vision/samples/system-test/similarProducts.test.js +++ b/vision/samples/system-test/similarProducts.test.js @@ -17,10 +17,11 @@ const vision = require('@google-cloud/vision'); const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); const path = require('path'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + const cmd = `node productSearch/similarProducts.js`; const filter = ['', 'style=womens']; const localPath = path.join(__dirname, '../resources/shoes_1.jpg'); @@ -45,7 +46,7 @@ testSimilarProducts.productPath = productSearch.productSetPath( describe(`similar products`, () => { it(`should check if similar product exists to one provided in local file with no filter`, async () => { - const output = await exec( + const output = execSync( `${cmd} getSimilarProductsFile "${testSimilarProducts.projectId}" "${ testSimilarProducts.location }" "${testSimilarProducts.productSetId}" "${ @@ -62,7 +63,7 @@ describe(`similar products`, () => { }); it(`should check if similar product exists to one provided in local file with filter`, async () => { - const output = await exec( + const output = execSync( `${cmd} getSimilarProductsFile "${testSimilarProducts.projectId}" "${ testSimilarProducts.location }" "${testSimilarProducts.productSetId}" "${ @@ -78,7 +79,7 @@ describe(`similar products`, () => { }); it(`should check if similar product exists to one provided in GCS file with no filter`, async () => { - const output = await exec( + const output = execSync( `${cmd} getSimilarProductsGcs "${testSimilarProducts.projectId}" "${ testSimilarProducts.location }" "${testSimilarProducts.productSetId}" "${ @@ -95,7 +96,7 @@ describe(`similar products`, () => { }); it(`should check if similar product exists to one provided in GCS file with filter`, async () => { - const output = await exec( + const output = execSync( `${cmd} getSimilarProductsGcs "${testSimilarProducts.projectId}" "${ testSimilarProducts.location }" "${testSimilarProducts.productSetId}" "${ diff --git a/vision/samples/system-test/textDetection.test.js b/vision/samples/system-test/textDetection.test.js index b567563bdd..8a4d283812 100644 --- a/vision/samples/system-test/textDetection.test.js +++ b/vision/samples/system-test/textDetection.test.js @@ -17,24 +17,26 @@ const path = require('path'); const {assert} = require('chai'); -const execa = require('execa'); +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); describe(`Text Detection`, () => { it(`should detect texts`, async () => { const inputDir = path.join(__dirname, `../resources`); - const result = await execa.shell(`node textDetection analyze ${inputDir}`, { - reject: false, - }); - if (result.stderr) { - if (result.stderr.match(/connect ECONNREFUSED/)) { + try { + execSync(`node textDetection analyze ${inputDir}`); + } catch (err) { + if (err.stderr.match(/connect ECONNREFUSED/)) { console.error( '☣️ Redis is unavailable. Skipping vision textDetection test.' ); - return true; + return; } - throw new Error(result.stderr); + throw new Error(err.stderr); } - const {stdout} = await execa.shell('node textDetection lookup sunbeams'); + + const stdout = execSync('node textDetection lookup sunbeams'); assert.match(stdout, /sunbeamkitties/); }); });