Skip to content

Commit 731fe57

Browse files
JustinBeckwithAhrar Monsur
authored andcommitted
refactor: use execSync for tests (#217)
1 parent 68f0cb3 commit 731fe57

9 files changed

+29
-58
lines changed

video-intelligence/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
},
2121
"devDependencies": {
2222
"chai": "^4.2.0",
23-
"execa": "^1.0.0",
2423
"mocha": "^6.0.0"
2524
}
2625
}

video-intelligence/system-test/analyze-streaming-annotation-to-storage.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,17 @@
1515

1616
'use strict';
1717

18-
const path = require('path');
19-
const execa = require('execa');
18+
const {execSync} = require('child_process');
2019
const {assert} = require('chai');
2120

2221
const cmd = `node analyze-streaming-annotation-to-storage.js`;
23-
const cwd = path.join(__dirname, '..');
2422
const project = process.env.GLCOUD_PROJECT;
25-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
26-
2723
const file = 'resources/cat.mp4';
2824
const outputUri = 'gs://' + project + '/VIDEO_STREAMING_OUTPUT';
2925

3026
describe('streaming annotation to storage', () => {
3127
it('should store the annotation results in GCS', async () => {
32-
const output = await exec(`${cmd} ${file} ${outputUri}`);
28+
const output = execSync(`${cmd} ${file} ${outputUri}`);
3329
assert.match(output, /The annotation is stored at:/);
3430
});
3531
});

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515

1616
'use strict';
1717

18-
const path = require('path');
19-
const execa = require('execa');
18+
const {execSync} = require('child_process');
2019
const {assert} = require('chai');
2120

2221
const cmd = `node analyze-streaming-labels.js`;
23-
const cwd = path.join(__dirname, '..');
24-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
25-
2622
const file = 'resources/cat.mp4';
2723

2824
describe('streaming label', () => {
2925
it('should analyze labels in a streaming video', async () => {
30-
const output = await exec(`${cmd} ${file}`);
26+
const output = execSync(`${cmd} ${file}`);
3127
assert.match(output, /cat/);
3228
assert.match(output, /Confidence: \d+\.\d+/);
3329
});

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515

1616
'use strict';
1717

18-
const path = require('path');
19-
const execa = require('execa');
18+
const {execSync} = require('child_process');
2019
const {assert} = require('chai');
2120

2221
const cmd = `node analyze-streaming-object.js`;
23-
const cwd = path.join(__dirname, '..');
24-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
25-
2622
const file = 'resources/cat.mp4';
2723

2824
describe('streaming object', () => {
2925
it('should track an object in a streaming video', async () => {
30-
const output = await exec(`${cmd} ${file}`);
26+
const output = execSync(`${cmd} ${file}`);
3127
assert.match(output, /cat/);
3228
assert.match(output, /Confidence: \d+\.\d+/);
3329
});

video-intelligence/system-test/analyze-streaming-safe-search.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515

1616
'use strict';
1717

18-
const path = require('path');
19-
const execa = require('execa');
18+
const {execSync} = require('child_process');
2019
const {assert} = require('chai');
2120

2221
const cmd = `node analyze-streaming-safe-search.js`;
23-
const cwd = path.join(__dirname, '..');
24-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
25-
2622
const file = 'resources/cat.mp4';
2723

2824
describe('streaming safe search', () => {
2925
it('should analyze explicit content in a streaming video', async () => {
30-
const output = await exec(`${cmd} ${file}`);
26+
const output = execSync(`${cmd} ${file}`);
3127
assert.match(output, /UNLIKELY/);
3228
});
3329
});

video-intelligence/system-test/analyze-streaming-shot-change.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515

1616
'use strict';
1717

18-
const path = require('path');
19-
const execa = require('execa');
18+
const {execSync} = require('child_process');
2019
const {assert} = require('chai');
2120

2221
const cmd = `node analyze-streaming-shot-change.js`;
23-
const cwd = path.join(__dirname, '..');
24-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
25-
2622
const file = 'resources/cat.mp4';
2723

2824
describe('streaming shot change', () => {
2925
it('should analyze shot changes in a streaming video', async () => {
30-
const output = await exec(`${cmd} ${file}`);
26+
const output = execSync(`${cmd} ${file}`);
3127
assert.match(output, /The entire video is one shot./);
3228
});
3329
});

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,90 +17,86 @@
1717

1818
'use strict';
1919

20-
const path = require('path');
2120
const {assert} = require('chai');
22-
const execa = require('execa');
21+
const {execSync} = require('child_process');
2322

2423
const cmd = 'node analyze.js';
25-
const cwd = path.join(__dirname, '..');
2624
const url = 'gs://nodejs-docs-samples-video/quickstart.mp4';
2725
const shortUrl = 'gs://nodejs-docs-samples-video/quickstart_short.mp4';
2826
const catUrl = 'gs://nodejs-docs-samples/video/cat.mp4';
2927
const file = 'resources/cat.mp4';
3028
const file2 = 'resources/googlework_short.mp4';
3129
const possibleTexts = /Google|GOOGLE|SUR|OMAR|ROTO|Vice President|58oo9|LONDRES|PARIS|METRO|RUE|CARLO/;
3230

33-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
34-
3531
describe('analyze samples', () => {
3632
// analyze_labels_gcs (one scene)
3733
it('should analyze labels in a GCS file with one scene', async () => {
38-
const output = await exec(`${cmd} labels-gcs ${shortUrl}`);
34+
const output = execSync(`${cmd} labels-gcs ${shortUrl}`);
3935
assert.match(output, /Label shirt occurs at:/);
4036
assert.match(output, /Confidence: \d+\.\d+/);
4137
});
4238

4339
// analyze_labels_gcs (multiple scenes)
4440
it('should analyze labels in a GCS file with multiple scenes', async () => {
45-
const output = await exec(`${cmd} labels-gcs ${url}`);
41+
const output = execSync(`${cmd} labels-gcs ${url}`);
4642
assert.match(output, /Label shirt occurs at:/);
4743
assert.match(output, /Confidence: \d+\.\d+/);
4844
});
4945

5046
// analyze_labels_local
5147
it('should analyze labels in a local file', async () => {
52-
const output = await exec(`${cmd} labels-file ${file}`);
48+
const output = execSync(`${cmd} labels-file ${file}`);
5349
assert.match(output, /Label whiskers occurs at:/);
5450
assert.match(output, /Confidence: \d+\.\d+/);
5551
});
5652

5753
// analyze_shots (multiple shots)
5854
it('should analyze shots in a GCS file with multiple shots', async () => {
59-
const output = await exec(`${cmd} shots ${url}`);
55+
const output = execSync(`${cmd} shots ${url}`);
6056
assert.match(output, /Scene 0 occurs from:/);
6157
});
6258

6359
// analyze_shots (one shot)
6460
it('should analyze shots in a GCS file with one shot', async () => {
65-
const output = await exec(`${cmd} shots ${shortUrl}`);
61+
const output = execSync(`${cmd} shots ${shortUrl}`);
6662
assert.match(output, /The entire video is one shot./);
6763
});
6864

6965
// analyze_safe_search
7066
it('should analyze safe search results in a GCS file', async () => {
71-
const output = await exec(`${cmd} safe-search ${url}`);
67+
const output = execSync(`${cmd} safe-search ${url}`);
7268
assert.match(output, /Time: \d+\.\d+s/);
7369
assert.match(output, /Explicit annotation results:/);
7470
});
7571

7672
// analyze_video_transcription
7773
it('should analyze video transcription results in a GCS file', async () => {
78-
const output = await exec(`${cmd} transcription ${shortUrl}`);
74+
const output = execSync(`${cmd} transcription ${shortUrl}`);
7975
assert.match(output, /over the pass/);
8076
});
8177

8278
//detect_text_gcs
8379
it('should detect text in a GCS file', async () => {
84-
const output = await exec(`${cmd} video-text-gcs ${shortUrl}`);
80+
const output = execSync(`${cmd} video-text-gcs ${shortUrl}`);
8581
assert.match(output, possibleTexts);
8682
});
8783

8884
//detect_text
8985
it('should detect text in a local file', async () => {
90-
const output = await exec(`${cmd} video-text ${file2}`);
86+
const output = execSync(`${cmd} video-text ${file2}`);
9187
assert.match(output, possibleTexts);
9288
});
9389

9490
//object_tracking_gcs
9591
it('should track objects in a GCS file', async () => {
96-
const output = await exec(`${cmd} track-objects-gcs ${catUrl}`);
92+
const output = execSync(`${cmd} track-objects-gcs ${catUrl}`);
9793
assert.match(output, /cat/);
9894
assert.match(output, /Confidence: \d+\.\d+/);
9995
});
10096

10197
//object_tracking
10298
it('should track objects in a local file', async () => {
103-
const output = await exec(`${cmd} track-objects ${file}`);
99+
const output = execSync(`${cmd} track-objects ${file}`);
104100
assert.match(output, /cat/);
105101
assert.match(output, /Confidence: \d+\.\d+/);
106102
});

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@
1717

1818
'use strict';
1919

20-
const path = require('path');
2120
const {assert} = require('chai');
22-
const execa = require('execa');
21+
const {execSync} = require('child_process');
2322

2423
const cmd = 'node analyze.v1p2beta1.js';
25-
const cwd = path.join(__dirname, '..');
26-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
27-
2824
const shortUrl = 'gs://nodejs-docs-samples/video/googlework_short.mp4';
2925
const url = 'gs://nodejs-docs-samples/video/cat.mp4';
3026
const file1 = 'resources/cat.mp4';
@@ -33,23 +29,23 @@ const possibleTexts = /Google|GOOGLE|SUR|OMAR|ROTO|Vice President|58oo9|LONDRES|
3329

3430
describe('analyze v1p2beta1 samples', () => {
3531
it('should detect text in a GCS file', async () => {
36-
const output = await exec(`${cmd} video-text-gcs ${shortUrl}`);
32+
const output = execSync(`${cmd} video-text-gcs ${shortUrl}`);
3733
assert.match(output, possibleTexts);
3834
});
3935

4036
it('should detect text in a local file', async () => {
41-
const output = await exec(`${cmd} video-text ${file2}`);
37+
const output = execSync(`${cmd} video-text ${file2}`);
4238
assert.match(output, possibleTexts);
4339
});
4440

4541
it('should track objects in a GCS file', async () => {
46-
const output = await exec(`${cmd} track-objects-gcs ${url}`);
42+
const output = execSync(`${cmd} track-objects-gcs ${url}`);
4743
assert.match(output, /cat/);
4844
assert.match(output, /Confidence: \d+\.\d+/);
4945
});
5046

5147
it('should track objects in a local file', async () => {
52-
const output = await exec(`${cmd} track-objects ${file1}`);
48+
const output = execSync(`${cmd} track-objects ${file1}`);
5349
assert.match(output, /cat/);
5450
assert.match(output, /Confidence: \d+\.\d+/);
5551
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
const path = require('path');
1919
const {assert} = require('chai');
20-
const execa = require('execa');
20+
const {execSync} = require('child_process');
2121

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

2525
describe('quickstart samples', () => {
2626
it('should analyze a hardcoded video', async () => {
27-
const {stdout} = await execa.shell(cmd, {cwd});
27+
const stdout = execSync(cmd, {cwd});
2828
assert.match(stdout, /Label standing occurs at:/);
2929
});
3030
});

0 commit comments

Comments
 (0)