Skip to content

Commit

Permalink
refactor: use execSync for tests
Browse files Browse the repository at this point in the history
refactor: use execSync for tests

#332 automerged by dpebot
  • Loading branch information
JustinBeckwith authored and Ace Nassri committed Nov 17, 2022
1 parent 782d768 commit 0dc7d13
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 45 deletions.
1 change: 0 additions & 1 deletion speech/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
},
"devDependencies": {
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^6.0.0",
"uuid": "^3.3.0"
}
Expand Down
6 changes: 4 additions & 2 deletions speech/system-test/MicrophoneStream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

const path = require('path');
const {assert} = require('chai');
const execa = require('execa');
const cp = require('child_process');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

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

describe('MicrophoneStream', () => {
it('should load and display Yaaaarghs(!) correctly', async () => {
const {stdout} = await execa.shell(`${cmd} --help`, {cwd});
const stdout = execSync(`${cmd} --help`, {cwd});
assert.match(
stdout,
/Streams audio input from microphone, translates to text/
Expand Down
27 changes: 11 additions & 16 deletions speech/system-test/betaFeatures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

const path = require('path');
const {assert} = require('chai');
const execa = require('execa');
const cp = require('child_process');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

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

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

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

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

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

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

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

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

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

it('should run word level confidence on a GCS bucket', async () => {
const output = await exec(
`${cmd} wordLevelConfidenceGCS -u ${brooklynUri}`
);
const output = execSync(`${cmd} wordLevelConfidenceGCS -u ${brooklynUri}`);
assert.match(output, /Transcription: how old is the Brooklyn Bridge/);
assert.match(output, /Confidence: \d\.\d/);
});
Expand Down
6 changes: 4 additions & 2 deletions speech/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

const path = require('path');
const {assert} = require('chai');
const execa = require('execa');
const cp = require('child_process');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

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

describe('Quickstart', () => {
it('should run quickstart', async () => {
const {stdout} = await execa.shell('node quickstart.js', {cwd});
const stdout = execSync('node quickstart.js', {cwd});
assert.match(stdout, new RegExp(`Transcription: ${text}`));
});
});
34 changes: 16 additions & 18 deletions speech/system-test/recognize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ const path = require('path');
const {Storage} = require('@google-cloud/storage');
const {assert} = require('chai');
const uuid = require('uuid');
const execa = require('execa');
const cp = require('child_process');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

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

describe('Recognize', () => {
before(async () => {
Expand All @@ -56,35 +56,33 @@ describe('Recognize', () => {
});

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

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

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

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

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

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

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

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

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

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

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

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

it('should run multi channel transcription on GCS file', async () => {
const output = await exec(
const output = execSync(
`${cmd} sync-multi-channel-gcs gs://${bucketName}/${filename3}`
);
assert.match(output, /Channel Tag: 2/);
Expand Down
10 changes: 4 additions & 6 deletions speech/system-test/recognize.v1p1beta1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@

const path = require('path');
const {assert} = require('chai');
const execa = require('execa');
const cp = require('child_process');

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

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

0 comments on commit 0dc7d13

Please sign in to comment.