Skip to content

Commit 27c8eff

Browse files
JustinBeckwithAhrar Monsur
authored and
Ahrar Monsur
committed
refactor: modernize the sample tests (#173)
1 parent e09ac0b commit 27c8eff

File tree

4 files changed

+80
-84
lines changed

4 files changed

+80
-84
lines changed

video-intelligence/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "nodejs-docs-samples-videointelligence",
3-
"version": "0.0.1",
43
"private": true,
54
"license": "Apache-2.0",
65
"files": [
@@ -13,14 +12,15 @@
1312
"node": ">=8"
1413
},
1514
"scripts": {
16-
"test": "mocha system-test/*.test.js --timeout=600000"
15+
"test": "mocha system-test --timeout=600000"
1716
},
1817
"dependencies": {
1918
"@google-cloud/video-intelligence": "^1.5.0",
2019
"yargs": "^12.0.0"
2120
},
2221
"devDependencies": {
23-
"@google-cloud/nodejs-repo-tools": "^3.0.0",
24-
"ava": "^0.25.0"
22+
"chai": "^4.2.0",
23+
"execa": "^1.0.0",
24+
"mocha": "^5.2.0"
2525
}
2626
}

video-intelligence/system-test/analyze.test.js

+44-50
Original file line numberDiff line numberDiff line change
@@ -18,67 +18,61 @@
1818
'use strict';
1919

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

2424
const cmd = 'node analyze.js';
2525
const cwd = path.join(__dirname, '..');
26-
2726
const url = 'gs://nodejs-docs-samples-video/quickstart.mp4';
2827
const shortUrl = 'gs://nodejs-docs-samples-video/quickstart_short.mp4';
2928
const file = 'resources/cat.mp4';
3029

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

38-
// analyze_labels_gcs (multiple scenes)
39-
it('should analyze labels in a GCS file with multiple scenes', async () => {
40-
const output = await tools.runAsync(`${cmd} labels-gcs ${url}`, cwd);
41-
assert.strictEqual(new RegExp(/Label shirt occurs at:/).test(output), true);
42-
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
43-
});
32+
describe('analyze samples', () => {
33+
// analyze_labels_gcs (one scene)
34+
it('should analyze labels in a GCS file with one scene', async () => {
35+
const output = await exec(`${cmd} labels-gcs ${shortUrl}`);
36+
assert.match(output, /Label shirt occurs at:/);
37+
assert.match(output, /Confidence: \d+\.\d+/);
38+
});
4439

45-
// analyze_labels_local
46-
it('should analyze labels in a local file', async () => {
47-
const output = await tools.runAsync(`${cmd} labels-file ${file}`, cwd);
48-
assert.strictEqual(
49-
new RegExp(/Label whiskers occurs at:/).test(output),
50-
true
51-
);
52-
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
53-
});
40+
// analyze_labels_gcs (multiple scenes)
41+
it('should analyze labels in a GCS file with multiple scenes', async () => {
42+
const output = await exec(`${cmd} labels-gcs ${url}`);
43+
assert.match(output, /Label shirt occurs at:/);
44+
assert.match(output, /Confidence: \d+\.\d+/);
45+
});
5446

55-
// analyze_shots (multiple shots)
56-
it('should analyze shots in a GCS file with multiple shots', async () => {
57-
const output = await tools.runAsync(`${cmd} shots ${url}`, cwd);
58-
assert.strictEqual(new RegExp(/Scene 0 occurs from:/).test(output), true);
59-
});
47+
// analyze_labels_local
48+
it('should analyze labels in a local file', async () => {
49+
const output = await exec(`${cmd} labels-file ${file}`);
50+
assert.match(output, /Label whiskers occurs at:/);
51+
assert.match(output, /Confidence: \d+\.\d+/);
52+
});
6053

61-
// analyze_shots (one shot)
62-
it('should analyze shots in a GCS file with one shot', async () => {
63-
const output = await tools.runAsync(`${cmd} shots ${shortUrl}`, cwd);
64-
assert.strictEqual(
65-
new RegExp(/The entire video is one shot./).test(output),
66-
true
67-
);
68-
});
54+
// analyze_shots (multiple shots)
55+
it('should analyze shots in a GCS file with multiple shots', async () => {
56+
const output = await exec(`${cmd} shots ${url}`);
57+
assert.match(output, /Scene 0 occurs from:/);
58+
});
6959

70-
// analyze_safe_search
71-
it('should analyze safe search results in a GCS file', async () => {
72-
const output = await tools.runAsync(`${cmd} safe-search ${url}`, cwd);
73-
assert.strictEqual(new RegExp(/Time: \d+\.\d+s/).test(output), true);
74-
assert.strictEqual(
75-
new RegExp(/Explicit annotation results:/).test(output),
76-
true
77-
);
78-
});
60+
// analyze_shots (one shot)
61+
it('should analyze shots in a GCS file with one shot', async () => {
62+
const output = await exec(`${cmd} shots ${shortUrl}`);
63+
assert.match(output, /The entire video is one shot./);
64+
});
65+
66+
// analyze_safe_search
67+
it('should analyze safe search results in a GCS file', async () => {
68+
const output = await exec(`${cmd} safe-search ${url}`);
69+
assert.match(output, /Time: \d+\.\d+s/);
70+
assert.match(output, /Explicit annotation results:/);
71+
});
7972

80-
// analyze_video_transcription
81-
it('should analyze video transcription results in a GCS file', async () => {
82-
const output = await tools.runAsync(`${cmd} transcription ${shortUrl}`, cwd);
83-
assert.strictEqual(new RegExp(/over the pass/).test(output), true);
73+
// analyze_video_transcription
74+
it('should analyze video transcription results in a GCS file', async () => {
75+
const output = await exec(`${cmd} transcription ${shortUrl}`);
76+
assert.match(output, /over the pass/);
77+
});
8478
});

video-intelligence/system-test/analyze.v1p2beta1.test.js

+25-22
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,39 @@
1818
'use strict';
1919

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

2424
const cmd = 'node analyze.v1p2beta1.js';
2525
const cwd = path.join(__dirname, '..');
26+
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
2627

2728
const shortUrl = 'gs://nodejs-docs-samples/video/googlework_short.mp4';
2829
const url = 'gs://nodejs-docs-samples/video/cat.mp4';
2930
const file1 = 'resources/cat.mp4';
3031
const file2 = 'resources/googlework_short.mp4';
3132
const possibleTexts = /Google|GOOGLE|SUR|OMAR|ROTO|Vice President|58oo9|LONDRES|PARIS|METRO|RUE|CARLO/;
3233

33-
it('should detect text in a GCS file', async () => {
34-
const output = await tools.runAsync(`${cmd} video-text-gcs ${shortUrl}`, cwd);
35-
assert.strictEqual(new RegExp(possibleTexts).test(output), true);
36-
});
37-
38-
it('should detect text in a local file', async () => {
39-
const output = await tools.runAsync(`${cmd} video-text ${file2}`, cwd);
40-
assert.strictEqual(new RegExp(possibleTexts).test(output), true);
41-
});
42-
43-
it('should track objects in a GCS file', async () => {
44-
const output = await tools.runAsync(`${cmd} track-objects-gcs ${url}`, cwd);
45-
assert.strictEqual(new RegExp(/cat/).test(output), true);
46-
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
47-
});
48-
49-
it('should track objects in a local file', async () => {
50-
const output = await tools.runAsync(`${cmd} track-objects ${file1}`, cwd);
51-
assert.strictEqual(new RegExp(/cat/).test(output), true);
52-
assert.strictEqual(new RegExp(/Confidence: \d+\.\d+/).test(output), true);
34+
describe('analyze v1p2beta1 samples', () => {
35+
it('should detect text in a GCS file', async () => {
36+
const output = await exec(`${cmd} video-text-gcs ${shortUrl}`);
37+
assert.match(output, possibleTexts);
38+
});
39+
40+
it('should detect text in a local file', async () => {
41+
const output = await exec(`${cmd} video-text ${file2}`);
42+
assert.match(output, possibleTexts);
43+
});
44+
45+
it('should track objects in a GCS file', async () => {
46+
const output = await exec(`${cmd} track-objects-gcs ${url}`);
47+
assert.match(output, /cat/);
48+
assert.match(output, /Confidence: \d+\.\d+/);
49+
});
50+
51+
it('should track objects in a local file', async () => {
52+
const output = await exec(`${cmd} track-objects ${file1}`);
53+
assert.match(output, /cat/);
54+
assert.match(output, /Confidence: \d+\.\d+/);
55+
});
5356
});

video-intelligence/system-test/quickstart.test.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
'use strict';
1717

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

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

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

0 commit comments

Comments
 (0)