Skip to content

Commit 684ad6a

Browse files
JustinBeckwithyoshi-automation
authored andcommitted
refactor: use execSync for tests
refactor: use execSync for tests #332 automerged by dpebot
1 parent 8a2c13a commit 684ad6a

6 files changed

+39
-45
lines changed

speech/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
},
1919
"devDependencies": {
2020
"chai": "^4.2.0",
21-
"execa": "^1.0.0",
2221
"mocha": "^6.0.0",
2322
"uuid": "^3.3.0"
2423
}

speech/system-test/MicrophoneStream.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717

1818
const path = require('path');
1919
const {assert} = require('chai');
20-
const execa = require('execa');
20+
const cp = require('child_process');
21+
22+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2123

2224
const cmd = 'node MicrophoneStream.js';
2325
const cwd = path.join(__dirname, '..');
2426

2527
describe('MicrophoneStream', () => {
2628
it('should load and display Yaaaarghs(!) correctly', async () => {
27-
const {stdout} = await execa.shell(`${cmd} --help`, {cwd});
29+
const stdout = execSync(`${cmd} --help`, {cwd});
2830
assert.match(
2931
stdout,
3032
/Streams audio input from microphone, translates to text/

speech/system-test/betaFeatures.test.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
const path = require('path');
1919
const {assert} = require('chai');
20-
const execa = require('execa');
20+
const cp = require('child_process');
21+
22+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2123

2224
const cmd = 'node betaFeatures.js';
2325
const cwd = path.join(__dirname, `..`);
24-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
2526

2627
//audio file paths
2728
const resourcePath = path.join(__dirname, '..', 'resources');
@@ -37,55 +38,49 @@ const stereoUri = 'gs://cloud-samples-tests/speech/commercial_stereo.wav';
3738

3839
describe(`BetaFeatures`, () => {
3940
it('should run speech diarization on a local file', async () => {
40-
const output = await exec(`${cmd} Diarization -f ${monoFilePath}`);
41+
const output = execSync(`${cmd} Diarization -f ${monoFilePath}`);
4142
assert.match(output, /speakerTag:/);
4243
});
4344

4445
it('should run speech diarization on a GCS file', async () => {
45-
const output = await exec(`${cmd} DiarizationGCS -u ${monoUri}`, cwd);
46+
const output = execSync(`${cmd} DiarizationGCS -u ${monoUri}`, cwd);
4647
assert.match(output, /speakerTag:/);
4748
});
4849

4950
it('should run multi channel transcription on a local file', async () => {
50-
const output = await exec(
51+
const output = execSync(
5152
`${cmd} multiChannelTranscribe -f ${stereoFilePath}`
5253
);
5354
assert.match(output, /Channel Tag: 2/);
5455
});
5556

5657
it('should run multi channel transcription on GCS file', async () => {
57-
const output = await exec(
58-
`${cmd} multiChannelTranscribeGCS -u ${stereoUri}`
59-
);
58+
const output = execSync(`${cmd} multiChannelTranscribeGCS -u ${stereoUri}`);
6059
assert.match(output, /Channel Tag: 2/);
6160
});
6261

6362
it('should transcribe multi-language on a local file', async () => {
64-
const output = await exec(
63+
const output = execSync(
6564
`${cmd} multiLanguageTranscribe -f ${multiLanguageFile}`
6665
);
6766
assert.match(output, /Transcription: how are you doing estoy bien e tu/);
6867
});
6968

7069
it('should transcribe multi-language on a GCS bucket', async () => {
71-
const output = await exec(
72-
`${cmd} multiLanguageTranscribeGCS -u ${multiUri}`
73-
);
70+
const output = execSync(`${cmd} multiLanguageTranscribeGCS -u ${multiUri}`);
7471
assert.match(output, /Transcription: how are you doing estoy bien e tu/);
7572
});
7673

7774
it('should run word Level Confience on a local file', async () => {
78-
const output = await exec(
75+
const output = execSync(
7976
`${cmd} wordLevelConfidence -f ${BrooklynFilePath}`
8077
);
8178
assert.match(output, /Transcription: how old is the Brooklyn Bridge/);
8279
assert.match(output, /Confidence: \d\.\d/);
8380
});
8481

8582
it('should run word level confidence on a GCS bucket', async () => {
86-
const output = await exec(
87-
`${cmd} wordLevelConfidenceGCS -u ${brooklynUri}`
88-
);
83+
const output = execSync(`${cmd} wordLevelConfidenceGCS -u ${brooklynUri}`);
8984
assert.match(output, /Transcription: how old is the Brooklyn Bridge/);
9085
assert.match(output, /Confidence: \d\.\d/);
9186
});

speech/system-test/quickstart.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919

2020
const path = require('path');
2121
const {assert} = require('chai');
22-
const execa = require('execa');
22+
const cp = require('child_process');
23+
24+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2325

2426
const cwd = path.join(__dirname, '..');
2527
const text = 'how old is the Brooklyn Bridge';
2628

2729
describe('Quickstart', () => {
2830
it('should run quickstart', async () => {
29-
const {stdout} = await execa.shell('node quickstart.js', {cwd});
31+
const stdout = execSync('node quickstart.js', {cwd});
3032
assert.match(stdout, new RegExp(`Transcription: ${text}`));
3133
});
3234
});

speech/system-test/recognize.test.js

+16-18
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ const path = require('path');
1919
const {Storage} = require('@google-cloud/storage');
2020
const {assert} = require('chai');
2121
const uuid = require('uuid');
22-
const execa = require('execa');
22+
const cp = require('child_process');
23+
24+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2325

2426
const storage = new Storage();
2527
const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`;
2628
const cmd = 'node recognize.js';
27-
const cwd = path.join(__dirname, '..');
2829
const resourcePath = path.join(__dirname, '..', 'resources');
2930
const filename = `audio.raw`;
3031
const filename1 = `Google_Gnome.wav`;
@@ -38,7 +39,6 @@ const text = 'how old is the Brooklyn Bridge';
3839
const text1 = 'the weather outside is sunny';
3940
const text2 = `Terrific. It's on the way.`;
4041
const text3 = 'Chrome';
41-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
4242

4343
describe('Recognize', () => {
4444
before(async () => {
@@ -56,35 +56,33 @@ describe('Recognize', () => {
5656
});
5757

5858
it('should run sync recognize', async () => {
59-
const output = await exec(`${cmd} sync ${filepath}`);
59+
const output = execSync(`${cmd} sync ${filepath}`);
6060
assert.match(output, new RegExp(`Transcription: ${text}`));
6161
});
6262

6363
it('should run sync recognize on a GCS file', async () => {
64-
const output = await exec(`${cmd} sync-gcs gs://${bucketName}/${filename}`);
64+
const output = execSync(`${cmd} sync-gcs gs://${bucketName}/${filename}`);
6565
assert.match(output, new RegExp(`Transcription: ${text}`));
6666
});
6767

6868
it('should run sync recognize with word time offset', async () => {
69-
const output = await exec(`${cmd} sync-words ${filepath}`);
69+
const output = execSync(`${cmd} sync-words ${filepath}`);
7070
assert.match(output, new RegExp(`Transcription: ${text}`));
7171
assert.match(output, new RegExp('\\d+\\.\\d+ secs - \\d+\\.\\d+ secs'));
7272
});
7373

7474
it('should run async recognize on a local file', async () => {
75-
const output = await exec(`${cmd} async ${filepath}`);
75+
const output = execSync(`${cmd} async ${filepath}`);
7676
assert.match(output, new RegExp(`Transcription: ${text}`));
7777
});
7878

7979
it('should run async recognize on a GCS file', async () => {
80-
const output = await exec(
81-
`${cmd} async-gcs gs://${bucketName}/${filename}`
82-
);
80+
const output = execSync(`${cmd} async-gcs gs://${bucketName}/${filename}`);
8381
assert.match(output, new RegExp(`Transcription: ${text}`));
8482
});
8583

8684
it('should run async recognize on a GCS file with word time offset', async () => {
87-
const output = await exec(
85+
const output = execSync(
8886
`${cmd} async-gcs-words gs://${bucketName}/${filename}`
8987
);
9088
assert.match(output, new RegExp(`Transcription: ${text}`));
@@ -93,43 +91,43 @@ describe('Recognize', () => {
9391
});
9492

9593
it('should run streaming recognize', async () => {
96-
const output = await exec(`${cmd} stream ${filepath}`);
94+
const output = execSync(`${cmd} stream ${filepath}`);
9795
assert.match(output, new RegExp(`Transcription: ${text}`));
9896
});
9997

10098
it('should run sync recognize with model selection', async () => {
10199
const model = 'video';
102-
const output = await exec(`${cmd} sync-model ${filepath1} ${model}`);
100+
const output = execSync(`${cmd} sync-model ${filepath1} ${model}`);
103101
assert.match(output, /Transcription:/);
104102
assert.match(output, new RegExp(text1));
105103
});
106104

107105
it('should run sync recognize on a GCS file with model selection', async () => {
108106
const model = 'video';
109-
const output = await exec(
107+
const output = execSync(
110108
`${cmd} sync-model-gcs gs://${bucketName}/${filename1} ${model}`
111109
);
112110
assert.match(output, /Transcription:/);
113111
assert.match(output, new RegExp(text1));
114112
});
115113

116114
it('should run sync recognize with auto punctuation', async () => {
117-
const output = await exec(`${cmd} sync-auto-punctuation ${filepath2}`);
115+
const output = execSync(`${cmd} sync-auto-punctuation ${filepath2}`);
118116
assert.match(output, new RegExp(text2));
119117
});
120118

121119
it('should run sync recognize with enhanced model', async () => {
122-
const output = await exec(`${cmd} sync-enhanced-model ${filepath2}`);
120+
const output = execSync(`${cmd} sync-enhanced-model ${filepath2}`);
123121
assert.match(output, new RegExp(text3));
124122
});
125123

126124
it('should run multi channel transcription on a local file', async () => {
127-
const output = await exec(`${cmd} sync-multi-channel ${filepath3}`);
125+
const output = execSync(`${cmd} sync-multi-channel ${filepath3}`);
128126
assert.match(output, /Channel Tag: 2/);
129127
});
130128

131129
it('should run multi channel transcription on GCS file', async () => {
132-
const output = await exec(
130+
const output = execSync(
133131
`${cmd} sync-multi-channel-gcs gs://${bucketName}/${filename3}`
134132
);
135133
assert.match(output, /Channel Tag: 2/);

speech/system-test/recognize.v1p1beta1.test.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717

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

22-
const cwd = path.join(__dirname, '..');
23-
const exec = async cmd => (await execa.shell(cmd, {cwd})).stdout;
22+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2423
const cmd = 'node recognize.v1p1beta1.js';
2524
const filepath = path.join(__dirname, '..', 'resources', 'audio.raw');
26-
const text = 'how old is the Brooklyn Bridge';
2725

2826
describe('Recognize v1p1beta1', () => {
2927
it('should run sync recognize with metadata', async () => {
30-
const output = await exec(`${cmd} sync-metadata ${filepath}`);
31-
assert.match(output, new RegExp(text));
28+
const output = execSync(`${cmd} sync-metadata ${filepath}`);
29+
assert.match(output, /how old is the Brooklyn Bridge/);
3230
});
3331
});

0 commit comments

Comments
 (0)