Skip to content

Commit

Permalink
refactor: use execSync for tests (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and Ace Nassri committed Nov 17, 2022
1 parent deb95e9 commit d7b9d30
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 58 deletions.
1 change: 0 additions & 1 deletion video-intelligence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
},
"devDependencies": {
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^6.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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+/);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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+/);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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./);
});
});
28 changes: 12 additions & 16 deletions video-intelligence/system-test/analyze.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,90 +17,86 @@

'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';
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+/);
});
Expand Down
14 changes: 5 additions & 9 deletions video-intelligence/system-test/analyze.v1p2beta1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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+/);
});
Expand Down
4 changes: 2 additions & 2 deletions video-intelligence/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:/);
});
});

0 comments on commit d7b9d30

Please sign in to comment.