From 88f479982fe96912af8986d6595f83b21cd78b6e Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Thu, 4 Apr 2019 14:06:40 -0700 Subject: [PATCH] refactor: use execSync for tests (#217) --- video-intelligence/package.json | 1 - ...ze-streaming-annotation-to-storage.test.js | 8 ++---- .../analyze-streaming-labels.test.js | 8 ++---- .../analyze-streaming-object.test.js | 8 ++---- .../analyze-streaming-safe-search.test.js | 8 ++---- .../analyze-streaming-shot-change.test.js | 8 ++---- .../system-test/analyze.test.js | 28 ++++++++----------- .../system-test/analyze.v1p2beta1.test.js | 14 ++++------ .../system-test/quickstart.test.js | 4 +-- 9 files changed, 29 insertions(+), 58 deletions(-) diff --git a/video-intelligence/package.json b/video-intelligence/package.json index 9563fa35df..a5926527fe 100644 --- a/video-intelligence/package.json +++ b/video-intelligence/package.json @@ -20,7 +20,6 @@ }, "devDependencies": { "chai": "^4.2.0", - "execa": "^1.0.0", "mocha": "^6.0.0" } } diff --git a/video-intelligence/system-test/analyze-streaming-annotation-to-storage.test.js b/video-intelligence/system-test/analyze-streaming-annotation-to-storage.test.js index 116150bf0f..6215dbd7e2 100644 --- a/video-intelligence/system-test/analyze-streaming-annotation-to-storage.test.js +++ b/video-intelligence/system-test/analyze-streaming-annotation-to-storage.test.js @@ -15,21 +15,17 @@ 'use strict'; -const path = require('path'); -const execa = require('execa'); +const {execSync} = require('child_process'); const {assert} = require('chai'); const cmd = `node analyze-streaming-annotation-to-storage.js`; -const cwd = path.join(__dirname, '..'); const project = process.env.GLCOUD_PROJECT; -const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout; - const file = 'resources/cat.mp4'; const outputUri = 'gs://' + project + '/VIDEO_STREAMING_OUTPUT'; describe('streaming annotation to storage', () => { it('should store the annotation results in GCS', async () => { - const output = await exec(`${cmd} ${file} ${outputUri}`); + const output = execSync(`${cmd} ${file} ${outputUri}`); assert.match(output, /The annotation is stored at:/); }); }); diff --git a/video-intelligence/system-test/analyze-streaming-labels.test.js b/video-intelligence/system-test/analyze-streaming-labels.test.js index 405860d351..e9d885a20f 100644 --- a/video-intelligence/system-test/analyze-streaming-labels.test.js +++ b/video-intelligence/system-test/analyze-streaming-labels.test.js @@ -15,19 +15,15 @@ 'use strict'; -const path = require('path'); -const execa = require('execa'); +const {execSync} = require('child_process'); const {assert} = require('chai'); const cmd = `node analyze-streaming-labels.js`; -const cwd = path.join(__dirname, '..'); -const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout; - const file = 'resources/cat.mp4'; describe('streaming label', () => { it('should analyze labels in a streaming video', async () => { - const output = await exec(`${cmd} ${file}`); + const output = execSync(`${cmd} ${file}`); assert.match(output, /cat/); assert.match(output, /Confidence: \d+\.\d+/); }); diff --git a/video-intelligence/system-test/analyze-streaming-object.test.js b/video-intelligence/system-test/analyze-streaming-object.test.js index c26538b700..ae3f4397da 100644 --- a/video-intelligence/system-test/analyze-streaming-object.test.js +++ b/video-intelligence/system-test/analyze-streaming-object.test.js @@ -15,19 +15,15 @@ 'use strict'; -const path = require('path'); -const execa = require('execa'); +const {execSync} = require('child_process'); const {assert} = require('chai'); const cmd = `node analyze-streaming-object.js`; -const cwd = path.join(__dirname, '..'); -const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout; - const file = 'resources/cat.mp4'; describe('streaming object', () => { it('should track an object in a streaming video', async () => { - const output = await exec(`${cmd} ${file}`); + const output = execSync(`${cmd} ${file}`); assert.match(output, /cat/); assert.match(output, /Confidence: \d+\.\d+/); }); diff --git a/video-intelligence/system-test/analyze-streaming-safe-search.test.js b/video-intelligence/system-test/analyze-streaming-safe-search.test.js index d211e69a83..68626fc1a3 100644 --- a/video-intelligence/system-test/analyze-streaming-safe-search.test.js +++ b/video-intelligence/system-test/analyze-streaming-safe-search.test.js @@ -15,19 +15,15 @@ 'use strict'; -const path = require('path'); -const execa = require('execa'); +const {execSync} = require('child_process'); const {assert} = require('chai'); const cmd = `node analyze-streaming-safe-search.js`; -const cwd = path.join(__dirname, '..'); -const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout; - const file = 'resources/cat.mp4'; describe('streaming safe search', () => { it('should analyze explicit content in a streaming video', async () => { - const output = await exec(`${cmd} ${file}`); + const output = execSync(`${cmd} ${file}`); assert.match(output, /UNLIKELY/); }); }); diff --git a/video-intelligence/system-test/analyze-streaming-shot-change.test.js b/video-intelligence/system-test/analyze-streaming-shot-change.test.js index 22774307ff..7f5d24a5e3 100644 --- a/video-intelligence/system-test/analyze-streaming-shot-change.test.js +++ b/video-intelligence/system-test/analyze-streaming-shot-change.test.js @@ -15,19 +15,15 @@ 'use strict'; -const path = require('path'); -const execa = require('execa'); +const {execSync} = require('child_process'); const {assert} = require('chai'); const cmd = `node analyze-streaming-shot-change.js`; -const cwd = path.join(__dirname, '..'); -const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout; - const file = 'resources/cat.mp4'; describe('streaming shot change', () => { it('should analyze shot changes in a streaming video', async () => { - const output = await exec(`${cmd} ${file}`); + const output = execSync(`${cmd} ${file}`); assert.match(output, /The entire video is one shot./); }); }); diff --git a/video-intelligence/system-test/analyze.test.js b/video-intelligence/system-test/analyze.test.js index 5638004431..1eced2e153 100644 --- a/video-intelligence/system-test/analyze.test.js +++ b/video-intelligence/system-test/analyze.test.js @@ -17,12 +17,10 @@ 'use strict'; -const path = require('path'); const {assert} = require('chai'); -const execa = require('execa'); +const {execSync} = require('child_process'); const cmd = 'node analyze.js'; -const cwd = path.join(__dirname, '..'); const url = 'gs://nodejs-docs-samples-video/quickstart.mp4'; const shortUrl = 'gs://nodejs-docs-samples-video/quickstart_short.mp4'; const catUrl = 'gs://nodejs-docs-samples/video/cat.mp4'; @@ -30,77 +28,75 @@ const file = 'resources/cat.mp4'; const file2 = 'resources/googlework_short.mp4'; const possibleTexts = /Google|GOOGLE|SUR|OMAR|ROTO|Vice President|58oo9|LONDRES|PARIS|METRO|RUE|CARLO/; -const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout; - describe('analyze samples', () => { // analyze_labels_gcs (one scene) it('should analyze labels in a GCS file with one scene', async () => { - const output = await exec(`${cmd} labels-gcs ${shortUrl}`); + const output = execSync(`${cmd} labels-gcs ${shortUrl}`); assert.match(output, /Label shirt occurs at:/); assert.match(output, /Confidence: \d+\.\d+/); }); // analyze_labels_gcs (multiple scenes) it('should analyze labels in a GCS file with multiple scenes', async () => { - const output = await exec(`${cmd} labels-gcs ${url}`); + const output = execSync(`${cmd} labels-gcs ${url}`); assert.match(output, /Label shirt occurs at:/); assert.match(output, /Confidence: \d+\.\d+/); }); // analyze_labels_local it('should analyze labels in a local file', async () => { - const output = await exec(`${cmd} labels-file ${file}`); + const output = execSync(`${cmd} labels-file ${file}`); assert.match(output, /Label whiskers occurs at:/); assert.match(output, /Confidence: \d+\.\d+/); }); // analyze_shots (multiple shots) it('should analyze shots in a GCS file with multiple shots', async () => { - const output = await exec(`${cmd} shots ${url}`); + const output = execSync(`${cmd} shots ${url}`); assert.match(output, /Scene 0 occurs from:/); }); // analyze_shots (one shot) it('should analyze shots in a GCS file with one shot', async () => { - const output = await exec(`${cmd} shots ${shortUrl}`); + const output = execSync(`${cmd} shots ${shortUrl}`); assert.match(output, /The entire video is one shot./); }); // analyze_safe_search it('should analyze safe search results in a GCS file', async () => { - const output = await exec(`${cmd} safe-search ${url}`); + const output = execSync(`${cmd} safe-search ${url}`); assert.match(output, /Time: \d+\.\d+s/); assert.match(output, /Explicit annotation results:/); }); // analyze_video_transcription it('should analyze video transcription results in a GCS file', async () => { - const output = await exec(`${cmd} transcription ${shortUrl}`); + const output = execSync(`${cmd} transcription ${shortUrl}`); assert.match(output, /over the pass/); }); //detect_text_gcs it('should detect text in a GCS file', async () => { - const output = await exec(`${cmd} video-text-gcs ${shortUrl}`); + const output = execSync(`${cmd} video-text-gcs ${shortUrl}`); assert.match(output, possibleTexts); }); //detect_text it('should detect text in a local file', async () => { - const output = await exec(`${cmd} video-text ${file2}`); + const output = execSync(`${cmd} video-text ${file2}`); assert.match(output, possibleTexts); }); //object_tracking_gcs it('should track objects in a GCS file', async () => { - const output = await exec(`${cmd} track-objects-gcs ${catUrl}`); + const output = execSync(`${cmd} track-objects-gcs ${catUrl}`); assert.match(output, /cat/); assert.match(output, /Confidence: \d+\.\d+/); }); //object_tracking it('should track objects in a local file', async () => { - const output = await exec(`${cmd} track-objects ${file}`); + const output = execSync(`${cmd} track-objects ${file}`); assert.match(output, /cat/); assert.match(output, /Confidence: \d+\.\d+/); }); diff --git a/video-intelligence/system-test/analyze.v1p2beta1.test.js b/video-intelligence/system-test/analyze.v1p2beta1.test.js index 0b57b7a4c2..ab3eb2ebf4 100644 --- a/video-intelligence/system-test/analyze.v1p2beta1.test.js +++ b/video-intelligence/system-test/analyze.v1p2beta1.test.js @@ -17,14 +17,10 @@ 'use strict'; -const path = require('path'); const {assert} = require('chai'); -const execa = require('execa'); +const {execSync} = require('child_process'); const cmd = 'node analyze.v1p2beta1.js'; -const cwd = path.join(__dirname, '..'); -const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout; - const shortUrl = 'gs://nodejs-docs-samples/video/googlework_short.mp4'; const url = 'gs://nodejs-docs-samples/video/cat.mp4'; const file1 = 'resources/cat.mp4'; @@ -33,23 +29,23 @@ const possibleTexts = /Google|GOOGLE|SUR|OMAR|ROTO|Vice President|58oo9|LONDRES| describe('analyze v1p2beta1 samples', () => { it('should detect text in a GCS file', async () => { - const output = await exec(`${cmd} video-text-gcs ${shortUrl}`); + const output = execSync(`${cmd} video-text-gcs ${shortUrl}`); assert.match(output, possibleTexts); }); it('should detect text in a local file', async () => { - const output = await exec(`${cmd} video-text ${file2}`); + const output = execSync(`${cmd} video-text ${file2}`); assert.match(output, possibleTexts); }); it('should track objects in a GCS file', async () => { - const output = await exec(`${cmd} track-objects-gcs ${url}`); + const output = execSync(`${cmd} track-objects-gcs ${url}`); assert.match(output, /cat/); assert.match(output, /Confidence: \d+\.\d+/); }); it('should track objects in a local file', async () => { - const output = await exec(`${cmd} track-objects ${file1}`); + const output = execSync(`${cmd} track-objects ${file1}`); assert.match(output, /cat/); assert.match(output, /Confidence: \d+\.\d+/); }); diff --git a/video-intelligence/system-test/quickstart.test.js b/video-intelligence/system-test/quickstart.test.js index e7a9a93bd3..4291c27407 100644 --- a/video-intelligence/system-test/quickstart.test.js +++ b/video-intelligence/system-test/quickstart.test.js @@ -17,14 +17,14 @@ const path = require('path'); const {assert} = require('chai'); -const execa = require('execa'); +const {execSync} = require('child_process'); const cmd = 'node quickstart.js'; const cwd = path.join(__dirname, '..'); describe('quickstart samples', () => { it('should analyze a hardcoded video', async () => { - const {stdout} = await execa.shell(cmd, {cwd}); + const stdout = execSync(cmd, {cwd}); assert.match(stdout, /Label standing occurs at:/); }); });