Skip to content

Commit

Permalink
refactor: modernize the sample tests (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and ahrarmonsur committed Nov 17, 2022
1 parent e09ac0b commit 27c8eff
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 84 deletions.
8 changes: 4 additions & 4 deletions video-intelligence/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "nodejs-docs-samples-videointelligence",
"version": "0.0.1",
"private": true,
"license": "Apache-2.0",
"files": [
Expand All @@ -13,14 +12,15 @@
"node": ">=8"
},
"scripts": {
"test": "mocha system-test/*.test.js --timeout=600000"
"test": "mocha system-test --timeout=600000"
},
"dependencies": {
"@google-cloud/video-intelligence": "^1.5.0",
"yargs": "^12.0.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0"
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^5.2.0"
}
}
94 changes: 44 additions & 50 deletions video-intelligence/system-test/analyze.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,67 +18,61 @@
'use strict';

const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');
const {assert} = require('chai');
const execa = require('execa');

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 file = 'resources/cat.mp4';

// analyze_labels_gcs (one scene)
it('should analyze labels in a GCS file with one scene', async () => {
const output = await tools.runAsync(`${cmd} labels-gcs ${shortUrl}`, cwd);
assert.strictEqual(new RegExp(/Label shirt occurs at:/).test(output), true);
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
});
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;

// analyze_labels_gcs (multiple scenes)
it('should analyze labels in a GCS file with multiple scenes', async () => {
const output = await tools.runAsync(`${cmd} labels-gcs ${url}`, cwd);
assert.strictEqual(new RegExp(/Label shirt occurs at:/).test(output), true);
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
});
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}`);
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 tools.runAsync(`${cmd} labels-file ${file}`, cwd);
assert.strictEqual(
new RegExp(/Label whiskers occurs at:/).test(output),
true
);
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
});
// 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}`);
assert.match(output, /Label shirt 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 tools.runAsync(`${cmd} shots ${url}`, cwd);
assert.strictEqual(new RegExp(/Scene 0 occurs from:/).test(output), true);
});
// analyze_labels_local
it('should analyze labels in a local file', async () => {
const output = await exec(`${cmd} labels-file ${file}`);
assert.match(output, /Label whiskers occurs at:/);
assert.match(output, /Confidence: \d+\.\d+/);
});

// analyze_shots (one shot)
it('should analyze shots in a GCS file with one shot', async () => {
const output = await tools.runAsync(`${cmd} shots ${shortUrl}`, cwd);
assert.strictEqual(
new RegExp(/The entire video is one shot./).test(output),
true
);
});
// analyze_shots (multiple shots)
it('should analyze shots in a GCS file with multiple shots', async () => {
const output = await exec(`${cmd} shots ${url}`);
assert.match(output, /Scene 0 occurs from:/);
});

// analyze_safe_search
it('should analyze safe search results in a GCS file', async () => {
const output = await tools.runAsync(`${cmd} safe-search ${url}`, cwd);
assert.strictEqual(new RegExp(/Time: \d+\.\d+s/).test(output), true);
assert.strictEqual(
new RegExp(/Explicit annotation results:/).test(output),
true
);
});
// analyze_shots (one shot)
it('should analyze shots in a GCS file with one shot', async () => {
const output = await exec(`${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}`);
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 tools.runAsync(`${cmd} transcription ${shortUrl}`, cwd);
assert.strictEqual(new RegExp(/over the pass/).test(output), true);
// analyze_video_transcription
it('should analyze video transcription results in a GCS file', async () => {
const output = await exec(`${cmd} transcription ${shortUrl}`);
assert.match(output, /over the pass/);
});
});
47 changes: 25 additions & 22 deletions video-intelligence/system-test/analyze.v1p2beta1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,39 @@
'use strict';

const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');
const {assert} = require('chai');
const execa = require('execa');

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';
const file2 = 'resources/googlework_short.mp4';
const possibleTexts = /Google|GOOGLE|SUR|OMAR|ROTO|Vice President|58oo9|LONDRES|PARIS|METRO|RUE|CARLO/;

it('should detect text in a GCS file', async () => {
const output = await tools.runAsync(`${cmd} video-text-gcs ${shortUrl}`, cwd);
assert.strictEqual(new RegExp(possibleTexts).test(output), true);
});

it('should detect text in a local file', async () => {
const output = await tools.runAsync(`${cmd} video-text ${file2}`, cwd);
assert.strictEqual(new RegExp(possibleTexts).test(output), true);
});

it('should track objects in a GCS file', async () => {
const output = await tools.runAsync(`${cmd} track-objects-gcs ${url}`, cwd);
assert.strictEqual(new RegExp(/cat/).test(output), true);
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
});

it('should track objects in a local file', async () => {
const output = await tools.runAsync(`${cmd} track-objects ${file1}`, cwd);
assert.strictEqual(new RegExp(/cat/).test(output), true);
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
describe('analyze v1p2beta1 samples', () => {
it('should detect text in a GCS file', async () => {
const output = await exec(`${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}`);
assert.match(output, possibleTexts);
});

it('should track objects in a GCS file', async () => {
const output = await exec(`${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}`);
assert.match(output, /cat/);
assert.match(output, /Confidence: \d+\.\d+/);
});
});
15 changes: 7 additions & 8 deletions video-intelligence/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
'use strict';

const path = require('path');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');
const {assert} = require('chai');
const execa = require('execa');

const cmd = 'node quickstart.js';
const cwd = path.join(__dirname, '..');

it('should analyze a hardcoded video', async () => {
const output = await tools.runAsync(cmd, cwd);
assert.strictEqual(
new RegExp(/Label standing occurs at:/).test(output),
true
);
describe('quickstart samples', () => {
it('should analyze a hardcoded video', async () => {
const {stdout} = await execa.shell(cmd, {cwd});
assert.match(stdout, /Label standing occurs at:/);
});
});

0 comments on commit 27c8eff

Please sign in to comment.